Coverage Report

Created: 2026-08-13 07:23

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.12M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.12M
    int len = 0;
51
1.12M
    unsigned val = 1;
52
53
2.07M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
2.07M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.12M
    return val - 1;
57
1.12M
}
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
8.72M
{
66
8.72M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
8.72M
    if (chroma) {
69
4.73M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
4.73M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
4.73M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
2.82M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
4.73M
        unsigned ca, cl;
74
75
4.73M
#define MERGE_CTX(dir, type, no_val) \
76
9.46M
        c##dir = *(const type *) dir != no_val; \
77
9.46M
        break
78
79
4.73M
        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.06M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
888k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
661k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
1.11M
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
4.73M
        }
91
4.73M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
2.28M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
879k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
518k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
1.05M
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
4.73M
        }
98
4.73M
#undef MERGE_CTX
99
100
4.73M
        return 7 + not_one_blk * 3 + ca + cl;
101
4.73M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
1.64M
        return 0;
103
2.35M
    } else {
104
2.35M
        unsigned la, ll;
105
106
2.35M
#define MERGE_CTX(dir, type, tx) \
107
4.73M
        if (tx == TX_64X64) { \
108
323k
            uint64_t tmp = *(const uint64_t *) dir; \
109
323k
            tmp |= *(const uint64_t *) &dir[8]; \
110
323k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
323k
        } else \
112
4.73M
            l##dir = *(const type *) dir; \
113
4.73M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
4.73M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
4.73M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
4.73M
        break
117
118
2.35M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
1.33M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
476k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
359k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
33.3k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
161k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
2.35M
        }
126
2.36M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
1.35M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
463k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
357k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
33.1k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
161k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
2.36M
        }
134
2.36M
#undef MERGE_CTX
135
136
2.36M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
2.36M
    }
138
8.72M
}
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
3.60M
{
144
3.60M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
3.60M
    int s;
146
147
3.60M
#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
3.60M
    __asm__("" : "+r"(mask), "+r"(mul));
151
3.60M
#endif
152
153
3.60M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
1.40M
    case TX_4X4: {
156
1.40M
        int t = *(const uint8_t *) a >> 6;
157
1.40M
        t    += *(const uint8_t *) l >> 6;
158
1.40M
        s = t - 1 - 1;
159
1.40M
        break;
160
0
    }
161
414k
    case TX_8X8: {
162
414k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
414k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
414k
        t *= 0x04040404U;
165
414k
        s = (int) (t >> 24) - 2 - 2;
166
414k
        break;
167
0
    }
168
285k
    case TX_16X16: {
169
285k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
285k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
285k
        t *= (uint32_t) mul;
172
285k
        s = (int) (t >> 24) - 4 - 4;
173
285k
        break;
174
0
    }
175
273k
    case TX_32X32: {
176
273k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
273k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
273k
        t *= mul;
179
273k
        s = (int) (t >> 56) - 8 - 8;
180
273k
        break;
181
0
    }
182
124k
    case TX_64X64: {
183
124k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
124k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
124k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
124k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
124k
        t *= mul;
188
124k
        s = (int) (t >> 56) - 16 - 16;
189
124k
        break;
190
0
    }
191
130k
    case RTX_4X8: {
192
130k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
130k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
130k
        t *= 0x04040404U;
195
130k
        s = (int) (t >> 24) - 1 - 2;
196
130k
        break;
197
0
    }
198
193k
    case RTX_8X4: {
199
193k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
193k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
193k
        t *= 0x04040404U;
202
193k
        s = (int) (t >> 24) - 2 - 1;
203
193k
        break;
204
0
    }
205
101k
    case RTX_8X16: {
206
101k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
101k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
101k
        t = (t >> 6) * (uint32_t) mul;
209
101k
        s = (int) (t >> 24) - 2 - 4;
210
101k
        break;
211
0
    }
212
196k
    case RTX_16X8: {
213
196k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
196k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
196k
        t = (t >> 6) * (uint32_t) mul;
216
196k
        s = (int) (t >> 24) - 4 - 2;
217
196k
        break;
218
0
    }
219
53.2k
    case RTX_16X32: {
220
53.2k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
53.2k
        t         += *(const uint64_t *) l & mask;
222
53.2k
        t = (t >> 6) * mul;
223
53.2k
        s = (int) (t >> 56) - 4 - 8;
224
53.2k
        break;
225
0
    }
226
93.1k
    case RTX_32X16: {
227
93.1k
        uint64_t t = *(const uint64_t *) a & mask;
228
93.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
93.1k
        t = (t >> 6) * mul;
230
93.1k
        s = (int) (t >> 56) - 8 - 4;
231
93.1k
        break;
232
0
    }
233
38.7k
    case RTX_32X64: {
234
38.7k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
38.7k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
38.7k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
38.7k
        t *= mul;
238
38.7k
        s = (int) (t >> 56) - 8 - 16;
239
38.7k
        break;
240
0
    }
241
31.8k
    case RTX_64X32: {
242
31.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
31.8k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
31.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
31.8k
        t *= mul;
246
31.8k
        s = (int) (t >> 56) - 16 - 8;
247
31.8k
        break;
248
0
    }
249
56.8k
    case RTX_4X16: {
250
56.8k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
56.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
56.8k
        t = (t >> 6) * (uint32_t) mul;
253
56.8k
        s = (int) (t >> 24) - 1 - 4;
254
56.8k
        break;
255
0
    }
256
110k
    case RTX_16X4: {
257
110k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
110k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
110k
        t = (t >> 6) * (uint32_t) mul;
260
110k
        s = (int) (t >> 24) - 4 - 1;
261
110k
        break;
262
0
    }
263
33.0k
    case RTX_8X32: {
264
33.0k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
33.0k
        t         += *(const uint64_t *) l & mask;
266
33.0k
        t = (t >> 6) * mul;
267
33.0k
        s = (int) (t >> 56) - 2 - 8;
268
33.0k
        break;
269
0
    }
270
46.3k
    case RTX_32X8: {
271
46.3k
        uint64_t t = *(const uint64_t *) a & mask;
272
46.3k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
46.3k
        t = (t >> 6) * mul;
274
46.3k
        s = (int) (t >> 56) - 8 - 2;
275
46.3k
        break;
276
0
    }
277
10.6k
    case RTX_16X64: {
278
10.6k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
10.6k
        t         += *(const uint64_t *) &l[0] & mask;
280
10.6k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
10.6k
        t *= mul;
282
10.6k
        s = (int) (t >> 56) - 4 - 16;
283
10.6k
        break;
284
0
    }
285
7.87k
    case RTX_64X16: {
286
7.87k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
7.87k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
7.87k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
7.87k
        t *= mul;
290
7.87k
        s = (int) (t >> 56) - 16 - 4;
291
7.87k
        break;
292
0
    }
293
3.60M
    }
294
295
3.60M
    return (s != 0) + (s > 0);
296
3.60M
}
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
74.1M
{
305
74.1M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
74.1M
    unsigned offset;
307
74.1M
    if (tx_class == TX_CLASS_2D) {
308
68.4M
        mag += levels[1 * stride + 1];
309
68.4M
        *hi_mag = mag;
310
68.4M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
68.4M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
68.4M
    } else {
313
5.63M
        mag += levels[0 * stride + 2];
314
5.63M
        *hi_mag = mag;
315
5.63M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
5.63M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
5.63M
    }
318
74.1M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
74.1M
}
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
8.73M
{
328
8.73M
    Dav1dTileState *const ts = t->ts;
329
8.73M
    const int chroma = !!plane;
330
8.73M
    const Dav1dFrameContext *const f = t->f;
331
8.73M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
8.73M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
8.73M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
8.73M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
8.73M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
8.73M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
8.73M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
8.73M
    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
8.73M
    if (all_skip) {
346
4.36M
        *res_ctx = 0x40;
347
4.36M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
4.36M
        return -1;
349
4.36M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
4.36M
    if (lossless) {
353
1.26M
        assert(t_dim->max == TX_4X4);
354
1.26M
        *txtp = WHT_WHT;
355
3.09M
    } else if (t_dim->max + intra >= TX_64X64) {
356
682k
        *txtp = DCT_DCT;
357
2.41M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
590k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
590k
                        get_uv_inter_txtp(t_dim, *txtp);
361
1.82M
    } 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
23.4k
        *txtp = DCT_DCT;
366
1.80M
    } else {
367
1.80M
        unsigned idx;
368
1.80M
        if (intra) {
369
1.17M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
996k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.17M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
484k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
484k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
484k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
685k
            } else {
376
685k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
685k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
685k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
685k
            }
380
1.17M
            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.17M
        } else {
384
631k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
168k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
168k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
168k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
463k
            } else if (t_dim->min == TX_16X16) {
389
54.0k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
54.0k
                          ts->cdf.m.txtp_inter2, 11);
391
54.0k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
409k
            } else {
393
409k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
409k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
409k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
409k
            }
397
631k
            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
631k
        }
401
1.80M
    }
402
403
    // find end-of-block (eob)
404
4.36M
    int eob;
405
4.36M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
4.36M
    const int tx2dszctx = slw + slh;
407
4.36M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
4.36M
    const int is_1d = tx_class != TX_CLASS_2D;
409
4.36M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
4.37M
    case sz: { \
412
4.37M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
4.37M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
4.37M
        break; \
415
4.37M
    }
416
1.65M
    case_sz(0,   16,  8, [is_1d]);
417
423k
    case_sz(1,   32,  8, [is_1d]);
418
753k
    case_sz(2,   64,  8, [is_1d]);
419
393k
    case_sz(3,  128,  8, [is_1d]);
420
455k
    case_sz(4,  256, 16, [is_1d]);
421
189k
    case_sz(5,  512, 16,        );
422
501k
    case_sz(6, 1024, 16,        );
423
4.36M
#undef case_sz
424
4.36M
    }
425
4.36M
    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
4.36M
    if (eob > 1) {
429
2.86M
        const int eob_bin = eob - 2;
430
2.86M
        uint16_t *const eob_hi_bit_cdf =
431
2.86M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
2.86M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
2.86M
        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
2.86M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
2.86M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
2.86M
    }
440
4.36M
    assert(eob >= 0);
441
442
    // base tokens
443
4.36M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
4.36M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
4.36M
    unsigned rc, dc_tok;
446
447
4.36M
    if (eob) {
448
3.04M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
3.04M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
3.04M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
3.04M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
3.04M
        int tok = eob_tok + 1;
455
3.04M
        int level_tok = tok * 0x41;
456
3.04M
        unsigned mag;
457
458
3.04M
#define DECODE_COEFS_CLASS(tx_class) \
459
3.04M
        unsigned x, y; \
460
3.04M
        uint8_t *level; \
461
3.04M
        if (tx_class == TX_CLASS_2D) \
462
3.04M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
3.04M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
292k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
292k
        else /* tx_class == TX_CLASS_V */ \
467
292k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
3.04M
        if (dbg) \
469
3.04M
            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
3.04M
        if (eob_tok == 2) { \
472
68.5k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
68.5k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
68.5k
            level_tok = tok + (3 << 6); \
475
68.5k
            if (dbg) \
476
68.5k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
68.5k
        } \
480
3.04M
        cf[rc] = tok << 11; \
481
3.04M
        if (tx_class == TX_CLASS_2D) \
482
3.04M
            level = levels + rc; \
483
3.04M
        else \
484
3.04M
            level = levels + x * stride + y; \
485
3.04M
        *level = (uint8_t) level_tok; \
486
76.8M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
73.8M
            unsigned rc_i; \
488
73.8M
            if (tx_class == TX_CLASS_2D) \
489
73.8M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
73.8M
            else if (tx_class == TX_CLASS_H) \
491
5.46M
                x = i & mask, y = i >> shift, rc_i = i; \
492
5.46M
            else /* tx_class == TX_CLASS_V */ \
493
5.46M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
73.8M
            assert(x < 32 && y < 32); \
495
73.8M
            if (tx_class == TX_CLASS_2D) \
496
73.8M
                level = levels + rc_i; \
497
73.8M
            else \
498
73.8M
                level = levels + x * stride + y; \
499
73.8M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
73.8M
            if (tx_class == TX_CLASS_2D) \
501
73.8M
                y |= x; \
502
73.8M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
73.8M
            if (dbg) \
504
73.8M
                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
73.8M
            if (tok == 3) { \
507
5.92M
                mag &= 63; \
508
5.92M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
5.92M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
5.92M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
5.92M
                if (dbg) \
512
5.92M
                    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
5.92M
                *level = (uint8_t) (tok + (3 << 6)); \
516
5.92M
                cf[rc_i] = (tok << 11) | rc; \
517
5.92M
                rc = rc_i; \
518
67.9M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
67.9M
                tok *= 0x17ff41; \
521
67.9M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
67.9M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
67.9M
                if (tok) rc = rc_i; \
525
67.9M
                cf[rc_i] = tok; \
526
67.9M
            } \
527
73.8M
        } \
528
        /* dc */ \
529
3.04M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
3.04M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
3.04M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
3.04M
        if (dbg) \
533
3.04M
            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
3.04M
        if (dc_tok == 3) { \
536
1.08M
            if (tx_class == TX_CLASS_2D) \
537
1.08M
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
1.05M
                      levels[1 * stride + 1]; \
539
1.08M
            mag &= 63; \
540
1.08M
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
1.08M
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
1.08M
            if (dbg) \
543
1.08M
                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.08M
        } \
546
3.04M
        break
547
548
3.04M
        const uint16_t *scan;
549
3.04M
        switch (tx_class) {
550
2.75M
        case TX_CLASS_2D: {
551
2.75M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
2.75M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
2.75M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
2.75M
            scan = dav1d_scans[tx];
555
2.75M
            const ptrdiff_t stride = 4 << slh;
556
2.75M
            const unsigned shift = slh + 2, shift2 = 0;
557
2.75M
            const unsigned mask = (4 << slh) - 1;
558
2.75M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
2.75M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
2.75M
        }
561
183k
        case TX_CLASS_H: {
562
183k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
183k
            const ptrdiff_t stride = 16;
564
183k
            const unsigned shift = slh + 2, shift2 = 0;
565
183k
            const unsigned mask = (4 << slh) - 1;
566
183k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
183k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
183k
        }
569
109k
        case TX_CLASS_V: {
570
109k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
109k
            const ptrdiff_t stride = 16;
572
109k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
109k
            const unsigned mask = (4 << slw) - 1;
574
109k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
109k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
109k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
3.04M
        }
580
3.04M
    } else { // dc-only
581
1.32M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
1.32M
        dc_tok = 1 + tok_br;
583
1.32M
        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
1.32M
        if (tok_br == 2) {
587
52.8k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
52.8k
            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
52.8k
        }
592
1.32M
        rc = 0;
593
1.32M
    }
594
595
    // residual and sign
596
4.36M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
4.36M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
4.36M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
4.36M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
4.36M
    unsigned cul_level, dc_sign_level;
601
602
4.36M
    if (!dc_tok) {
603
765k
        cul_level = 0;
604
765k
        dc_sign_level = 1 << 6;
605
765k
        if (qm_tbl) goto ac_qm;
606
564k
        goto ac_noqm;
607
765k
    }
608
609
3.59M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
3.59M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
3.59M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
3.59M
    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
3.59M
    int dc_dq = dq_tbl[0];
617
3.59M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
3.59M
    if (qm_tbl) {
620
1.07M
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
1.07M
        if (dc_tok == 15) {
623
35.6k
            dc_tok = read_golomb(&ts->msac) + 15;
624
35.6k
            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
35.6k
            dc_tok &= 0xfffff;
629
35.6k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
1.04M
        } else {
631
1.04M
            dc_dq *= dc_tok;
632
1.04M
            assert(dc_dq <= 0xffffff);
633
1.04M
        }
634
1.07M
        cul_level = dc_tok;
635
1.07M
        dc_dq >>= dq_shift;
636
1.07M
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
1.07M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
1.60M
        if (rc) ac_qm: {
640
1.60M
            const unsigned ac_dq = dq_tbl[1];
641
11.6M
            do {
642
11.6M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
11.6M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
11.6M
                const unsigned rc_tok = cf[rc];
646
11.6M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
11.6M
                int dq_sat;
648
649
11.6M
                if (rc_tok >= (15 << 11)) {
650
694k
                    tok = read_golomb(&ts->msac) + 15;
651
694k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
694k
                    tok &= 0xfffff;
656
694k
                    dq = (dq * tok) & 0xffffff;
657
10.9M
                } else {
658
10.9M
                    tok = rc_tok >> 11;
659
10.9M
                    dq *= tok;
660
10.9M
                    assert(dq <= 0xffffff);
661
10.9M
                }
662
11.6M
                cul_level += tok;
663
11.6M
                dq >>= dq_shift;
664
11.6M
                dq_sat = umin(dq, cf_max + sign);
665
11.6M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
11.6M
                rc = rc_tok & 0x3ff;
668
11.6M
            } while (rc);
669
1.60M
        }
670
2.51M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
2.51M
        if (dc_tok == 15) {
673
86.2k
            dc_tok = read_golomb(&ts->msac) + 15;
674
86.2k
            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
86.2k
            dc_tok &= 0xfffff;
679
86.2k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
86.2k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
2.43M
        } else {
682
2.43M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
2.43M
            assert(dc_dq <= cf_max);
684
2.43M
        }
685
2.51M
        cul_level = dc_tok;
686
2.51M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
3.71M
        if (rc) ac_noqm: {
689
3.71M
            const unsigned ac_dq = dq_tbl[1];
690
17.4M
            do {
691
17.4M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
17.4M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
17.4M
                const unsigned rc_tok = cf[rc];
695
17.4M
                unsigned tok;
696
17.4M
                int dq;
697
698
                // residual
699
17.4M
                if (rc_tok >= (15 << 11)) {
700
312k
                    tok = read_golomb(&ts->msac) + 15;
701
312k
                    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
312k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
312k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
312k
                    dq = umin(dq, cf_max + sign);
711
17.1M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
17.1M
                    tok = rc_tok >> 11;
714
17.1M
                    dq = ((ac_dq * tok) >> dq_shift);
715
17.1M
                    assert(dq <= cf_max);
716
17.1M
                }
717
17.4M
                cul_level += tok;
718
17.4M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
17.4M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
17.4M
            } while (rc);
722
3.71M
        }
723
2.51M
    }
724
725
    // context
726
4.35M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
4.35M
    return eob;
729
3.59M
}
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
2.03M
{
737
2.03M
    const Dav1dFrameContext *const f = t->f;
738
2.03M
    Dav1dTileState *const ts = t->ts;
739
2.03M
    const Dav1dDSPContext *const dsp = f->dsp;
740
2.03M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
2.03M
    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
2.03M
    if (depth < 2 && tx_split[depth] &&
746
208k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
165k
    {
748
165k
        const enum RectTxfmSize sub = t_dim->sub;
749
165k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
165k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
165k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
165k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
165k
        t->bx += txsw;
755
165k
        if (txw >= txh && t->bx < f->bw)
756
124k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
124k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
165k
        t->bx -= txsw;
759
165k
        t->by += txsh;
760
165k
        if (txh >= txw && t->by < f->bh) {
761
112k
            if (dst)
762
39.6k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
112k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
112k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
112k
            t->bx += txsw;
766
112k
            if (txw >= txh && t->bx < f->bw)
767
73.0k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
73.0k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
112k
            t->bx -= txsw;
770
112k
        }
771
165k
        t->by -= txsh;
772
1.86M
    } else {
773
1.86M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
1.86M
        enum TxfmType txtp;
775
1.86M
        uint8_t cf_ctx;
776
1.86M
        int eob;
777
1.86M
        coef *cf;
778
779
1.86M
        if (t->frame_thread.pass) {
780
1.86M
            const int p = t->frame_thread.pass & 1;
781
1.86M
            assert(ts->frame_thread[p].cf);
782
1.86M
            cf = ts->frame_thread[p].cf;
783
1.86M
            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
1.86M
        if (t->frame_thread.pass != 2) {
788
1.23M
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
1.23M
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
1.23M
            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.23M
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
1.23M
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
1.23M
#define set_ctx(rep_macro) \
796
4.67M
            for (int y = 0; y < txh; y++) { \
797
3.44M
                rep_macro(txtp_map, 0, txtp); \
798
3.44M
                txtp_map += 32; \
799
3.44M
            }
800
1.23M
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
1.23M
            case_set_upto16(t_dim->lw);
802
1.23M
#undef set_ctx
803
1.23M
            if (t->frame_thread.pass == 1)
804
1.23M
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
1.23M
        } else {
806
629k
            const int cbi = *ts->frame_thread[0].cbi++;
807
629k
            eob  = cbi >> 5;
808
629k
            txtp = cbi & 0x1f;
809
629k
        }
810
1.86M
        if (!(t->frame_thread.pass & 1)) {
811
629k
            assert(dst);
812
629k
            if (eob >= 0) {
813
448k
                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
448k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
448k
                                              HIGHBD_CALL_SUFFIX);
817
448k
                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
448k
            }
820
629k
        }
821
1.86M
    }
822
2.03M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
4.88M
{
827
4.88M
    const Dav1dFrameContext *const f = t->f;
828
4.88M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
4.88M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
4.88M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
4.88M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
4.88M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
4.88M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
4.88M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
4.88M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
4.14M
                           (bw4 > ss_hor || t->bx & 1) &&
837
3.84M
                           (bh4 > ss_ver || t->by & 1);
838
839
4.88M
    if (b->skip) {
840
2.88M
        BlockContext *const a = t->a;
841
2.88M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
2.88M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
2.88M
        if (has_chroma) {
844
2.08M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
2.08M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
2.08M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
2.08M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
2.08M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
2.08M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
2.08M
        }
851
2.88M
        return;
852
2.88M
    }
853
854
1.99M
    Dav1dTileState *const ts = t->ts;
855
1.99M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.99M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.99M
    assert(t->frame_thread.pass == 1);
858
1.99M
    assert(!b->skip);
859
1.99M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.99M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.99M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
4.04M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
2.04M
        const int sub_h4 = imin(h4, 16 + init_y);
865
4.16M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
2.11M
            const int sub_w4 = imin(w4, init_x + 16);
867
2.11M
            int y_off = !!init_y, y, x;
868
4.55M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
2.43M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
2.43M
            {
871
2.43M
                int x_off = !!init_x;
872
6.24M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
3.81M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
3.81M
                {
875
3.81M
                    if (!b->intra) {
876
1.03M
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
1.03M
                                       x_off, y_off, NULL);
878
2.78M
                    } else {
879
2.78M
                        uint8_t cf_ctx = 0x40;
880
2.78M
                        enum TxfmType txtp;
881
2.78M
                        const int eob =
882
2.78M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.78M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.78M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.78M
                        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.78M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.78M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.78M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.78M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.78M
                    }
893
3.81M
                }
894
2.43M
                t->bx -= x;
895
2.43M
            }
896
2.11M
            t->by -= y;
897
898
2.11M
            if (!has_chroma) continue;
899
900
1.57M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.57M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
4.71M
            for (int pl = 0; pl < 2; pl++) {
903
6.62M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
3.48M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
3.48M
                {
906
8.21M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
4.73M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
4.73M
                    {
909
4.73M
                        uint8_t cf_ctx = 0x40;
910
4.73M
                        enum TxfmType txtp;
911
4.73M
                        if (!b->intra)
912
1.39M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.39M
                                                        bx4 + (x << ss_hor)];
914
4.73M
                        const int eob =
915
4.73M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
4.73M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
4.73M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
4.73M
                                         &txtp, &cf_ctx);
919
4.73M
                        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
4.73M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
4.73M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
4.73M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
4.73M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
4.73M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
4.73M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
4.73M
                    }
930
3.48M
                    t->bx -= x << ss_hor;
931
3.48M
                }
932
3.14M
                t->by -= y << ss_ver;
933
3.14M
            }
934
1.57M
        }
935
2.04M
    }
936
1.99M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
2.24M
{
827
2.24M
    const Dav1dFrameContext *const f = t->f;
828
2.24M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.24M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.24M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.24M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.24M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.24M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.24M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.24M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.02M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.87M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.24M
    if (b->skip) {
840
1.33M
        BlockContext *const a = t->a;
841
1.33M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.33M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.33M
        if (has_chroma) {
844
1.00M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.00M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.00M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.00M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.00M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.00M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.00M
        }
851
1.33M
        return;
852
1.33M
    }
853
854
910k
    Dav1dTileState *const ts = t->ts;
855
910k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
910k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
910k
    assert(t->frame_thread.pass == 1);
858
910k
    assert(!b->skip);
859
910k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
910k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
910k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.84M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
935k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.90M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
968k
            const int sub_w4 = imin(w4, init_x + 16);
867
968k
            int y_off = !!init_y, y, x;
868
2.06M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.09M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.09M
            {
871
1.09M
                int x_off = !!init_x;
872
2.71M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.61M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.61M
                {
875
1.61M
                    if (!b->intra) {
876
426k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
426k
                                       x_off, y_off, NULL);
878
1.19M
                    } else {
879
1.19M
                        uint8_t cf_ctx = 0x40;
880
1.19M
                        enum TxfmType txtp;
881
1.19M
                        const int eob =
882
1.19M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.19M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.19M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.19M
                        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.19M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.19M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.19M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.19M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.19M
                    }
893
1.61M
                }
894
1.09M
                t->bx -= x;
895
1.09M
            }
896
968k
            t->by -= y;
897
898
968k
            if (!has_chroma) continue;
899
900
778k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
778k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.33M
            for (int pl = 0; pl < 2; pl++) {
903
3.23M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.67M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.67M
                {
906
3.71M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.04M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.04M
                    {
909
2.04M
                        uint8_t cf_ctx = 0x40;
910
2.04M
                        enum TxfmType txtp;
911
2.04M
                        if (!b->intra)
912
593k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
593k
                                                        bx4 + (x << ss_hor)];
914
2.04M
                        const int eob =
915
2.04M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.04M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.04M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.04M
                                         &txtp, &cf_ctx);
919
2.04M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.04M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.04M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.04M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.04M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.04M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.04M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.04M
                    }
930
1.67M
                    t->bx -= x << ss_hor;
931
1.67M
                }
932
1.55M
                t->by -= y << ss_ver;
933
1.55M
            }
934
778k
        }
935
935k
    }
936
910k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
2.63M
{
827
2.63M
    const Dav1dFrameContext *const f = t->f;
828
2.63M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.63M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.63M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.63M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.63M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.63M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.63M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.63M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.12M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.96M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.63M
    if (b->skip) {
840
1.55M
        BlockContext *const a = t->a;
841
1.55M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.55M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.55M
        if (has_chroma) {
844
1.08M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.08M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.08M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.08M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.08M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.08M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.08M
        }
851
1.55M
        return;
852
1.55M
    }
853
854
1.08M
    Dav1dTileState *const ts = t->ts;
855
1.08M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.08M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.08M
    assert(t->frame_thread.pass == 1);
858
1.08M
    assert(!b->skip);
859
1.08M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.08M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.08M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.19M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.11M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.26M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.14M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.14M
            int y_off = !!init_y, y, x;
868
2.49M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.34M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.34M
            {
871
1.34M
                int x_off = !!init_x;
872
3.53M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.19M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.19M
                {
875
2.19M
                    if (!b->intra) {
876
605k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
605k
                                       x_off, y_off, NULL);
878
1.59M
                    } else {
879
1.59M
                        uint8_t cf_ctx = 0x40;
880
1.59M
                        enum TxfmType txtp;
881
1.59M
                        const int eob =
882
1.59M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.59M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.59M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.59M
                        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.59M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.59M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.59M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.59M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.59M
                    }
893
2.19M
                }
894
1.34M
                t->bx -= x;
895
1.34M
            }
896
1.14M
            t->by -= y;
897
898
1.14M
            if (!has_chroma) continue;
899
900
792k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
792k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.37M
            for (int pl = 0; pl < 2; pl++) {
903
3.39M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.80M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.80M
                {
906
4.49M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.68M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.68M
                    {
909
2.68M
                        uint8_t cf_ctx = 0x40;
910
2.68M
                        enum TxfmType txtp;
911
2.68M
                        if (!b->intra)
912
796k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
796k
                                                        bx4 + (x << ss_hor)];
914
2.68M
                        const int eob =
915
2.68M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.68M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.68M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.68M
                                         &txtp, &cf_ctx);
919
2.68M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.68M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.68M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.68M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.68M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.68M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.68M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.68M
                    }
930
1.80M
                    t->bx -= x << ss_hor;
931
1.80M
                }
932
1.58M
                t->by -= y << ss_ver;
933
1.58M
            }
934
792k
        }
935
1.11M
    }
936
1.08M
}
937
938
static int mc(Dav1dTaskContext *const t,
939
              pixel *const dst8, int16_t *const dst16, const ptrdiff_t dst_stride,
940
              const int bw4, const int bh4,
941
              const int bx, const int by, const int pl,
942
              const mv mv, const Dav1dThreadPicture *const refp, const int refidx,
943
              const enum Filter2d filter_2d)
944
1.80M
{
945
1.80M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.80M
    const Dav1dFrameContext *const f = t->f;
947
1.80M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.80M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.80M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.80M
    const int mvx = mv.x, mvy = mv.y;
951
1.80M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.80M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.80M
    const pixel *ref;
954
955
1.80M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
1.16M
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
1.16M
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
1.16M
        int w, h;
959
960
1.16M
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
787k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
787k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
787k
        } else {
964
381k
            w = f->bw * 4 >> ss_hor;
965
381k
            h = f->bh * 4 >> ss_ver;
966
381k
        }
967
1.16M
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
860k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
543k
            dy + bh4 * v_mul + !!my * 4 > h)
970
702k
        {
971
702k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
702k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
702k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
702k
                                emu_edge_buf, 192 * sizeof(pixel),
975
702k
                                refp->p.data[pl], ref_stride);
976
702k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
702k
            ref_stride = 192 * sizeof(pixel);
978
702k
        } else {
979
466k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
466k
        }
981
982
1.16M
        if (dst8 != NULL) {
983
962k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
962k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
962k
                                     HIGHBD_CALL_SUFFIX);
986
962k
        } else {
987
206k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
206k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
206k
                                      HIGHBD_CALL_SUFFIX);
990
206k
        }
991
1.16M
    } else {
992
635k
        assert(refp != &f->sr_cur);
993
994
635k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
635k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
1.27M
#define scale_mv(res, val, scale) do { \
997
1.27M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
1.27M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
1.27M
        } while (0)
1000
635k
        int pos_y, pos_x;
1001
635k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
635k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
635k
#undef scale_mv
1004
635k
        const int left = pos_x >> 10;
1005
635k
        const int top = pos_y >> 10;
1006
635k
        const int right =
1007
635k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
635k
        const int bottom =
1009
635k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
635k
        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
635k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
635k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
635k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
457k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
457k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
457k
                                w, h, left - 3, top - 3,
1023
457k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
457k
                                refp->p.data[pl], ref_stride);
1025
457k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
457k
            ref_stride = 320 * sizeof(pixel);
1027
457k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
457k
        } else {
1029
177k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
177k
        }
1031
1032
635k
        if (dst8 != NULL) {
1033
486k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
486k
                                            bw4 * h_mul, bh4 * v_mul,
1035
486k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
486k
                                            f->svc[refidx][0].step,
1037
486k
                                            f->svc[refidx][1].step
1038
486k
                                            HIGHBD_CALL_SUFFIX);
1039
486k
        } else {
1040
148k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
148k
                                             bw4 * h_mul, bh4 * v_mul,
1042
148k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
148k
                                             f->svc[refidx][0].step,
1044
148k
                                             f->svc[refidx][1].step
1045
148k
                                             HIGHBD_CALL_SUFFIX);
1046
148k
        }
1047
635k
    }
1048
1049
1.80M
    return 0;
1050
1.80M
}
1051
1052
static int obmc(Dav1dTaskContext *const t,
1053
                pixel *const dst, const ptrdiff_t dst_stride,
1054
                const uint8_t *const b_dim, const int pl,
1055
                const int bx4, const int by4, const int w4, const int h4)
1056
114k
{
1057
114k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
114k
    const Dav1dFrameContext *const f = t->f;
1059
114k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
114k
    pixel *const lap = bitfn(t->scratch.lap);
1061
114k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
114k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
114k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
114k
    int res;
1065
1066
114k
    if (t->by > t->ts->tiling.row_start &&
1067
93.7k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
80.0k
    {
1069
169k
        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
89.4k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
89.4k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
89.4k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
89.4k
            if (a_r->ref.ref[0] > 0) {
1076
87.9k
                const int ow4 = imin(step4, b_dim[0]);
1077
87.9k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
87.9k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
87.9k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
87.9k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
87.9k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
87.9k
                if (res) return res;
1083
87.9k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
87.9k
                                   h_mul * ow4, v_mul * oh4);
1085
87.9k
                i++;
1086
87.9k
            }
1087
89.4k
            x += step4;
1088
89.4k
        }
1089
80.0k
    }
1090
1091
114k
    if (t->bx > t->ts->tiling.col_start)
1092
194k
        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
101k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
101k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
101k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
101k
            if (l_r->ref.ref[0] > 0) {
1099
99.7k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
99.7k
                const int oh4 = imin(step4, b_dim[1]);
1101
99.7k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
99.7k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
99.7k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
99.7k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
99.7k
                if (res) return res;
1106
99.7k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
99.7k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
99.7k
                i++;
1109
99.7k
            }
1110
101k
            y += step4;
1111
101k
        }
1112
114k
    return 0;
1113
114k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
43.4k
{
1121
43.4k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
43.4k
    const Dav1dFrameContext *const f = t->f;
1123
43.4k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
43.4k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
43.4k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
43.4k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
43.4k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
43.4k
    const int32_t *const mat = wmp->matrix;
1129
43.4k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
43.4k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
159k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
116k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
116k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
116k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
509k
        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
393k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
393k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
393k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
393k
            const int dx = (int) (mvx >> 16) - 4;
1144
393k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
393k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
393k
            const int dy = (int) (mvy >> 16) - 4;
1147
393k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
393k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
393k
            const pixel *ref_ptr;
1151
393k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
393k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
313k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
313k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
313k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
313k
                                    refp->p.data[pl], ref_stride);
1158
313k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
313k
                ref_stride = 32 * sizeof(pixel);
1160
313k
            } else {
1161
80.0k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
80.0k
            }
1163
393k
            if (dst16 != NULL)
1164
57.1k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
57.1k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
336k
            else
1167
336k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
336k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
393k
        }
1170
116k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
22.5k
        else      dst16 += 8 * dstride;
1172
116k
    }
1173
43.4k
    return 0;
1174
43.4k
}
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.17M
{
1180
2.17M
    Dav1dTileState *const ts = t->ts;
1181
2.17M
    const Dav1dFrameContext *const f = t->f;
1182
2.17M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
2.17M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
2.17M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
2.17M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
2.17M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
2.17M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
2.17M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
2.17M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
2.17M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
2.17M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.89M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.76M
                           (bh4 > ss_ver || t->by & 1);
1194
2.17M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
2.17M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
2.17M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
2.17M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
2.17M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
4.40M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
2.22M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
2.22M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
4.54M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
2.30M
            if (b->pal_sz[0]) {
1208
14.6k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
14.6k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
14.6k
                const uint8_t *pal_idx;
1211
14.6k
                if (t->frame_thread.pass) {
1212
14.6k
                    const int p = t->frame_thread.pass & 1;
1213
14.6k
                    assert(ts->frame_thread[p].pal_idx);
1214
14.6k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
14.6k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
14.6k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
14.6k
                const pixel *const pal = t->frame_thread.pass ?
1220
14.6k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
14.6k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
14.6k
                    bytefn(t->scratch.pal)[0];
1223
14.6k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
14.6k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
14.6k
                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
14.6k
            }
1229
1230
2.30M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
2.30M
                                     sm_flag(&t->l, by4) |
1232
2.30M
                                     intra_edge_filter_flag);
1233
2.30M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
2.22M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
2.30M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
2.22M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
2.30M
            int y, x;
1238
2.30M
            const int sub_w4 = imin(w4, init_x + 16);
1239
5.20M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
2.89M
                 y += t_dim->h, t->by += t_dim->h)
1241
2.89M
            {
1242
2.89M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
2.89M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
2.89M
                                    t->bx + init_x);
1245
9.65M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
6.75M
                     x += t_dim->w, t->bx += t_dim->w)
1247
6.75M
                {
1248
6.75M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
6.73M
                    int angle = b->y_angle;
1251
6.73M
                    const enum EdgeFlags edge_flags =
1252
6.73M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
5.36M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
6.73M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
5.12M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
6.73M
                    const pixel *top_sb_edge = NULL;
1257
6.73M
                    if (!(t->by & (f->sb_step - 1))) {
1258
879k
                        top_sb_edge = f->ipred_edge[0];
1259
879k
                        const int sby = t->by >> f->sb_shift;
1260
879k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
879k
                    }
1262
6.73M
                    const enum IntraPredMode m =
1263
6.73M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
6.73M
                                                          t->bx > ts->tiling.col_start,
1265
6.73M
                                                          t->by,
1266
6.73M
                                                          t->by > ts->tiling.row_start,
1267
6.73M
                                                          ts->tiling.col_end,
1268
6.73M
                                                          ts->tiling.row_end,
1269
6.73M
                                                          edge_flags, dst,
1270
6.73M
                                                          f->cur.stride[0], top_sb_edge,
1271
6.73M
                                                          b->y_mode, &angle,
1272
6.73M
                                                          t_dim->w, t_dim->h,
1273
6.73M
                                                          f->seq_hdr->intra_edge_filter,
1274
6.73M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
6.73M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
6.73M
                                             t_dim->w * 4, t_dim->h * 4,
1277
6.73M
                                             angle | intra_flags,
1278
6.73M
                                             4 * f->bw - 4 * t->bx,
1279
6.73M
                                             4 * f->bh - 4 * t->by
1280
6.73M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
6.73M
                    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.75M
                skip_y_pred: {}
1293
6.75M
                    if (!b->skip) {
1294
1.24M
                        coef *cf;
1295
1.24M
                        int eob;
1296
1.24M
                        enum TxfmType txtp;
1297
1.24M
                        if (t->frame_thread.pass) {
1298
1.24M
                            const int p = t->frame_thread.pass & 1;
1299
1.24M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.24M
                            cf = ts->frame_thread[p].cf;
1301
1.24M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.24M
                            eob  = cbi >> 5;
1303
1.24M
                            txtp = cbi & 0x1f;
1304
1.24M
                        } 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.24M
                        if (eob >= 0) {
1317
924k
                            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
924k
                            dsp->itx.itxfm_add[b->tx]
1321
924k
                                              [txtp](dst,
1322
924k
                                                     f->cur.stride[0],
1323
924k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
924k
                            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
924k
                        }
1328
5.50M
                    } 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.75M
                    dst += 4 * t_dim->w;
1333
6.75M
                }
1334
2.89M
                t->bx -= x;
1335
2.89M
            }
1336
2.31M
            t->by -= y;
1337
1338
2.31M
            if (!has_chroma) continue;
1339
1340
1.70M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.70M
            if (b->uv_mode == CFL_PRED) {
1343
336k
                assert(!init_x && !init_y);
1344
1345
336k
                int16_t *const ac = t->scratch.ac;
1346
336k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
336k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
336k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
336k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
336k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
336k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
336k
                const int furthest_r =
1354
336k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
336k
                const int furthest_b =
1356
336k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
336k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
336k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
336k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
336k
                                                         cbw4 * 4, cbh4 * 4);
1361
1.00M
                for (int pl = 0; pl < 2; pl++) {
1362
672k
                    if (!b->cfl_alpha[pl]) continue;
1363
535k
                    int angle = 0;
1364
535k
                    const pixel *top_sb_edge = NULL;
1365
535k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
122k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
122k
                        const int sby = t->by >> f->sb_shift;
1368
122k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
122k
                    }
1370
535k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
535k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
535k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
535k
                    const enum IntraPredMode m =
1374
535k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
535k
                                                          ypos, ypos > ystart,
1376
535k
                                                          ts->tiling.col_end >> ss_hor,
1377
535k
                                                          ts->tiling.row_end >> ss_ver,
1378
535k
                                                          0, uv_dst[pl], stride,
1379
535k
                                                          top_sb_edge, DC_PRED, &angle,
1380
535k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
535k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
535k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
535k
                                           uv_t_dim->w * 4,
1384
535k
                                           uv_t_dim->h * 4,
1385
535k
                                           ac, b->cfl_alpha[pl]
1386
535k
                                           HIGHBD_CALL_SUFFIX);
1387
535k
                }
1388
336k
                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.36M
            } else if (b->pal_sz[1]) {
1394
5.64k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
5.64k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
5.64k
                const pixel (*pal)[8];
1397
5.64k
                const uint8_t *pal_idx;
1398
5.64k
                if (t->frame_thread.pass) {
1399
5.64k
                    const int p = t->frame_thread.pass & 1;
1400
5.64k
                    assert(ts->frame_thread[p].pal_idx);
1401
5.64k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
5.64k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
5.64k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
5.64k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
5.64k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
5.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
5.64k
                                       f->cur.stride[1], pal[1],
1412
5.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
5.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
5.64k
                                       f->cur.stride[1], pal[2],
1415
5.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
5.64k
                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
5.64k
            }
1425
1426
1.70M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.70M
                                 sm_uv_flag(&t->l, cby4);
1428
1.70M
            const int uv_sb_has_tr =
1429
1.70M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.65M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.70M
            const int uv_sb_has_bl =
1432
1.70M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.65M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.70M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
5.10M
            for (int pl = 0; pl < 2; pl++) {
1436
7.15M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
3.75M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
3.75M
                {
1439
3.75M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
3.75M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
3.75M
                                        ((t->bx + init_x) >> ss_hor));
1442
8.74M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
4.99M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
4.99M
                    {
1445
4.99M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
4.45M
                            b->pal_sz[1])
1447
547k
                        {
1448
547k
                            goto skip_uv_pred;
1449
547k
                        }
1450
1451
4.44M
                        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
4.44M
                        const enum EdgeFlags edge_flags =
1456
4.44M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
2.26M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
3.19M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
4.44M
                            ((x > (init_x >> ss_hor) ||
1460
3.20M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
2.86M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
4.44M
                        const pixel *top_sb_edge = NULL;
1463
4.44M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
1.09M
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
1.09M
                            const int sby = t->by >> f->sb_shift;
1466
1.09M
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
1.09M
                        }
1468
4.44M
                        const enum IntraPredMode uv_mode =
1469
4.44M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
4.44M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
4.44M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
4.44M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
4.44M
                        const enum IntraPredMode m =
1474
4.44M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
4.44M
                                                              ypos, ypos > ystart,
1476
4.44M
                                                              ts->tiling.col_end >> ss_hor,
1477
4.44M
                                                              ts->tiling.row_end >> ss_ver,
1478
4.44M
                                                              edge_flags, dst, stride,
1479
4.44M
                                                              top_sb_edge, uv_mode,
1480
4.44M
                                                              &angle, uv_t_dim->w,
1481
4.44M
                                                              uv_t_dim->h,
1482
4.44M
                                                              f->seq_hdr->intra_edge_filter,
1483
4.44M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
4.44M
                        angle |= intra_edge_filter_flag;
1485
4.44M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
4.44M
                                                 uv_t_dim->w * 4,
1487
4.44M
                                                 uv_t_dim->h * 4,
1488
4.44M
                                                 angle | sm_uv_fl,
1489
4.44M
                                                 (4 * f->bw + ss_hor -
1490
4.44M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
4.44M
                                                 (4 * f->bh + ss_ver -
1492
4.44M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
4.44M
                                                 HIGHBD_CALL_SUFFIX);
1494
4.44M
                        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
4.99M
                    skip_uv_pred: {}
1505
4.99M
                        if (!b->skip) {
1506
1.38M
                            enum TxfmType txtp;
1507
1.38M
                            int eob;
1508
1.38M
                            coef *cf;
1509
1.38M
                            if (t->frame_thread.pass) {
1510
1.38M
                                const int p = t->frame_thread.pass & 1;
1511
1.38M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.38M
                                cf = ts->frame_thread[p].cf;
1513
1.38M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.38M
                                eob  = cbi >> 5;
1515
1.38M
                                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.38M
                            if (eob >= 0) {
1533
395k
                                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
395k
                                dsp->itx.itxfm_add[b->uvtx]
1537
395k
                                                  [txtp](dst, stride,
1538
395k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
395k
                                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
395k
                            }
1543
3.61M
                        } 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
4.99M
                        dst += uv_t_dim->w * 4;
1548
4.99M
                    }
1549
3.75M
                    t->bx -= x << ss_hor;
1550
3.75M
                }
1551
3.40M
                t->by -= y << ss_ver;
1552
3.40M
            }
1553
1.70M
        }
1554
2.22M
    }
1555
2.17M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
951k
{
1180
951k
    Dav1dTileState *const ts = t->ts;
1181
951k
    const Dav1dFrameContext *const f = t->f;
1182
951k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
951k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
951k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
951k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
951k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
951k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
951k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
951k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
951k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
951k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
868k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
810k
                           (bh4 > ss_ver || t->by & 1);
1194
951k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
951k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
951k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
951k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
951k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.93M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
976k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
976k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.99M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.01M
            if (b->pal_sz[0]) {
1208
6.40k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
6.40k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
6.40k
                const uint8_t *pal_idx;
1211
6.40k
                if (t->frame_thread.pass) {
1212
6.40k
                    const int p = t->frame_thread.pass & 1;
1213
6.40k
                    assert(ts->frame_thread[p].pal_idx);
1214
6.40k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
6.40k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
6.40k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
6.40k
                const pixel *const pal = t->frame_thread.pass ?
1220
6.40k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
6.40k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
6.40k
                    bytefn(t->scratch.pal)[0];
1223
6.40k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
6.40k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
6.40k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
6.40k
            }
1229
1230
1.01M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.01M
                                     sm_flag(&t->l, by4) |
1232
1.01M
                                     intra_edge_filter_flag);
1233
1.01M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
976k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.01M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
976k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.01M
            int y, x;
1238
1.01M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.36M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.35M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.34M
            {
1242
1.34M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.34M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.34M
                                    t->bx + init_x);
1245
5.58M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
4.23M
                     x += t_dim->w, t->bx += t_dim->w)
1247
4.22M
                {
1248
4.22M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
4.22M
                    int angle = b->y_angle;
1251
4.22M
                    const enum EdgeFlags edge_flags =
1252
4.22M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
3.56M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
4.22M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
3.44M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
4.22M
                    const pixel *top_sb_edge = NULL;
1257
4.22M
                    if (!(t->by & (f->sb_step - 1))) {
1258
441k
                        top_sb_edge = f->ipred_edge[0];
1259
441k
                        const int sby = t->by >> f->sb_shift;
1260
441k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
441k
                    }
1262
4.22M
                    const enum IntraPredMode m =
1263
4.22M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
4.22M
                                                          t->bx > ts->tiling.col_start,
1265
4.22M
                                                          t->by,
1266
4.22M
                                                          t->by > ts->tiling.row_start,
1267
4.22M
                                                          ts->tiling.col_end,
1268
4.22M
                                                          ts->tiling.row_end,
1269
4.22M
                                                          edge_flags, dst,
1270
4.22M
                                                          f->cur.stride[0], top_sb_edge,
1271
4.22M
                                                          b->y_mode, &angle,
1272
4.22M
                                                          t_dim->w, t_dim->h,
1273
4.22M
                                                          f->seq_hdr->intra_edge_filter,
1274
4.22M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
4.22M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
4.22M
                                             t_dim->w * 4, t_dim->h * 4,
1277
4.22M
                                             angle | intra_flags,
1278
4.22M
                                             4 * f->bw - 4 * t->bx,
1279
4.22M
                                             4 * f->bh - 4 * t->by
1280
4.22M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
4.22M
                    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
4.23M
                skip_y_pred: {}
1293
4.23M
                    if (!b->skip) {
1294
517k
                        coef *cf;
1295
517k
                        int eob;
1296
517k
                        enum TxfmType txtp;
1297
517k
                        if (t->frame_thread.pass) {
1298
517k
                            const int p = t->frame_thread.pass & 1;
1299
517k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
517k
                            cf = ts->frame_thread[p].cf;
1301
517k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
517k
                            eob  = cbi >> 5;
1303
517k
                            txtp = cbi & 0x1f;
1304
517k
                        } 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
517k
                        if (eob >= 0) {
1317
380k
                            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
380k
                            dsp->itx.itxfm_add[b->tx]
1321
380k
                                              [txtp](dst,
1322
380k
                                                     f->cur.stride[0],
1323
380k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
380k
                            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
380k
                        }
1328
3.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
4.23M
                    dst += 4 * t_dim->w;
1333
4.23M
                }
1334
1.35M
                t->bx -= x;
1335
1.35M
            }
1336
1.01M
            t->by -= y;
1337
1338
1.01M
            if (!has_chroma) continue;
1339
1340
790k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
790k
            if (b->uv_mode == CFL_PRED) {
1343
154k
                assert(!init_x && !init_y);
1344
1345
154k
                int16_t *const ac = t->scratch.ac;
1346
154k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
154k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
154k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
154k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
154k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
154k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
154k
                const int furthest_r =
1354
154k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
154k
                const int furthest_b =
1356
154k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
154k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
154k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
154k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
154k
                                                         cbw4 * 4, cbh4 * 4);
1361
464k
                for (int pl = 0; pl < 2; pl++) {
1362
309k
                    if (!b->cfl_alpha[pl]) continue;
1363
249k
                    int angle = 0;
1364
249k
                    const pixel *top_sb_edge = NULL;
1365
249k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
53.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
53.3k
                        const int sby = t->by >> f->sb_shift;
1368
53.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
53.3k
                    }
1370
249k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
249k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
249k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
249k
                    const enum IntraPredMode m =
1374
249k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
249k
                                                          ypos, ypos > ystart,
1376
249k
                                                          ts->tiling.col_end >> ss_hor,
1377
249k
                                                          ts->tiling.row_end >> ss_ver,
1378
249k
                                                          0, uv_dst[pl], stride,
1379
249k
                                                          top_sb_edge, DC_PRED, &angle,
1380
249k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
249k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
249k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
249k
                                           uv_t_dim->w * 4,
1384
249k
                                           uv_t_dim->h * 4,
1385
249k
                                           ac, b->cfl_alpha[pl]
1386
249k
                                           HIGHBD_CALL_SUFFIX);
1387
249k
                }
1388
154k
                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
635k
            } else if (b->pal_sz[1]) {
1394
2.74k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.74k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.74k
                const pixel (*pal)[8];
1397
2.74k
                const uint8_t *pal_idx;
1398
2.74k
                if (t->frame_thread.pass) {
1399
2.74k
                    const int p = t->frame_thread.pass & 1;
1400
2.74k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.74k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.74k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.74k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.74k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.74k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.74k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.74k
                                       f->cur.stride[1], pal[1],
1412
2.74k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.74k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.74k
                                       f->cur.stride[1], pal[2],
1415
2.74k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.74k
                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.74k
            }
1425
1426
790k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
790k
                                 sm_uv_flag(&t->l, cby4);
1428
790k
            const int uv_sb_has_tr =
1429
790k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
766k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
790k
            const int uv_sb_has_bl =
1432
790k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
766k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
790k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.36M
            for (int pl = 0; pl < 2; pl++) {
1436
3.31M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.74M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.74M
                {
1439
1.74M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.74M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.74M
                                        ((t->bx + init_x) >> ss_hor));
1442
3.99M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.25M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.25M
                    {
1445
2.25M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.00M
                            b->pal_sz[1])
1447
255k
                        {
1448
255k
                            goto skip_uv_pred;
1449
255k
                        }
1450
1451
1.99M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.99M
                        const enum EdgeFlags edge_flags =
1456
1.99M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
981k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.42M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.99M
                            ((x > (init_x >> ss_hor) ||
1460
1.48M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.27M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.99M
                        const pixel *top_sb_edge = NULL;
1463
1.99M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
523k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
523k
                            const int sby = t->by >> f->sb_shift;
1466
523k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
523k
                        }
1468
1.99M
                        const enum IntraPredMode uv_mode =
1469
1.99M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.99M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.99M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.99M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.99M
                        const enum IntraPredMode m =
1474
1.99M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.99M
                                                              ypos, ypos > ystart,
1476
1.99M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.99M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.99M
                                                              edge_flags, dst, stride,
1479
1.99M
                                                              top_sb_edge, uv_mode,
1480
1.99M
                                                              &angle, uv_t_dim->w,
1481
1.99M
                                                              uv_t_dim->h,
1482
1.99M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.99M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.99M
                        angle |= intra_edge_filter_flag;
1485
1.99M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.99M
                                                 uv_t_dim->w * 4,
1487
1.99M
                                                 uv_t_dim->h * 4,
1488
1.99M
                                                 angle | sm_uv_fl,
1489
1.99M
                                                 (4 * f->bw + ss_hor -
1490
1.99M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.99M
                                                 (4 * f->bh + ss_ver -
1492
1.99M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.99M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.99M
                        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.25M
                    skip_uv_pred: {}
1505
2.25M
                        if (!b->skip) {
1506
626k
                            enum TxfmType txtp;
1507
626k
                            int eob;
1508
626k
                            coef *cf;
1509
626k
                            if (t->frame_thread.pass) {
1510
626k
                                const int p = t->frame_thread.pass & 1;
1511
626k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
626k
                                cf = ts->frame_thread[p].cf;
1513
626k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
626k
                                eob  = cbi >> 5;
1515
626k
                                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
626k
                            if (eob >= 0) {
1533
206k
                                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
206k
                                dsp->itx.itxfm_add[b->uvtx]
1537
206k
                                                  [txtp](dst, stride,
1538
206k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
206k
                                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
206k
                            }
1543
1.62M
                        } 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.25M
                        dst += uv_t_dim->w * 4;
1548
2.25M
                    }
1549
1.74M
                    t->bx -= x << ss_hor;
1550
1.74M
                }
1551
1.57M
                t->by -= y << ss_ver;
1552
1.57M
            }
1553
790k
        }
1554
976k
    }
1555
951k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
1.22M
{
1180
1.22M
    Dav1dTileState *const ts = t->ts;
1181
1.22M
    const Dav1dFrameContext *const f = t->f;
1182
1.22M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.22M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.22M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.22M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.22M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.22M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.22M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.22M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.22M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.22M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.02M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
952k
                           (bh4 > ss_ver || t->by & 1);
1194
1.22M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.22M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.22M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.22M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.22M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.47M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.25M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.25M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.54M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.29M
            if (b->pal_sz[0]) {
1208
8.20k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
8.20k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
8.20k
                const uint8_t *pal_idx;
1211
8.20k
                if (t->frame_thread.pass) {
1212
8.20k
                    const int p = t->frame_thread.pass & 1;
1213
8.20k
                    assert(ts->frame_thread[p].pal_idx);
1214
8.20k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
8.20k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
8.20k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
8.20k
                const pixel *const pal = t->frame_thread.pass ?
1220
8.20k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
8.20k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
8.20k
                    bytefn(t->scratch.pal)[0];
1223
8.20k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
8.20k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
8.20k
                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
8.20k
            }
1229
1230
1.29M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.29M
                                     sm_flag(&t->l, by4) |
1232
1.29M
                                     intra_edge_filter_flag);
1233
1.29M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.25M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.29M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.25M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.29M
            int y, x;
1238
1.29M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.84M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.54M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.54M
            {
1242
1.54M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.54M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.54M
                                    t->bx + init_x);
1245
4.07M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.52M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.52M
                {
1248
2.52M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.51M
                    int angle = b->y_angle;
1251
2.51M
                    const enum EdgeFlags edge_flags =
1252
2.51M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.80M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.51M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.67M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.51M
                    const pixel *top_sb_edge = NULL;
1257
2.51M
                    if (!(t->by & (f->sb_step - 1))) {
1258
438k
                        top_sb_edge = f->ipred_edge[0];
1259
438k
                        const int sby = t->by >> f->sb_shift;
1260
438k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
438k
                    }
1262
2.51M
                    const enum IntraPredMode m =
1263
2.51M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.51M
                                                          t->bx > ts->tiling.col_start,
1265
2.51M
                                                          t->by,
1266
2.51M
                                                          t->by > ts->tiling.row_start,
1267
2.51M
                                                          ts->tiling.col_end,
1268
2.51M
                                                          ts->tiling.row_end,
1269
2.51M
                                                          edge_flags, dst,
1270
2.51M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.51M
                                                          b->y_mode, &angle,
1272
2.51M
                                                          t_dim->w, t_dim->h,
1273
2.51M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.51M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.51M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.51M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.51M
                                             angle | intra_flags,
1278
2.51M
                                             4 * f->bw - 4 * t->bx,
1279
2.51M
                                             4 * f->bh - 4 * t->by
1280
2.51M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.51M
                    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.52M
                skip_y_pred: {}
1293
2.52M
                    if (!b->skip) {
1294
732k
                        coef *cf;
1295
732k
                        int eob;
1296
732k
                        enum TxfmType txtp;
1297
732k
                        if (t->frame_thread.pass) {
1298
732k
                            const int p = t->frame_thread.pass & 1;
1299
732k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
732k
                            cf = ts->frame_thread[p].cf;
1301
732k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
732k
                            eob  = cbi >> 5;
1303
732k
                            txtp = cbi & 0x1f;
1304
732k
                        } 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
732k
                        if (eob >= 0) {
1317
544k
                            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
544k
                            dsp->itx.itxfm_add[b->tx]
1321
544k
                                              [txtp](dst,
1322
544k
                                                     f->cur.stride[0],
1323
544k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
544k
                            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
544k
                        }
1328
1.79M
                    } 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.52M
                    dst += 4 * t_dim->w;
1333
2.52M
                }
1334
1.54M
                t->bx -= x;
1335
1.54M
            }
1336
1.29M
            t->by -= y;
1337
1338
1.29M
            if (!has_chroma) continue;
1339
1340
914k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
914k
            if (b->uv_mode == CFL_PRED) {
1343
181k
                assert(!init_x && !init_y);
1344
1345
181k
                int16_t *const ac = t->scratch.ac;
1346
181k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
181k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
181k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
181k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
181k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
181k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
181k
                const int furthest_r =
1354
181k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
181k
                const int furthest_b =
1356
181k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
181k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
181k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
181k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
181k
                                                         cbw4 * 4, cbh4 * 4);
1361
543k
                for (int pl = 0; pl < 2; pl++) {
1362
362k
                    if (!b->cfl_alpha[pl]) continue;
1363
285k
                    int angle = 0;
1364
285k
                    const pixel *top_sb_edge = NULL;
1365
285k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
69.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
69.0k
                        const int sby = t->by >> f->sb_shift;
1368
69.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
69.0k
                    }
1370
285k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
285k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
285k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
285k
                    const enum IntraPredMode m =
1374
285k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
285k
                                                          ypos, ypos > ystart,
1376
285k
                                                          ts->tiling.col_end >> ss_hor,
1377
285k
                                                          ts->tiling.row_end >> ss_ver,
1378
285k
                                                          0, uv_dst[pl], stride,
1379
285k
                                                          top_sb_edge, DC_PRED, &angle,
1380
285k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
285k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
285k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
285k
                                           uv_t_dim->w * 4,
1384
285k
                                           uv_t_dim->h * 4,
1385
285k
                                           ac, b->cfl_alpha[pl]
1386
285k
                                           HIGHBD_CALL_SUFFIX);
1387
285k
                }
1388
181k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
732k
            } else if (b->pal_sz[1]) {
1394
2.90k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.90k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.90k
                const pixel (*pal)[8];
1397
2.90k
                const uint8_t *pal_idx;
1398
2.90k
                if (t->frame_thread.pass) {
1399
2.90k
                    const int p = t->frame_thread.pass & 1;
1400
2.90k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.90k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.90k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.90k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.90k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.90k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.90k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.90k
                                       f->cur.stride[1], pal[1],
1412
2.90k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.90k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.90k
                                       f->cur.stride[1], pal[2],
1415
2.90k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.90k
                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.90k
            }
1425
1426
914k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
914k
                                 sm_uv_flag(&t->l, cby4);
1428
914k
            const int uv_sb_has_tr =
1429
914k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
890k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
914k
            const int uv_sb_has_bl =
1432
914k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
890k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
914k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.74M
            for (int pl = 0; pl < 2; pl++) {
1436
3.83M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.01M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.00M
                {
1439
2.00M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.00M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.00M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.75M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.74M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.74M
                    {
1445
2.74M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.45M
                            b->pal_sz[1])
1447
291k
                        {
1448
291k
                            goto skip_uv_pred;
1449
291k
                        }
1450
1451
2.45M
                        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.45M
                        const enum EdgeFlags edge_flags =
1456
2.45M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.28M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.76M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.45M
                            ((x > (init_x >> ss_hor) ||
1460
1.71M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.59M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.45M
                        const pixel *top_sb_edge = NULL;
1463
2.45M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
575k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
575k
                            const int sby = t->by >> f->sb_shift;
1466
575k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
575k
                        }
1468
2.45M
                        const enum IntraPredMode uv_mode =
1469
2.45M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.45M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.45M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.45M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.45M
                        const enum IntraPredMode m =
1474
2.45M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.45M
                                                              ypos, ypos > ystart,
1476
2.45M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.45M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.45M
                                                              edge_flags, dst, stride,
1479
2.45M
                                                              top_sb_edge, uv_mode,
1480
2.45M
                                                              &angle, uv_t_dim->w,
1481
2.45M
                                                              uv_t_dim->h,
1482
2.45M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.45M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.45M
                        angle |= intra_edge_filter_flag;
1485
2.45M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.45M
                                                 uv_t_dim->w * 4,
1487
2.45M
                                                 uv_t_dim->h * 4,
1488
2.45M
                                                 angle | sm_uv_fl,
1489
2.45M
                                                 (4 * f->bw + ss_hor -
1490
2.45M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.45M
                                                 (4 * f->bh + ss_ver -
1492
2.45M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.45M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.45M
                        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.74M
                    skip_uv_pred: {}
1505
2.74M
                        if (!b->skip) {
1506
754k
                            enum TxfmType txtp;
1507
754k
                            int eob;
1508
754k
                            coef *cf;
1509
754k
                            if (t->frame_thread.pass) {
1510
754k
                                const int p = t->frame_thread.pass & 1;
1511
754k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
754k
                                cf = ts->frame_thread[p].cf;
1513
754k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
754k
                                eob  = cbi >> 5;
1515
754k
                                txtp = cbi & 0x1f;
1516
754k
                            } else {
1517
0
                                uint8_t cf_ctx;
1518
0
                                cf = bitfn(t->cf);
1519
0
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
0
                                                   &t->l.ccoef[pl][cby4 + y],
1521
0
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
0
                                                   &txtp, &cf_ctx);
1523
0
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
0
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
0
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
0
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
0
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
0
                            }
1532
754k
                            if (eob >= 0) {
1533
189k
                                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
189k
                                dsp->itx.itxfm_add[b->uvtx]
1537
189k
                                                  [txtp](dst, stride,
1538
189k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
189k
                                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
189k
                            }
1543
1.98M
                        } 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.74M
                        dst += uv_t_dim->w * 4;
1548
2.74M
                    }
1549
2.01M
                    t->bx -= x << ss_hor;
1550
2.01M
                }
1551
1.82M
                t->by -= y << ss_ver;
1552
1.82M
            }
1553
914k
        }
1554
1.25M
    }
1555
1.22M
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
677k
{
1560
677k
    Dav1dTileState *const ts = t->ts;
1561
677k
    const Dav1dFrameContext *const f = t->f;
1562
677k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
677k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
677k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
677k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
677k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
677k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
677k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
677k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
677k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
415k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
388k
                           (bh4 > ss_ver || t->by & 1);
1573
677k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
677k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
677k
    int res;
1576
1577
    // prediction
1578
677k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
677k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
677k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
677k
    const ptrdiff_t uvdstoff =
1582
677k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
677k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
169k
        assert(!f->frame_hdr->super_res.enabled);
1586
169k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
169k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
169k
        if (res) return res;
1589
318k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
212k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
212k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
212k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
212k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
212k
            if (res) return res;
1595
212k
        }
1596
507k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
431k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
431k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
431k
        if (imin(bw4, bh4) > 1 &&
1601
257k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
247k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
14.0k
        {
1604
14.0k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
14.0k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
14.0k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
14.0k
            if (res) return res;
1608
417k
        } else {
1609
417k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
417k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
417k
            if (res) return res;
1612
417k
            if (b->motion_mode == MM_OBMC) {
1613
61.5k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
61.5k
                if (res) return res;
1615
61.5k
            }
1616
417k
        }
1617
431k
        if (b->interintra_type) {
1618
12.5k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
12.5k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
10.2k
                                   SMOOTH_PRED : b->interintra_mode;
1621
12.5k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
12.5k
            int angle = 0;
1623
12.5k
            const pixel *top_sb_edge = NULL;
1624
12.5k
            if (!(t->by & (f->sb_step - 1))) {
1625
6.10k
                top_sb_edge = f->ipred_edge[0];
1626
6.10k
                const int sby = t->by >> f->sb_shift;
1627
6.10k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
6.10k
            }
1629
12.5k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
12.5k
                                                  t->by, t->by > ts->tiling.row_start,
1631
12.5k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
12.5k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
12.5k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
12.5k
                                                  HIGHBD_CALL_SUFFIX);
1635
12.5k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
12.5k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
12.5k
                                     HIGHBD_CALL_SUFFIX);
1638
12.5k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
12.5k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
12.5k
        }
1641
1642
431k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
201k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
201k
        refmvs_block *const *r;
1647
201k
        if (is_sub8x8) {
1648
31.0k
            assert(ss_hor == 1);
1649
31.0k
            r = &t->rt.r[(t->by & 31) + 5];
1650
31.0k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
31.0k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
31.0k
            if (bw4 == 1 && bh4 == ss_ver)
1653
4.18k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
31.0k
        }
1655
1656
        // chroma prediction
1657
201k
        if (is_sub8x8) {
1658
30.4k
            assert(ss_hor == 1);
1659
30.4k
            ptrdiff_t h_off = 0, v_off = 0;
1660
30.4k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
12.3k
                for (int pl = 0; pl < 2; pl++) {
1662
8.24k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
8.24k
                             NULL, f->cur.stride[1],
1664
8.24k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
8.24k
                             r[-1][t->bx - 1].mv.mv[0],
1666
8.24k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
8.24k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
8.24k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
8.24k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
8.24k
                    if (res) return res;
1671
8.24k
                }
1672
4.12k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
4.12k
                h_off = 2;
1674
4.12k
            }
1675
30.4k
            if (bw4 == 1) {
1676
15.0k
                const enum Filter2d left_filter_2d =
1677
15.0k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
45.1k
                for (int pl = 0; pl < 2; pl++) {
1679
30.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
30.0k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
30.0k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
30.0k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
30.0k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
30.0k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
30.0k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
30.0k
                    if (res) return res;
1687
30.0k
                }
1688
15.0k
                h_off = 2;
1689
15.0k
            }
1690
30.4k
            if (bh4 == ss_ver) {
1691
19.5k
                const enum Filter2d top_filter_2d =
1692
19.5k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
58.6k
                for (int pl = 0; pl < 2; pl++) {
1694
39.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
39.0k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
39.0k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
39.0k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
39.0k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
39.0k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
39.0k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
39.0k
                    if (res) return res;
1702
39.0k
                }
1703
19.5k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
19.5k
            }
1705
91.3k
            for (int pl = 0; pl < 2; pl++) {
1706
60.9k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
60.9k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
60.9k
                         refp, b->ref[0], filter_2d);
1709
60.9k
                if (res) return res;
1710
60.9k
            }
1711
170k
        } else {
1712
170k
            if (imin(cbw4, cbh4) > 1 &&
1713
78.6k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
72.4k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
9.02k
            {
1716
27.0k
                for (int pl = 0; pl < 2; pl++) {
1717
18.0k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
18.0k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
18.0k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
18.0k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
18.0k
                    if (res) return res;
1722
18.0k
                }
1723
161k
            } else {
1724
485k
                for (int pl = 0; pl < 2; pl++) {
1725
323k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
323k
                             NULL, f->cur.stride[1],
1727
323k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
323k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
323k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
323k
                    if (res) return res;
1731
323k
                    if (b->motion_mode == MM_OBMC) {
1732
53.2k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
53.2k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
53.2k
                        if (res) return res;
1735
53.2k
                    }
1736
323k
                }
1737
161k
            }
1738
170k
            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
10.1k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
30.5k
                for (int pl = 0; pl < 2; pl++) {
1745
20.3k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
20.3k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
20.3k
                    enum IntraPredMode m =
1748
20.3k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
17.1k
                        SMOOTH_PRED : b->interintra_mode;
1750
20.3k
                    int angle = 0;
1751
20.3k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
20.3k
                    const pixel *top_sb_edge = NULL;
1753
20.3k
                    if (!(t->by & (f->sb_step - 1))) {
1754
9.51k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
9.51k
                        const int sby = t->by >> f->sb_shift;
1756
9.51k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
9.51k
                    }
1758
20.3k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
20.3k
                                                          (t->bx >> ss_hor) >
1760
20.3k
                                                              (ts->tiling.col_start >> ss_hor),
1761
20.3k
                                                          t->by >> ss_ver,
1762
20.3k
                                                          (t->by >> ss_ver) >
1763
20.3k
                                                              (ts->tiling.row_start >> ss_ver),
1764
20.3k
                                                          ts->tiling.col_end >> ss_hor,
1765
20.3k
                                                          ts->tiling.row_end >> ss_ver,
1766
20.3k
                                                          0, uvdst, f->cur.stride[1],
1767
20.3k
                                                          top_sb_edge, m,
1768
20.3k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
20.3k
                                                          HIGHBD_CALL_SUFFIX);
1770
20.3k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
20.3k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
20.3k
                                             HIGHBD_CALL_SUFFIX);
1773
20.3k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
20.3k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
20.3k
                }
1776
10.1k
            }
1777
170k
        }
1778
1779
431k
    skip_inter_chroma_pred: {}
1780
431k
        t->tl_4x4_filter = filter_2d;
1781
431k
    } else {
1782
76.0k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
76.0k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
76.0k
        int jnt_weight;
1786
76.0k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
76.0k
        const uint8_t *mask;
1788
1789
228k
        for (int i = 0; i < 2; i++) {
1790
152k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
152k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
5.94k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
5.94k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
5.94k
                if (res) return res;
1796
146k
            } else {
1797
146k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
146k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
146k
                if (res) return res;
1800
146k
            }
1801
152k
        }
1802
76.0k
        switch (b->comp_type) {
1803
50.9k
        case COMP_INTER_AVG:
1804
50.9k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
50.9k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
50.9k
            break;
1807
12.5k
        case COMP_INTER_WEIGHTED_AVG:
1808
12.5k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
12.5k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
12.5k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
12.5k
            break;
1812
7.74k
        case COMP_INTER_SEG:
1813
7.74k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
7.74k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
7.74k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
7.74k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
7.74k
            mask = seg_mask;
1818
7.74k
            break;
1819
4.74k
        case COMP_INTER_WEDGE:
1820
4.74k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
4.74k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
4.74k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
4.74k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
4.74k
            if (has_chroma)
1825
3.61k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
4.74k
            break;
1827
76.0k
        }
1828
1829
        // chroma
1830
160k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
321k
            for (int i = 0; i < 2; i++) {
1832
214k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
214k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
34.7k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
5.41k
                {
1836
5.41k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
5.41k
                                      b_dim, 1 + pl,
1838
5.41k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
5.41k
                    if (res) return res;
1840
208k
                } else {
1841
208k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
208k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
208k
                    if (res) return res;
1844
208k
                }
1845
214k
            }
1846
107k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
107k
            switch (b->comp_type) {
1848
69.6k
            case COMP_INTER_AVG:
1849
69.6k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
69.6k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
69.6k
                            HIGHBD_CALL_SUFFIX);
1852
69.6k
                break;
1853
17.0k
            case COMP_INTER_WEIGHTED_AVG:
1854
17.0k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
17.0k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
17.0k
                              HIGHBD_CALL_SUFFIX);
1857
17.0k
                break;
1858
7.22k
            case COMP_INTER_WEDGE:
1859
20.4k
            case COMP_INTER_SEG:
1860
20.4k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
20.4k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
20.4k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
20.4k
                             HIGHBD_CALL_SUFFIX);
1864
20.4k
                break;
1865
107k
            }
1866
107k
        }
1867
76.0k
    }
1868
1869
677k
    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
677k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
677k
    if (b->skip) {
1882
        // reset coef contexts
1883
269k
        BlockContext *const a = t->a;
1884
269k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
269k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
269k
        if (has_chroma) {
1887
116k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
116k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
116k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
116k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
116k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
116k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
116k
        }
1894
269k
        return 0;
1895
269k
    }
1896
1897
408k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
408k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
408k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
828k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
850k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
430k
            int y_off = !!init_y, y;
1905
430k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
880k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
450k
                 y += ytx->h, y_off++)
1908
450k
            {
1909
450k
                int x, x_off = !!init_x;
1910
973k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
523k
                     x += ytx->w, x_off++)
1912
523k
                {
1913
523k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
523k
                                   x_off, y_off, &dst[x * 4]);
1915
523k
                    t->bx += ytx->w;
1916
523k
                }
1917
450k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
450k
                t->bx -= x;
1919
450k
                t->by += ytx->h;
1920
450k
            }
1921
430k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
430k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
779k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
519k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
519k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
519k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.08M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
561k
                {
1931
561k
                    int x;
1932
561k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.25M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
688k
                    {
1935
688k
                        coef *cf;
1936
688k
                        int eob;
1937
688k
                        enum TxfmType txtp;
1938
688k
                        if (t->frame_thread.pass) {
1939
688k
                            const int p = t->frame_thread.pass & 1;
1940
688k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
688k
                            cf = ts->frame_thread[p].cf;
1942
688k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
688k
                            eob  = cbi >> 5;
1944
688k
                            txtp = cbi & 0x1f;
1945
688k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            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
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
688k
                        if (eob >= 0) {
1964
196k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
196k
                            dsp->itx.itxfm_add[b->uvtx]
1967
196k
                                              [txtp](&uvdst[4 * x],
1968
196k
                                                     f->cur.stride[1],
1969
196k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
196k
                            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
196k
                        }
1974
688k
                        t->bx += uvtx->w << ss_hor;
1975
688k
                    }
1976
561k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
561k
                    t->bx -= x << ss_hor;
1978
561k
                    t->by += uvtx->h << ss_ver;
1979
561k
                }
1980
519k
                t->by -= y << ss_ver;
1981
519k
            }
1982
430k
        }
1983
420k
    }
1984
408k
    return 0;
1985
677k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
285k
{
1560
285k
    Dav1dTileState *const ts = t->ts;
1561
285k
    const Dav1dFrameContext *const f = t->f;
1562
285k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
285k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
285k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
285k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
285k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
285k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
285k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
285k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
285k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
243k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
227k
                           (bh4 > ss_ver || t->by & 1);
1573
285k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
285k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
285k
    int res;
1576
1577
    // prediction
1578
285k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
285k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
285k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
285k
    const ptrdiff_t uvdstoff =
1582
285k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
285k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
85.6k
        assert(!f->frame_hdr->super_res.enabled);
1586
85.6k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
85.6k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
85.6k
        if (res) return res;
1589
209k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
139k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
139k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
139k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
139k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
139k
            if (res) return res;
1595
139k
        }
1596
200k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
164k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
164k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
164k
        if (imin(bw4, bh4) > 1 &&
1601
97.8k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
90.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
8.99k
        {
1604
8.99k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
8.99k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
8.99k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
8.99k
            if (res) return res;
1608
155k
        } else {
1609
155k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
155k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
155k
            if (res) return res;
1612
155k
            if (b->motion_mode == MM_OBMC) {
1613
20.8k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
20.8k
                if (res) return res;
1615
20.8k
            }
1616
155k
        }
1617
164k
        if (b->interintra_type) {
1618
6.88k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
6.88k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
5.53k
                                   SMOOTH_PRED : b->interintra_mode;
1621
6.88k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
6.88k
            int angle = 0;
1623
6.88k
            const pixel *top_sb_edge = NULL;
1624
6.88k
            if (!(t->by & (f->sb_step - 1))) {
1625
3.24k
                top_sb_edge = f->ipred_edge[0];
1626
3.24k
                const int sby = t->by >> f->sb_shift;
1627
3.24k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
3.24k
            }
1629
6.88k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
6.88k
                                                  t->by, t->by > ts->tiling.row_start,
1631
6.88k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
6.88k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
6.88k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
6.88k
                                                  HIGHBD_CALL_SUFFIX);
1635
6.88k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
6.88k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
6.88k
                                     HIGHBD_CALL_SUFFIX);
1638
6.88k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
6.88k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
6.88k
        }
1641
1642
164k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
113k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
113k
        refmvs_block *const *r;
1647
113k
        if (is_sub8x8) {
1648
15.5k
            assert(ss_hor == 1);
1649
15.5k
            r = &t->rt.r[(t->by & 31) + 5];
1650
15.5k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
15.5k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
15.5k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.07k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
15.5k
        }
1655
1656
        // chroma prediction
1657
113k
        if (is_sub8x8) {
1658
15.3k
            assert(ss_hor == 1);
1659
15.3k
            ptrdiff_t h_off = 0, v_off = 0;
1660
15.3k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
6.10k
                for (int pl = 0; pl < 2; pl++) {
1662
4.06k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
4.06k
                             NULL, f->cur.stride[1],
1664
4.06k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
4.06k
                             r[-1][t->bx - 1].mv.mv[0],
1666
4.06k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
4.06k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
4.06k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
4.06k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
4.06k
                    if (res) return res;
1671
4.06k
                }
1672
2.03k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.03k
                h_off = 2;
1674
2.03k
            }
1675
15.3k
            if (bw4 == 1) {
1676
8.80k
                const enum Filter2d left_filter_2d =
1677
8.80k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
26.4k
                for (int pl = 0; pl < 2; pl++) {
1679
17.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
17.6k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
17.6k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
17.6k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
17.6k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
17.6k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
17.6k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
17.6k
                    if (res) return res;
1687
17.6k
                }
1688
8.80k
                h_off = 2;
1689
8.80k
            }
1690
15.3k
            if (bh4 == ss_ver) {
1691
8.62k
                const enum Filter2d top_filter_2d =
1692
8.62k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
25.8k
                for (int pl = 0; pl < 2; pl++) {
1694
17.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
17.2k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
17.2k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
17.2k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
17.2k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
17.2k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
17.2k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
17.2k
                    if (res) return res;
1702
17.2k
                }
1703
8.62k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
8.62k
            }
1705
46.1k
            for (int pl = 0; pl < 2; pl++) {
1706
30.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
30.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
30.7k
                         refp, b->ref[0], filter_2d);
1709
30.7k
                if (res) return res;
1710
30.7k
            }
1711
97.9k
        } else {
1712
97.9k
            if (imin(cbw4, cbh4) > 1 &&
1713
44.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
40.3k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
5.83k
            {
1716
17.5k
                for (int pl = 0; pl < 2; pl++) {
1717
11.6k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
11.6k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
11.6k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
11.6k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
11.6k
                    if (res) return res;
1722
11.6k
                }
1723
92.1k
            } else {
1724
276k
                for (int pl = 0; pl < 2; pl++) {
1725
184k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
184k
                             NULL, f->cur.stride[1],
1727
184k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
184k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
184k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
184k
                    if (res) return res;
1731
184k
                    if (b->motion_mode == MM_OBMC) {
1732
29.4k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
29.4k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
29.4k
                        if (res) return res;
1735
29.4k
                    }
1736
184k
                }
1737
92.1k
            }
1738
97.9k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
6.15k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
18.4k
                for (int pl = 0; pl < 2; pl++) {
1745
12.3k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
12.3k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
12.3k
                    enum IntraPredMode m =
1748
12.3k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
10.1k
                        SMOOTH_PRED : b->interintra_mode;
1750
12.3k
                    int angle = 0;
1751
12.3k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
12.3k
                    const pixel *top_sb_edge = NULL;
1753
12.3k
                    if (!(t->by & (f->sb_step - 1))) {
1754
5.30k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
5.30k
                        const int sby = t->by >> f->sb_shift;
1756
5.30k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
5.30k
                    }
1758
12.3k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
12.3k
                                                          (t->bx >> ss_hor) >
1760
12.3k
                                                              (ts->tiling.col_start >> ss_hor),
1761
12.3k
                                                          t->by >> ss_ver,
1762
12.3k
                                                          (t->by >> ss_ver) >
1763
12.3k
                                                              (ts->tiling.row_start >> ss_ver),
1764
12.3k
                                                          ts->tiling.col_end >> ss_hor,
1765
12.3k
                                                          ts->tiling.row_end >> ss_ver,
1766
12.3k
                                                          0, uvdst, f->cur.stride[1],
1767
12.3k
                                                          top_sb_edge, m,
1768
12.3k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
12.3k
                                                          HIGHBD_CALL_SUFFIX);
1770
12.3k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
12.3k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
12.3k
                                             HIGHBD_CALL_SUFFIX);
1773
12.3k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
12.3k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
12.3k
                }
1776
6.15k
            }
1777
97.9k
        }
1778
1779
164k
    skip_inter_chroma_pred: {}
1780
164k
        t->tl_4x4_filter = filter_2d;
1781
164k
    } else {
1782
36.0k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
36.0k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
36.0k
        int jnt_weight;
1786
36.0k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
36.0k
        const uint8_t *mask;
1788
1789
108k
        for (int i = 0; i < 2; i++) {
1790
72.1k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
72.1k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
3.12k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
3.12k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
3.12k
                if (res) return res;
1796
69.0k
            } else {
1797
69.0k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
69.0k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
69.0k
                if (res) return res;
1800
69.0k
            }
1801
72.1k
        }
1802
36.0k
        switch (b->comp_type) {
1803
25.7k
        case COMP_INTER_AVG:
1804
25.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
25.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
25.7k
            break;
1807
4.35k
        case COMP_INTER_WEIGHTED_AVG:
1808
4.35k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
4.35k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
4.35k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
4.35k
            break;
1812
3.55k
        case COMP_INTER_SEG:
1813
3.55k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
3.55k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
3.55k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
3.55k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
3.55k
            mask = seg_mask;
1818
3.55k
            break;
1819
2.45k
        case COMP_INTER_WEDGE:
1820
2.45k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.45k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.45k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.45k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.45k
            if (has_chroma)
1825
2.00k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.45k
            break;
1827
36.0k
        }
1828
1829
        // chroma
1830
85.6k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
171k
            for (int i = 0; i < 2; i++) {
1832
114k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
114k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
18.9k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.53k
                {
1836
2.53k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.53k
                                      b_dim, 1 + pl,
1838
2.53k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.53k
                    if (res) return res;
1840
111k
                } else {
1841
111k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
111k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
111k
                    if (res) return res;
1844
111k
                }
1845
114k
            }
1846
57.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
57.0k
            switch (b->comp_type) {
1848
39.7k
            case COMP_INTER_AVG:
1849
39.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
39.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
39.7k
                            HIGHBD_CALL_SUFFIX);
1852
39.7k
                break;
1853
7.24k
            case COMP_INTER_WEIGHTED_AVG:
1854
7.24k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
7.24k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
7.24k
                              HIGHBD_CALL_SUFFIX);
1857
7.24k
                break;
1858
4.01k
            case COMP_INTER_WEDGE:
1859
10.1k
            case COMP_INTER_SEG:
1860
10.1k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
10.1k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
10.1k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
10.1k
                             HIGHBD_CALL_SUFFIX);
1864
10.1k
                break;
1865
57.0k
            }
1866
57.0k
        }
1867
36.0k
    }
1868
1869
285k
    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
285k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
285k
    if (b->skip) {
1882
        // reset coef contexts
1883
97.7k
        BlockContext *const a = t->a;
1884
97.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
97.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
97.7k
        if (has_chroma) {
1887
70.5k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
70.5k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
70.5k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
70.5k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
70.5k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
70.5k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
70.5k
        }
1894
97.7k
        return 0;
1895
97.7k
    }
1896
1897
188k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
188k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
188k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
382k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
394k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
200k
            int y_off = !!init_y, y;
1905
200k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
407k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
207k
                 y += ytx->h, y_off++)
1908
207k
            {
1909
207k
                int x, x_off = !!init_x;
1910
443k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
236k
                     x += ytx->w, x_off++)
1912
236k
                {
1913
236k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
236k
                                   x_off, y_off, &dst[x * 4]);
1915
236k
                    t->bx += ytx->w;
1916
236k
                }
1917
207k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
207k
                t->bx -= x;
1919
207k
                t->by += ytx->h;
1920
207k
            }
1921
200k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
200k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
453k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
302k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
302k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
302k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
624k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
321k
                {
1931
321k
                    int x;
1932
321k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
694k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
372k
                    {
1935
372k
                        coef *cf;
1936
372k
                        int eob;
1937
372k
                        enum TxfmType txtp;
1938
372k
                        if (t->frame_thread.pass) {
1939
372k
                            const int p = t->frame_thread.pass & 1;
1940
372k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
372k
                            cf = ts->frame_thread[p].cf;
1942
372k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
372k
                            eob  = cbi >> 5;
1944
372k
                            txtp = cbi & 0x1f;
1945
372k
                        } 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
372k
                        if (eob >= 0) {
1964
98.4k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
98.4k
                            dsp->itx.itxfm_add[b->uvtx]
1967
98.4k
                                              [txtp](&uvdst[4 * x],
1968
98.4k
                                                     f->cur.stride[1],
1969
98.4k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
98.4k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
98.4k
                        }
1974
372k
                        t->bx += uvtx->w << ss_hor;
1975
372k
                    }
1976
321k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
321k
                    t->bx -= x << ss_hor;
1978
321k
                    t->by += uvtx->h << ss_ver;
1979
321k
                }
1980
302k
                t->by -= y << ss_ver;
1981
302k
            }
1982
200k
        }
1983
194k
    }
1984
188k
    return 0;
1985
285k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
391k
{
1560
391k
    Dav1dTileState *const ts = t->ts;
1561
391k
    const Dav1dFrameContext *const f = t->f;
1562
391k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
391k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
391k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
391k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
391k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
391k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
391k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
391k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
391k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
171k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
161k
                           (bh4 > ss_ver || t->by & 1);
1573
391k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
391k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
391k
    int res;
1576
1577
    // prediction
1578
391k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
391k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
391k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
391k
    const ptrdiff_t uvdstoff =
1582
391k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
391k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
83.9k
        assert(!f->frame_hdr->super_res.enabled);
1586
83.9k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
83.9k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
83.9k
        if (res) return res;
1589
108k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
72.2k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
72.2k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
72.2k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
72.2k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
72.2k
            if (res) return res;
1595
72.2k
        }
1596
307k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
267k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
267k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
267k
        if (imin(bw4, bh4) > 1 &&
1601
159k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
157k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.07k
        {
1604
5.07k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.07k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.07k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.07k
            if (res) return res;
1608
262k
        } else {
1609
262k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
262k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
262k
            if (res) return res;
1612
262k
            if (b->motion_mode == MM_OBMC) {
1613
40.7k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
40.7k
                if (res) return res;
1615
40.7k
            }
1616
262k
        }
1617
267k
        if (b->interintra_type) {
1618
5.62k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
5.62k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
4.71k
                                   SMOOTH_PRED : b->interintra_mode;
1621
5.62k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
5.62k
            int angle = 0;
1623
5.62k
            const pixel *top_sb_edge = NULL;
1624
5.62k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.85k
                top_sb_edge = f->ipred_edge[0];
1626
2.85k
                const int sby = t->by >> f->sb_shift;
1627
2.85k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.85k
            }
1629
5.62k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
5.62k
                                                  t->by, t->by > ts->tiling.row_start,
1631
5.62k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
5.62k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
5.62k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
5.62k
                                                  HIGHBD_CALL_SUFFIX);
1635
5.62k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
5.62k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
5.62k
                                     HIGHBD_CALL_SUFFIX);
1638
5.62k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
5.62k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
5.62k
        }
1641
1642
267k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
88.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
88.0k
        refmvs_block *const *r;
1647
88.0k
        if (is_sub8x8) {
1648
15.4k
            assert(ss_hor == 1);
1649
15.4k
            r = &t->rt.r[(t->by & 31) + 5];
1650
15.4k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
15.4k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
15.4k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.11k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
15.4k
        }
1655
1656
        // chroma prediction
1657
88.0k
        if (is_sub8x8) {
1658
15.0k
            assert(ss_hor == 1);
1659
15.0k
            ptrdiff_t h_off = 0, v_off = 0;
1660
15.0k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
6.27k
                for (int pl = 0; pl < 2; pl++) {
1662
4.18k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
4.18k
                             NULL, f->cur.stride[1],
1664
4.18k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
4.18k
                             r[-1][t->bx - 1].mv.mv[0],
1666
4.18k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
4.18k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
4.18k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
4.18k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
4.18k
                    if (res) return res;
1671
4.18k
                }
1672
2.09k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.09k
                h_off = 2;
1674
2.09k
            }
1675
15.0k
            if (bw4 == 1) {
1676
6.24k
                const enum Filter2d left_filter_2d =
1677
6.24k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
18.7k
                for (int pl = 0; pl < 2; pl++) {
1679
12.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
12.4k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
12.4k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
12.4k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
12.4k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
12.4k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
12.4k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
12.4k
                    if (res) return res;
1687
12.4k
                }
1688
6.24k
                h_off = 2;
1689
6.24k
            }
1690
15.0k
            if (bh4 == ss_ver) {
1691
10.9k
                const enum Filter2d top_filter_2d =
1692
10.9k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
32.7k
                for (int pl = 0; pl < 2; pl++) {
1694
21.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
21.8k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
21.8k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
21.8k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
21.8k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
21.8k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
21.8k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
21.8k
                    if (res) return res;
1702
21.8k
                }
1703
10.9k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
10.9k
            }
1705
45.2k
            for (int pl = 0; pl < 2; pl++) {
1706
30.1k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
30.1k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
30.1k
                         refp, b->ref[0], filter_2d);
1709
30.1k
                if (res) return res;
1710
30.1k
            }
1711
72.9k
        } else {
1712
72.9k
            if (imin(cbw4, cbh4) > 1 &&
1713
33.9k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
32.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.19k
            {
1716
9.57k
                for (int pl = 0; pl < 2; pl++) {
1717
6.38k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
6.38k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
6.38k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
6.38k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
6.38k
                    if (res) return res;
1722
6.38k
                }
1723
69.7k
            } else {
1724
209k
                for (int pl = 0; pl < 2; pl++) {
1725
139k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
139k
                             NULL, f->cur.stride[1],
1727
139k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
139k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
139k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
139k
                    if (res) return res;
1731
139k
                    if (b->motion_mode == MM_OBMC) {
1732
23.8k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
23.8k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
23.8k
                        if (res) return res;
1735
23.8k
                    }
1736
139k
                }
1737
69.7k
            }
1738
72.9k
            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
4.01k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
12.0k
                for (int pl = 0; pl < 2; pl++) {
1745
8.03k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
8.03k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
8.03k
                    enum IntraPredMode m =
1748
8.03k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
7.01k
                        SMOOTH_PRED : b->interintra_mode;
1750
8.03k
                    int angle = 0;
1751
8.03k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
8.03k
                    const pixel *top_sb_edge = NULL;
1753
8.03k
                    if (!(t->by & (f->sb_step - 1))) {
1754
4.20k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
4.20k
                        const int sby = t->by >> f->sb_shift;
1756
4.20k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
4.20k
                    }
1758
8.03k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
8.03k
                                                          (t->bx >> ss_hor) >
1760
8.03k
                                                              (ts->tiling.col_start >> ss_hor),
1761
8.03k
                                                          t->by >> ss_ver,
1762
8.03k
                                                          (t->by >> ss_ver) >
1763
8.03k
                                                              (ts->tiling.row_start >> ss_ver),
1764
8.03k
                                                          ts->tiling.col_end >> ss_hor,
1765
8.03k
                                                          ts->tiling.row_end >> ss_ver,
1766
8.03k
                                                          0, uvdst, f->cur.stride[1],
1767
8.03k
                                                          top_sb_edge, m,
1768
8.03k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
8.03k
                                                          HIGHBD_CALL_SUFFIX);
1770
8.03k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
8.03k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
8.03k
                                             HIGHBD_CALL_SUFFIX);
1773
8.03k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
8.03k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
8.03k
                }
1776
4.01k
            }
1777
72.9k
        }
1778
1779
267k
    skip_inter_chroma_pred: {}
1780
267k
        t->tl_4x4_filter = filter_2d;
1781
267k
    } else {
1782
39.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
39.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
39.9k
        int jnt_weight;
1786
39.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
39.9k
        const uint8_t *mask;
1788
1789
119k
        for (int i = 0; i < 2; i++) {
1790
79.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
79.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.82k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.82k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.82k
                if (res) return res;
1796
77.0k
            } else {
1797
77.0k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
77.0k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
77.0k
                if (res) return res;
1800
77.0k
            }
1801
79.8k
        }
1802
39.9k
        switch (b->comp_type) {
1803
25.2k
        case COMP_INTER_AVG:
1804
25.2k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
25.2k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
25.2k
            break;
1807
8.19k
        case COMP_INTER_WEIGHTED_AVG:
1808
8.19k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
8.19k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
8.19k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
8.19k
            break;
1812
4.19k
        case COMP_INTER_SEG:
1813
4.19k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.19k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.19k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.19k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.19k
            mask = seg_mask;
1818
4.19k
            break;
1819
2.29k
        case COMP_INTER_WEDGE:
1820
2.29k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.29k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.29k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.29k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.29k
            if (has_chroma)
1825
1.60k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.29k
            break;
1827
39.9k
        }
1828
1829
        // chroma
1830
75.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
150k
            for (int i = 0; i < 2; i++) {
1832
100k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
100k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
15.7k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.87k
                {
1836
2.87k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.87k
                                      b_dim, 1 + pl,
1838
2.87k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.87k
                    if (res) return res;
1840
97.3k
                } else {
1841
97.3k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
97.3k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
97.3k
                    if (res) return res;
1844
97.3k
                }
1845
100k
            }
1846
50.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
50.0k
            switch (b->comp_type) {
1848
29.9k
            case COMP_INTER_AVG:
1849
29.9k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
29.9k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
29.9k
                            HIGHBD_CALL_SUFFIX);
1852
29.9k
                break;
1853
9.81k
            case COMP_INTER_WEIGHTED_AVG:
1854
9.81k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
9.81k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
9.81k
                              HIGHBD_CALL_SUFFIX);
1857
9.81k
                break;
1858
3.21k
            case COMP_INTER_WEDGE:
1859
10.3k
            case COMP_INTER_SEG:
1860
10.3k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
10.3k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
10.3k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
10.3k
                             HIGHBD_CALL_SUFFIX);
1864
10.3k
                break;
1865
50.0k
            }
1866
50.0k
        }
1867
39.9k
    }
1868
1869
391k
    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
391k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
391k
    if (b->skip) {
1882
        // reset coef contexts
1883
171k
        BlockContext *const a = t->a;
1884
171k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
171k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
171k
        if (has_chroma) {
1887
46.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
46.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
46.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
46.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
46.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
46.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
46.2k
        }
1894
171k
        return 0;
1895
171k
    }
1896
1897
219k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
219k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
219k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
445k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
456k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
230k
            int y_off = !!init_y, y;
1905
230k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
473k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
242k
                 y += ytx->h, y_off++)
1908
242k
            {
1909
242k
                int x, x_off = !!init_x;
1910
529k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
286k
                     x += ytx->w, x_off++)
1912
286k
                {
1913
286k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
286k
                                   x_off, y_off, &dst[x * 4]);
1915
286k
                    t->bx += ytx->w;
1916
286k
                }
1917
242k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
242k
                t->bx -= x;
1919
242k
                t->by += ytx->h;
1920
242k
            }
1921
230k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
230k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
325k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
217k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
217k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
217k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
456k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
239k
                {
1931
239k
                    int x;
1932
239k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
555k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
316k
                    {
1935
316k
                        coef *cf;
1936
316k
                        int eob;
1937
316k
                        enum TxfmType txtp;
1938
316k
                        if (t->frame_thread.pass) {
1939
316k
                            const int p = t->frame_thread.pass & 1;
1940
316k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
316k
                            cf = ts->frame_thread[p].cf;
1942
316k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
316k
                            eob  = cbi >> 5;
1944
316k
                            txtp = cbi & 0x1f;
1945
316k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            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
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
316k
                        if (eob >= 0) {
1964
98.1k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
98.1k
                            dsp->itx.itxfm_add[b->uvtx]
1967
98.1k
                                              [txtp](&uvdst[4 * x],
1968
98.1k
                                                     f->cur.stride[1],
1969
98.1k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
98.1k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
98.1k
                        }
1974
316k
                        t->bx += uvtx->w << ss_hor;
1975
316k
                    }
1976
239k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
239k
                    t->bx -= x << ss_hor;
1978
239k
                    t->by += uvtx->h << ss_ver;
1979
239k
                }
1980
217k
                t->by -= y << ss_ver;
1981
217k
            }
1982
230k
        }
1983
225k
    }
1984
219k
    return 0;
1985
391k
}
1986
1987
272k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
272k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
272k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
272k
    const int y = sby * f->sb_step * 4;
1994
272k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
272k
    pixel *const p[3] = {
1996
272k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
272k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
272k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
272k
    };
2000
272k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
272k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
272k
                                        f->lf.start_of_tile_row[sby]);
2003
272k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
122k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
122k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
122k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
122k
    const int y = sby * f->sb_step * 4;
1994
122k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
122k
    pixel *const p[3] = {
1996
122k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
122k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
122k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
122k
    };
2000
122k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
122k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
122k
                                        f->lf.start_of_tile_row[sby]);
2003
122k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
150k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
150k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
150k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
150k
    const int y = sby * f->sb_step * 4;
1994
150k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
150k
    pixel *const p[3] = {
1996
150k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
150k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
150k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
150k
    };
2000
150k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
150k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
150k
                                        f->lf.start_of_tile_row[sby]);
2003
150k
}
2004
2005
308k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
308k
    const int y = sby * f->sb_step * 4;
2007
308k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
308k
    pixel *const p[3] = {
2009
308k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
308k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
308k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
308k
    };
2013
308k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
308k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
308k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
272k
    {
2017
272k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
272k
    }
2019
308k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
244k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
244k
    }
2023
308k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
140k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
140k
    const int y = sby * f->sb_step * 4;
2007
140k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
140k
    pixel *const p[3] = {
2009
140k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
140k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
140k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
140k
    };
2013
140k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
140k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
140k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
121k
    {
2017
121k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
121k
    }
2019
140k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
105k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
105k
    }
2023
140k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
167k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
167k
    const int y = sby * f->sb_step * 4;
2007
167k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
167k
    pixel *const p[3] = {
2009
167k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
167k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
167k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
167k
    };
2013
167k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
167k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
167k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
150k
    {
2017
150k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
150k
    }
2019
167k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
139k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
139k
    }
2023
167k
}
2024
2025
155k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
155k
    const Dav1dFrameContext *const f = tc->f;
2027
155k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
155k
    const int sbsz = f->sb_step;
2029
155k
    const int y = sby * sbsz * 4;
2030
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
155k
    pixel *const p[3] = {
2032
155k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
155k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
155k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
155k
    };
2036
155k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
155k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
155k
    const int start = sby * sbsz;
2039
155k
    if (sby) {
2040
64.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
64.5k
        pixel *p_up[3] = {
2042
64.5k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
64.5k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
64.5k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
64.5k
        };
2046
64.5k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
64.5k
    }
2048
155k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
155k
    const int end = imin(start + n_blks, f->bh);
2050
155k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
155k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
76.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
76.8k
    const Dav1dFrameContext *const f = tc->f;
2027
76.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
76.8k
    const int sbsz = f->sb_step;
2029
76.8k
    const int y = sby * sbsz * 4;
2030
76.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
76.8k
    pixel *const p[3] = {
2032
76.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
76.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
76.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
76.8k
    };
2036
76.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
76.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
76.8k
    const int start = sby * sbsz;
2039
76.8k
    if (sby) {
2040
35.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
35.7k
        pixel *p_up[3] = {
2042
35.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
35.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
35.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
35.7k
        };
2046
35.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
35.7k
    }
2048
76.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
76.8k
    const int end = imin(start + n_blks, f->bh);
2050
76.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
76.8k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
78.6k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
78.6k
    const Dav1dFrameContext *const f = tc->f;
2027
78.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
78.6k
    const int sbsz = f->sb_step;
2029
78.6k
    const int y = sby * sbsz * 4;
2030
78.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
78.6k
    pixel *const p[3] = {
2032
78.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
78.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
78.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
78.6k
    };
2036
78.6k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
78.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
78.6k
    const int start = sby * sbsz;
2039
78.6k
    if (sby) {
2040
28.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
28.8k
        pixel *p_up[3] = {
2042
28.8k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
28.8k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
28.8k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
28.8k
        };
2046
28.8k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
28.8k
    }
2048
78.6k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
78.6k
    const int end = imin(start + n_blks, f->bh);
2050
78.6k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
78.6k
}
2052
2053
48.1k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
48.1k
    const int sbsz = f->sb_step;
2055
48.1k
    const int y = sby * sbsz * 4;
2056
48.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
48.1k
    const pixel *const p[3] = {
2058
48.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
48.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
48.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
48.1k
    };
2062
48.1k
    pixel *const sr_p[3] = {
2063
48.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
48.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
48.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
48.1k
    };
2067
48.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
172k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
124k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
124k
        const int h_start = 8 * !!sby >> ss_ver;
2071
124k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
124k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
124k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
124k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
124k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
124k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
124k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
124k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
124k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
124k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
124k
                          imin(img_h, h_end) + h_start, src_w,
2083
124k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
124k
                          HIGHBD_CALL_SUFFIX);
2085
124k
    }
2086
48.1k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
22.1k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
22.1k
    const int sbsz = f->sb_step;
2055
22.1k
    const int y = sby * sbsz * 4;
2056
22.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
22.1k
    const pixel *const p[3] = {
2058
22.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
22.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
22.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
22.1k
    };
2062
22.1k
    pixel *const sr_p[3] = {
2063
22.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
22.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
22.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
22.1k
    };
2067
22.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
77.5k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
55.4k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
55.4k
        const int h_start = 8 * !!sby >> ss_ver;
2071
55.4k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
55.4k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
55.4k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
55.4k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
55.4k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
55.4k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
55.4k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
55.4k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
55.4k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
55.4k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
55.4k
                          imin(img_h, h_end) + h_start, src_w,
2083
55.4k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
55.4k
                          HIGHBD_CALL_SUFFIX);
2085
55.4k
    }
2086
22.1k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
26.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
26.0k
    const int sbsz = f->sb_step;
2055
26.0k
    const int y = sby * sbsz * 4;
2056
26.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
26.0k
    const pixel *const p[3] = {
2058
26.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
26.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
26.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
26.0k
    };
2062
26.0k
    pixel *const sr_p[3] = {
2063
26.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
26.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
26.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
26.0k
    };
2067
26.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
95.1k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
69.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
69.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
69.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
69.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
69.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
69.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
69.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
69.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
69.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
69.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
69.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
69.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
69.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
69.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
69.1k
                          HIGHBD_CALL_SUFFIX);
2085
69.1k
    }
2086
26.0k
}
2087
2088
173k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
173k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
173k
    const int y = sby * f->sb_step * 4;
2091
173k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
173k
    pixel *const sr_p[3] = {
2093
173k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
173k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
173k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
173k
    };
2097
173k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
173k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
73.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
73.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
73.3k
    const int y = sby * f->sb_step * 4;
2091
73.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
73.3k
    pixel *const sr_p[3] = {
2093
73.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
73.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
73.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
73.3k
    };
2097
73.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
73.3k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
100k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
100k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
100k
    const int y = sby * f->sb_step * 4;
2091
100k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
100k
    pixel *const sr_p[3] = {
2093
100k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
100k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
100k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
100k
    };
2097
100k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
100k
}
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
347k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
347k
    const Dav1dFrameContext *const f = t->f;
2113
347k
    Dav1dTileState *const ts = t->ts;
2114
347k
    const int sby = t->by >> f->sb_shift;
2115
347k
    const int sby_off = f->sb128w * 128 * sby;
2116
347k
    const int x_off = ts->tiling.col_start;
2117
2118
347k
    const pixel *const y =
2119
347k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
347k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
347k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
347k
               4 * (ts->tiling.col_end - x_off));
2123
2124
347k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
247k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
247k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
247k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
247k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
742k
        for (int pl = 1; pl <= 2; pl++)
2131
494k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
256k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
256k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
247k
    }
2135
347k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
161k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
161k
    const Dav1dFrameContext *const f = t->f;
2113
161k
    Dav1dTileState *const ts = t->ts;
2114
161k
    const int sby = t->by >> f->sb_shift;
2115
161k
    const int sby_off = f->sb128w * 128 * sby;
2116
161k
    const int x_off = ts->tiling.col_start;
2117
2118
161k
    const pixel *const y =
2119
161k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
161k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
161k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
161k
               4 * (ts->tiling.col_end - x_off));
2123
2124
161k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
128k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
128k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
128k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
128k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
385k
        for (int pl = 1; pl <= 2; pl++)
2131
256k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
256k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
256k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
128k
    }
2135
161k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
186k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
186k
    const Dav1dFrameContext *const f = t->f;
2113
186k
    Dav1dTileState *const ts = t->ts;
2114
186k
    const int sby = t->by >> f->sb_shift;
2115
186k
    const int sby_off = f->sb128w * 128 * sby;
2116
186k
    const int x_off = ts->tiling.col_start;
2117
2118
186k
    const pixel *const y =
2119
186k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
186k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
186k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
186k
               4 * (ts->tiling.col_end - x_off));
2123
2124
186k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
119k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
119k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
119k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
119k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
357k
        for (int pl = 1; pl <= 2; pl++)
2131
238k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
119k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
119k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
119k
    }
2135
186k
}
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
38.7k
{
2142
38.7k
    const Dav1dFrameContext *const f = t->f;
2143
38.7k
    pixel *const pal = t->frame_thread.pass ?
2144
38.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
38.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.4E
        bytefn(t->scratch.pal)[0];
2147
182k
    for (int x = 0; x < bw4; x++)
2148
143k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
157k
    for (int y = 0; y < bh4; y++)
2150
118k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
38.7k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
18.2k
{
2142
18.2k
    const Dav1dFrameContext *const f = t->f;
2143
18.2k
    pixel *const pal = t->frame_thread.pass ?
2144
18.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
18.2k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.2k
        bytefn(t->scratch.pal)[0];
2147
84.8k
    for (int x = 0; x < bw4; x++)
2148
66.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
73.2k
    for (int y = 0; y < bh4; y++)
2150
54.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
18.2k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
20.5k
{
2142
20.5k
    const Dav1dFrameContext *const f = t->f;
2143
20.5k
    pixel *const pal = t->frame_thread.pass ?
2144
20.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
20.5k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.4E
        bytefn(t->scratch.pal)[0];
2147
97.7k
    for (int x = 0; x < bw4; x++)
2148
77.2k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
84.0k
    for (int y = 0; y < bh4; y++)
2150
63.5k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
20.5k
}
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
15.2k
{
2158
15.2k
    const Dav1dFrameContext *const f = t->f;
2159
15.2k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
15.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
15.2k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
15.2k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
45.8k
    for (int pl = 1; pl <= 2; pl++) {
2165
181k
        for (int x = 0; x < bw4; x++)
2166
150k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
155k
        for (int y = 0; y < bh4; y++)
2168
124k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
30.5k
    }
2170
15.2k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
7.18k
{
2158
7.18k
    const Dav1dFrameContext *const f = t->f;
2159
7.18k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.18k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.18k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.18k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
21.5k
    for (int pl = 1; pl <= 2; pl++) {
2165
85.9k
        for (int x = 0; x < bw4; x++)
2166
71.6k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
74.0k
        for (int y = 0; y < bh4; y++)
2168
59.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
14.3k
    }
2170
7.18k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
8.11k
{
2158
8.11k
    const Dav1dFrameContext *const f = t->f;
2159
8.11k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.11k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.11k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.11k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
24.3k
    for (int pl = 1; pl <= 2; pl++) {
2165
95.1k
        for (int x = 0; x < bw4; x++)
2166
78.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
81.2k
        for (int y = 0; y < bh4; y++)
2168
65.0k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
16.2k
    }
2170
8.11k
}
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
54.0k
{
2176
54.0k
    Dav1dTileState *const ts = t->ts;
2177
54.0k
    const Dav1dFrameContext *const f = t->f;
2178
54.0k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
54.0k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
54.0k
    pixel cache[16], used_cache[8];
2181
54.0k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
54.0k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
54.0k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
54.0k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
54.0k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
91.7k
    while (l_cache && a_cache) {
2190
37.7k
        if (*l < *a) {
2191
13.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
13.8k
                cache[n_cache++] = *l;
2193
13.9k
            l++;
2194
13.9k
            l_cache--;
2195
23.7k
        } else {
2196
23.7k
            if (*a == *l) {
2197
9.50k
                l++;
2198
9.50k
                l_cache--;
2199
9.50k
            }
2200
23.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
22.8k
                cache[n_cache++] = *a;
2202
23.7k
            a++;
2203
23.7k
            a_cache--;
2204
23.7k
        }
2205
37.7k
    }
2206
54.0k
    if (l_cache) {
2207
62.1k
        do {
2208
62.1k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
50.6k
                cache[n_cache++] = *l;
2210
62.1k
            l++;
2211
62.1k
        } while (--l_cache > 0);
2212
39.1k
    } else if (a_cache) {
2213
44.3k
        do {
2214
44.3k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
35.8k
                cache[n_cache++] = *a;
2216
44.3k
            a++;
2217
44.3k
        } while (--a_cache > 0);
2218
11.1k
    }
2219
2220
    // find reused cache entries
2221
54.0k
    int i = 0;
2222
163k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
108k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
54.3k
            used_cache[i++] = cache[n];
2225
54.0k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
54.0k
    pixel *const pal = t->frame_thread.pass ?
2229
54.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
54.0k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
54.0k
        bytefn(t->scratch.pal)[pl];
2232
54.0k
    if (i < pal_sz) {
2233
47.1k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
47.1k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
47.1k
        if (i < pal_sz) {
2237
42.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
42.7k
            const int max = (1 << bpc) - 1;
2239
2240
99.3k
            do {
2241
99.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
99.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
99.3k
                if (prev + !pl >= max) {
2244
56.7k
                    for (; i < pal_sz; i++)
2245
36.6k
                        pal[i] = max;
2246
20.1k
                    break;
2247
20.1k
                }
2248
79.2k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
79.2k
            } while (i < pal_sz);
2250
42.7k
        }
2251
2252
        // merge cache+new entries
2253
47.1k
        int n = 0, m = n_used_cache;
2254
265k
        for (i = 0; i < pal_sz; i++) {
2255
218k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
35.3k
                pal[i] = used_cache[n++];
2257
183k
            } else {
2258
183k
                assert(m < pal_sz);
2259
183k
                pal[i] = pal[m++];
2260
183k
            }
2261
218k
        }
2262
47.1k
    } else {
2263
6.92k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
6.92k
    }
2265
2266
54.0k
    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
54.0k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
25.4k
{
2176
25.4k
    Dav1dTileState *const ts = t->ts;
2177
25.4k
    const Dav1dFrameContext *const f = t->f;
2178
25.4k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
25.4k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
25.4k
    pixel cache[16], used_cache[8];
2181
25.4k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
25.4k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
25.4k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
25.4k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
25.4k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
43.4k
    while (l_cache && a_cache) {
2190
17.9k
        if (*l < *a) {
2191
6.77k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.71k
                cache[n_cache++] = *l;
2193
6.77k
            l++;
2194
6.77k
            l_cache--;
2195
11.2k
        } else {
2196
11.2k
            if (*a == *l) {
2197
4.38k
                l++;
2198
4.38k
                l_cache--;
2199
4.38k
            }
2200
11.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.8k
                cache[n_cache++] = *a;
2202
11.2k
            a++;
2203
11.2k
            a_cache--;
2204
11.2k
        }
2205
17.9k
    }
2206
25.4k
    if (l_cache) {
2207
28.6k
        do {
2208
28.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
23.2k
                cache[n_cache++] = *l;
2210
28.6k
            l++;
2211
28.6k
        } while (--l_cache > 0);
2212
18.6k
    } else if (a_cache) {
2213
20.7k
        do {
2214
20.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
16.6k
                cache[n_cache++] = *a;
2216
20.7k
            a++;
2217
20.7k
        } while (--a_cache > 0);
2218
5.22k
    }
2219
2220
    // find reused cache entries
2221
25.4k
    int i = 0;
2222
76.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
50.7k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
25.2k
            used_cache[i++] = cache[n];
2225
25.4k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
25.4k
    pixel *const pal = t->frame_thread.pass ?
2229
25.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
25.4k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
25.4k
        bytefn(t->scratch.pal)[pl];
2232
25.4k
    if (i < pal_sz) {
2233
22.3k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
22.3k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
22.3k
        if (i < pal_sz) {
2237
20.2k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
20.2k
            const int max = (1 << bpc) - 1;
2239
2240
47.2k
            do {
2241
47.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
47.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
47.2k
                if (prev + !pl >= max) {
2244
27.3k
                    for (; i < pal_sz; i++)
2245
17.6k
                        pal[i] = max;
2246
9.66k
                    break;
2247
9.66k
                }
2248
37.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
37.5k
            } while (i < pal_sz);
2250
20.2k
        }
2251
2252
        // merge cache+new entries
2253
22.3k
        int n = 0, m = n_used_cache;
2254
126k
        for (i = 0; i < pal_sz; i++) {
2255
103k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
16.5k
                pal[i] = used_cache[n++];
2257
87.2k
            } else {
2258
87.2k
                assert(m < pal_sz);
2259
87.2k
                pal[i] = pal[m++];
2260
87.2k
            }
2261
103k
        }
2262
22.3k
    } else {
2263
3.15k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.15k
    }
2265
2266
25.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
25.4k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
28.6k
{
2176
28.6k
    Dav1dTileState *const ts = t->ts;
2177
28.6k
    const Dav1dFrameContext *const f = t->f;
2178
28.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
28.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
28.6k
    pixel cache[16], used_cache[8];
2181
28.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
28.6k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
28.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
28.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
28.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
48.3k
    while (l_cache && a_cache) {
2190
19.7k
        if (*l < *a) {
2191
7.18k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
7.13k
                cache[n_cache++] = *l;
2193
7.18k
            l++;
2194
7.18k
            l_cache--;
2195
12.5k
        } else {
2196
12.5k
            if (*a == *l) {
2197
5.12k
                l++;
2198
5.12k
                l_cache--;
2199
5.12k
            }
2200
12.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
11.9k
                cache[n_cache++] = *a;
2202
12.5k
            a++;
2203
12.5k
            a_cache--;
2204
12.5k
        }
2205
19.7k
    }
2206
28.6k
    if (l_cache) {
2207
33.4k
        do {
2208
33.4k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
27.4k
                cache[n_cache++] = *l;
2210
33.4k
            l++;
2211
33.4k
        } while (--l_cache > 0);
2212
20.5k
    } else if (a_cache) {
2213
23.6k
        do {
2214
23.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
19.1k
                cache[n_cache++] = *a;
2216
23.6k
            a++;
2217
23.6k
        } while (--a_cache > 0);
2218
5.97k
    }
2219
2220
    // find reused cache entries
2221
28.6k
    int i = 0;
2222
86.8k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
58.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
29.0k
            used_cache[i++] = cache[n];
2225
28.6k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
28.6k
    pixel *const pal = t->frame_thread.pass ?
2229
28.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
28.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
28.6k
        bytefn(t->scratch.pal)[pl];
2232
28.6k
    if (i < pal_sz) {
2233
24.8k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
24.8k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
24.8k
        if (i < pal_sz) {
2237
22.5k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
22.5k
            const int max = (1 << bpc) - 1;
2239
2240
52.1k
            do {
2241
52.1k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
52.1k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
52.1k
                if (prev + !pl >= max) {
2244
29.4k
                    for (; i < pal_sz; i++)
2245
18.9k
                        pal[i] = max;
2246
10.4k
                    break;
2247
10.4k
                }
2248
41.6k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
41.6k
            } while (i < pal_sz);
2250
22.5k
        }
2251
2252
        // merge cache+new entries
2253
24.8k
        int n = 0, m = n_used_cache;
2254
139k
        for (i = 0; i < pal_sz; i++) {
2255
114k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
18.8k
                pal[i] = used_cache[n++];
2257
95.9k
            } else {
2258
95.9k
                assert(m < pal_sz);
2259
95.9k
                pal[i] = pal[m++];
2260
95.9k
            }
2261
114k
        }
2262
24.8k
    } else {
2263
3.76k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.76k
    }
2265
2266
28.6k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
28.6k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
15.2k
{
2281
15.2k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
15.2k
    Dav1dTileState *const ts = t->ts;
2285
15.2k
    const Dav1dFrameContext *const f = t->f;
2286
15.2k
    pixel *const pal = t->frame_thread.pass ?
2287
15.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
15.2k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
15.2k
        bytefn(t->scratch.pal)[2];
2290
15.2k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
15.2k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
7.81k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
7.81k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
7.81k
        const int max = (1 << bpc) - 1;
2295
32.9k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
25.1k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
25.1k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
25.1k
            prev = pal[i] = (prev + delta) & max;
2299
25.1k
        }
2300
7.81k
    } else {
2301
39.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
31.6k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
7.48k
    }
2304
15.2k
    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
15.2k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
7.18k
{
2281
7.18k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.18k
    Dav1dTileState *const ts = t->ts;
2285
7.18k
    const Dav1dFrameContext *const f = t->f;
2286
7.18k
    pixel *const pal = t->frame_thread.pass ?
2287
7.18k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.18k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
7.18k
        bytefn(t->scratch.pal)[2];
2290
7.18k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.18k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.72k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.72k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.72k
        const int max = (1 << bpc) - 1;
2295
15.8k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
12.1k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
12.1k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
12.1k
            prev = pal[i] = (prev + delta) & max;
2299
12.1k
        }
2300
3.72k
    } else {
2301
18.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
14.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.45k
    }
2304
7.18k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
7.18k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
8.11k
{
2281
8.11k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.11k
    Dav1dTileState *const ts = t->ts;
2285
8.11k
    const Dav1dFrameContext *const f = t->f;
2286
8.11k
    pixel *const pal = t->frame_thread.pass ?
2287
8.11k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.11k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
8.11k
        bytefn(t->scratch.pal)[2];
2290
8.11k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
8.11k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.08k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.08k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.08k
        const int max = (1 << bpc) - 1;
2295
17.0k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
12.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
12.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
12.9k
            prev = pal[i] = (prev + delta) & max;
2299
12.9k
        }
2300
4.08k
    } else {
2301
21.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
17.0k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.03k
    }
2304
8.11k
    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.11k
}