Coverage Report

Created: 2026-12-01 06:50

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
703k
static inline unsigned read_golomb(MsacContext *const msac) {
50
703k
    int len = 0;
51
703k
    unsigned val = 1;
52
53
1.24M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.24M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
703k
    return val - 1;
57
703k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
4.37M
{
66
4.37M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.37M
    if (chroma) {
69
2.09M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.09M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.09M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.38M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.09M
        unsigned ca, cl;
74
75
2.09M
#define MERGE_CTX(dir, type, no_val) \
76
4.18M
        c##dir = *(const type *) dir != no_val; \
77
4.18M
        break
78
79
2.09M
        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
766k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
422k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
325k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
580k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.09M
        }
91
2.09M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
893k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
421k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
256k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
522k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.09M
        }
98
2.09M
#undef MERGE_CTX
99
100
2.09M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.27M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
870k
        return 0;
103
1.40M
    } else {
104
1.40M
        unsigned la, ll;
105
106
1.40M
#define MERGE_CTX(dir, type, tx) \
107
2.82M
        if (tx == TX_64X64) { \
108
205k
            uint64_t tmp = *(const uint64_t *) dir; \
109
205k
            tmp |= *(const uint64_t *) &dir[8]; \
110
205k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
205k
        } else \
112
2.82M
            l##dir = *(const type *) dir; \
113
2.82M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.82M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.82M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.82M
        break
117
118
1.40M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
783k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
323k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
180k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
21.1k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
102k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.40M
        }
126
1.41M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
792k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
313k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
182k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
20.8k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
102k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.41M
        }
134
1.41M
#undef MERGE_CTX
135
136
1.41M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.41M
    }
138
4.37M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.82M
{
144
1.82M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.82M
    int s;
146
147
1.82M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.82M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.82M
#endif
152
153
1.82M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
671k
    case TX_4X4: {
156
671k
        int t = *(const uint8_t *) a >> 6;
157
671k
        t    += *(const uint8_t *) l >> 6;
158
671k
        s = t - 1 - 1;
159
671k
        break;
160
0
    }
161
198k
    case TX_8X8: {
162
198k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
198k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
198k
        t *= 0x04040404U;
165
198k
        s = (int) (t >> 24) - 2 - 2;
166
198k
        break;
167
0
    }
168
136k
    case TX_16X16: {
169
136k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
136k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
136k
        t *= (uint32_t) mul;
172
136k
        s = (int) (t >> 24) - 4 - 4;
173
136k
        break;
174
0
    }
175
157k
    case TX_32X32: {
176
157k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
157k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
157k
        t *= mul;
179
157k
        s = (int) (t >> 56) - 8 - 8;
180
157k
        break;
181
0
    }
182
81.2k
    case TX_64X64: {
183
81.2k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
81.2k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
81.2k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
81.2k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
81.2k
        t *= mul;
188
81.2k
        s = (int) (t >> 56) - 16 - 16;
189
81.2k
        break;
190
0
    }
191
55.3k
    case RTX_4X8: {
192
55.3k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
55.3k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
55.3k
        t *= 0x04040404U;
195
55.3k
        s = (int) (t >> 24) - 1 - 2;
196
55.3k
        break;
197
0
    }
198
91.2k
    case RTX_8X4: {
199
91.2k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
91.2k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
91.2k
        t *= 0x04040404U;
202
91.2k
        s = (int) (t >> 24) - 2 - 1;
203
91.2k
        break;
204
0
    }
205
49.5k
    case RTX_8X16: {
206
49.5k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
49.5k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
49.5k
        t = (t >> 6) * (uint32_t) mul;
209
49.5k
        s = (int) (t >> 24) - 2 - 4;
210
49.5k
        break;
211
0
    }
212
105k
    case RTX_16X8: {
213
105k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
105k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
105k
        t = (t >> 6) * (uint32_t) mul;
216
105k
        s = (int) (t >> 24) - 4 - 2;
217
105k
        break;
218
0
    }
219
32.6k
    case RTX_16X32: {
220
32.6k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
32.6k
        t         += *(const uint64_t *) l & mask;
222
32.6k
        t = (t >> 6) * mul;
223
32.6k
        s = (int) (t >> 56) - 4 - 8;
224
32.6k
        break;
225
0
    }
226
74.1k
    case RTX_32X16: {
227
74.1k
        uint64_t t = *(const uint64_t *) a & mask;
228
74.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
74.1k
        t = (t >> 6) * mul;
230
74.1k
        s = (int) (t >> 56) - 8 - 4;
231
74.1k
        break;
232
0
    }
233
26.8k
    case RTX_32X64: {
234
26.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
26.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
26.8k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
26.8k
        t *= mul;
238
26.8k
        s = (int) (t >> 56) - 8 - 16;
239
26.8k
        break;
240
0
    }
241
29.1k
    case RTX_64X32: {
242
29.1k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
29.1k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
29.1k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
29.1k
        t *= mul;
246
29.1k
        s = (int) (t >> 56) - 16 - 8;
247
29.1k
        break;
248
0
    }
249
23.9k
    case RTX_4X16: {
250
23.9k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
23.9k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
23.9k
        t = (t >> 6) * (uint32_t) mul;
253
23.9k
        s = (int) (t >> 24) - 1 - 4;
254
23.9k
        break;
255
0
    }
256
48.4k
    case RTX_16X4: {
257
48.4k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
48.4k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
48.4k
        t = (t >> 6) * (uint32_t) mul;
260
48.4k
        s = (int) (t >> 24) - 4 - 1;
261
48.4k
        break;
262
0
    }
263
15.1k
    case RTX_8X32: {
264
15.1k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
15.1k
        t         += *(const uint64_t *) l & mask;
266
15.1k
        t = (t >> 6) * mul;
267
15.1k
        s = (int) (t >> 56) - 2 - 8;
268
15.1k
        break;
269
0
    }
270
22.6k
    case RTX_32X8: {
271
22.6k
        uint64_t t = *(const uint64_t *) a & mask;
272
22.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
22.6k
        t = (t >> 6) * mul;
274
22.6k
        s = (int) (t >> 56) - 8 - 2;
275
22.6k
        break;
276
0
    }
277
5.35k
    case RTX_16X64: {
278
5.35k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
5.35k
        t         += *(const uint64_t *) &l[0] & mask;
280
5.35k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
5.35k
        t *= mul;
282
5.35k
        s = (int) (t >> 56) - 4 - 16;
283
5.35k
        break;
284
0
    }
285
4.13k
    case RTX_64X16: {
286
4.13k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.13k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.13k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.13k
        t *= mul;
290
4.13k
        s = (int) (t >> 56) - 16 - 4;
291
4.13k
        break;
292
0
    }
293
1.82M
    }
294
295
1.82M
    return (s != 0) + (s > 0);
296
1.82M
}
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
36.7M
{
305
36.7M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
36.7M
    unsigned offset;
307
36.7M
    if (tx_class == TX_CLASS_2D) {
308
34.3M
        mag += levels[1 * stride + 1];
309
34.3M
        *hi_mag = mag;
310
34.3M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
34.3M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
34.3M
    } else {
313
2.48M
        mag += levels[0 * stride + 2];
314
2.48M
        *hi_mag = mag;
315
2.48M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.48M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.48M
    }
318
36.7M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
36.7M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
4.37M
{
328
4.37M
    Dav1dTileState *const ts = t->ts;
329
4.37M
    const int chroma = !!plane;
330
4.37M
    const Dav1dFrameContext *const f = t->f;
331
4.37M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.37M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.37M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.37M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.37M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.37M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.37M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.37M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
4.37M
    if (all_skip) {
346
2.17M
        *res_ctx = 0x40;
347
2.17M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.17M
        return -1;
349
2.17M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.19M
    if (lossless) {
353
577k
        assert(t_dim->max == TX_4X4);
354
577k
        *txtp = WHT_WHT;
355
1.62M
    } else if (t_dim->max + intra >= TX_64X64) {
356
411k
        *txtp = DCT_DCT;
357
1.20M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
255k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
255k
                        get_uv_inter_txtp(t_dim, *txtp);
361
954k
    } 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
19.8k
        *txtp = DCT_DCT;
366
934k
    } else {
367
934k
        unsigned idx;
368
934k
        if (intra) {
369
555k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
482k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
555k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
224k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
224k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
224k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
331k
            } else {
376
331k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
331k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
331k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
331k
            }
380
555k
            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
555k
        } else {
384
378k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
140k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
140k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
140k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
238k
            } else if (t_dim->min == TX_16X16) {
389
36.7k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
36.7k
                          ts->cdf.m.txtp_inter2, 11);
391
36.7k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
202k
            } else {
393
202k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
202k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
202k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
202k
            }
397
378k
            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
378k
        }
401
934k
    }
402
403
    // find end-of-block (eob)
404
2.19M
    int eob;
405
2.19M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.19M
    const int tx2dszctx = slw + slh;
407
2.19M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.19M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.19M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.20M
    case sz: { \
412
2.20M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.20M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.20M
        break; \
415
2.20M
    }
416
788k
    case_sz(0,   16,  8, [is_1d]);
417
193k
    case_sz(1,   32,  8, [is_1d]);
418
353k
    case_sz(2,   64,  8, [is_1d]);
419
205k
    case_sz(3,  128,  8, [is_1d]);
420
216k
    case_sz(4,  256, 16, [is_1d]);
421
132k
    case_sz(5,  512, 16,        );
422
312k
    case_sz(6, 1024, 16,        );
423
2.19M
#undef case_sz
424
2.19M
    }
425
2.20M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
2.20M
    if (eob > 1) {
429
1.47M
        const int eob_bin = eob - 2;
430
1.47M
        uint16_t *const eob_hi_bit_cdf =
431
1.47M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.47M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.47M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.47M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.47M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.47M
    }
440
2.20M
    assert(eob >= 0);
441
442
    // base tokens
443
2.20M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.20M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.20M
    unsigned rc, dc_tok;
446
447
2.20M
    if (eob) {
448
1.55M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.55M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.55M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.55M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.55M
        int tok = eob_tok + 1;
455
1.55M
        int level_tok = tok * 0x41;
456
1.55M
        unsigned mag;
457
458
1.55M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.55M
        unsigned x, y; \
460
1.55M
        uint8_t *level; \
461
1.55M
        if (tx_class == TX_CLASS_2D) \
462
1.55M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.55M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
129k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
129k
        else /* tx_class == TX_CLASS_V */ \
467
129k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.55M
        if (dbg) \
469
1.55M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.55M
        if (eob_tok == 2) { \
472
42.6k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
42.6k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
42.6k
            level_tok = tok + (3 << 6); \
475
42.6k
            if (dbg) \
476
42.6k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
42.6k
        } \
480
1.55M
        cf[rc] = tok << 11; \
481
1.55M
        if (tx_class == TX_CLASS_2D) \
482
1.55M
            level = levels + rc; \
483
1.55M
        else \
484
1.55M
            level = levels + x * stride + y; \
485
1.55M
        *level = (uint8_t) level_tok; \
486
38.2M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
36.6M
            unsigned rc_i; \
488
36.6M
            if (tx_class == TX_CLASS_2D) \
489
36.6M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
36.6M
            else if (tx_class == TX_CLASS_H) \
491
2.39M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.39M
            else /* tx_class == TX_CLASS_V */ \
493
2.39M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
36.6M
            assert(x < 32 && y < 32); \
495
36.6M
            if (tx_class == TX_CLASS_2D) \
496
36.6M
                level = levels + rc_i; \
497
36.6M
            else \
498
36.6M
                level = levels + x * stride + y; \
499
36.6M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
36.6M
            if (tx_class == TX_CLASS_2D) \
501
36.6M
                y |= x; \
502
36.6M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
36.6M
            if (dbg) \
504
36.6M
                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
36.6M
            if (tok == 3) { \
507
3.05M
                mag &= 63; \
508
3.05M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
3.05M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
3.05M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
3.05M
                if (dbg) \
512
3.05M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
3.05M
                *level = (uint8_t) (tok + (3 << 6)); \
516
3.05M
                cf[rc_i] = (tok << 11) | rc; \
517
3.05M
                rc = rc_i; \
518
33.6M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
33.6M
                tok *= 0x17ff41; \
521
33.6M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
33.6M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
33.6M
                if (tok) rc = rc_i; \
525
33.6M
                cf[rc_i] = tok; \
526
33.6M
            } \
527
36.6M
        } \
528
        /* dc */ \
529
1.55M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.55M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.55M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.55M
        if (dbg) \
533
1.55M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.55M
        if (dc_tok == 3) { \
536
588k
            if (tx_class == TX_CLASS_2D) \
537
588k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
576k
                      levels[1 * stride + 1]; \
539
588k
            mag &= 63; \
540
588k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
588k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
588k
            if (dbg) \
543
588k
                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
588k
        } \
546
1.55M
        break
547
548
1.55M
        const uint16_t *scan;
549
1.55M
        switch (tx_class) {
550
1.42M
        case TX_CLASS_2D: {
551
1.42M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.42M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.42M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.42M
            scan = dav1d_scans[tx];
555
1.42M
            const ptrdiff_t stride = 4 << slh;
556
1.42M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.42M
            const unsigned mask = (4 << slh) - 1;
558
1.42M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.42M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.42M
        }
561
85.2k
        case TX_CLASS_H: {
562
85.2k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
85.2k
            const ptrdiff_t stride = 16;
564
85.2k
            const unsigned shift = slh + 2, shift2 = 0;
565
85.2k
            const unsigned mask = (4 << slh) - 1;
566
85.2k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
85.2k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
85.2k
        }
569
44.5k
        case TX_CLASS_V: {
570
44.5k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
44.5k
            const ptrdiff_t stride = 16;
572
44.5k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
44.5k
            const unsigned mask = (4 << slw) - 1;
574
44.5k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
44.5k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
44.5k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.55M
        }
580
1.55M
    } else { // dc-only
581
648k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
648k
        dc_tok = 1 + tok_br;
583
648k
        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
648k
        if (tok_br == 2) {
587
29.8k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
29.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
29.8k
        }
592
648k
        rc = 0;
593
648k
    }
594
595
    // residual and sign
596
2.20M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.20M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.20M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.20M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.20M
    unsigned cul_level, dc_sign_level;
601
602
2.20M
    if (!dc_tok) {
603
374k
        cul_level = 0;
604
374k
        dc_sign_level = 1 << 6;
605
374k
        if (qm_tbl) goto ac_qm;
606
282k
        goto ac_noqm;
607
374k
    }
608
609
1.82M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.82M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.82M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.82M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.82M
    int dc_dq = dq_tbl[0];
617
1.82M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.82M
    if (qm_tbl) {
620
507k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
507k
        if (dc_tok == 15) {
623
17.0k
            dc_tok = read_golomb(&ts->msac) + 15;
624
17.0k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
17.0k
            dc_tok &= 0xfffff;
629
17.0k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
490k
        } else {
631
490k
            dc_dq *= dc_tok;
632
490k
            assert(dc_dq <= 0xffffff);
633
490k
        }
634
507k
        cul_level = dc_tok;
635
507k
        dc_dq >>= dq_shift;
636
507k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
507k
        cf[0] = (coef) apply_sign_bool(dc_dq, dc_sign);
638
639
760k
        if (rc) ac_qm: {
640
760k
            const unsigned ac_dq = dq_tbl[1];
641
5.56M
            do {
642
5.56M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
5.56M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
5.56M
                const unsigned rc_tok = cf[rc];
646
5.56M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
5.56M
                int dq_sat;
648
649
5.56M
                if (rc_tok >= (15 << 11)) {
650
440k
                    tok = read_golomb(&ts->msac) + 15;
651
440k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
440k
                    tok &= 0xfffff;
656
440k
                    dq = (dq * tok) & 0xffffff;
657
5.12M
                } else {
658
5.12M
                    tok = rc_tok >> 11;
659
5.12M
                    dq *= tok;
660
5.12M
                    assert(dq <= 0xffffff);
661
5.12M
                }
662
5.56M
                cul_level += tok;
663
5.56M
                dq >>= dq_shift;
664
5.56M
                dq_sat = umin(dq, cf_max + sign);
665
5.56M
                cf[rc] = (coef) apply_sign_bool(dq_sat, sign);
666
667
5.56M
                rc = rc_tok & 0x3ff;
668
5.56M
            } while (rc);
669
760k
        }
670
1.32M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.32M
        if (dc_tok == 15) {
673
50.7k
            dc_tok = read_golomb(&ts->msac) + 15;
674
50.7k
            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
50.7k
            dc_tok &= 0xfffff;
679
50.7k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
50.7k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.27M
        } else {
682
1.27M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.27M
            assert(dc_dq <= cf_max);
684
1.27M
        }
685
1.32M
        cul_level = dc_tok;
686
1.32M
        cf[0] = (coef) apply_sign_bool(dc_dq, dc_sign);
687
688
1.97M
        if (rc) ac_noqm: {
689
1.97M
            const unsigned ac_dq = dq_tbl[1];
690
9.10M
            do {
691
9.10M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
9.10M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
9.10M
                const unsigned rc_tok = cf[rc];
695
9.10M
                unsigned tok;
696
9.10M
                int dq;
697
698
                // residual
699
9.10M
                if (rc_tok >= (15 << 11)) {
700
194k
                    tok = read_golomb(&ts->msac) + 15;
701
194k
                    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
194k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
194k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
194k
                    dq = umin(dq, cf_max + sign);
711
8.91M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
8.91M
                    tok = rc_tok >> 11;
714
8.91M
                    dq = ((ac_dq * tok) >> dq_shift);
715
8.91M
                    assert(dq <= cf_max);
716
8.91M
                }
717
9.10M
                cul_level += tok;
718
9.10M
                cf[rc] = (coef) apply_sign_bool(dq, sign);
719
720
9.10M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
9.10M
            } while (rc);
722
1.97M
        }
723
1.32M
    }
724
725
    // context
726
2.20M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.20M
    return eob;
729
1.82M
}
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
911k
{
737
911k
    const Dav1dFrameContext *const f = t->f;
738
911k
    Dav1dTileState *const ts = t->ts;
739
911k
    const Dav1dDSPContext *const dsp = f->dsp;
740
911k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
911k
    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
911k
    if (depth < 2 && tx_split[depth] &&
746
132k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
96.4k
    {
748
96.4k
        const enum RectTxfmSize sub = t_dim->sub;
749
96.4k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
96.4k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
96.4k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
96.4k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
96.4k
        t->bx += txsw;
755
96.4k
        if (txw >= txh && t->bx < f->bw)
756
75.3k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
75.3k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
96.4k
        t->bx -= txsw;
759
96.4k
        t->by += txsh;
760
96.4k
        if (txh >= txw && t->by < f->bh) {
761
69.1k
            if (dst)
762
21.6k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
69.1k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
69.1k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
69.1k
            t->bx += txsw;
766
69.1k
            if (txw >= txh && t->bx < f->bw)
767
48.2k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
48.2k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
69.1k
            t->bx -= txsw;
770
69.1k
        }
771
96.4k
        t->by -= txsh;
772
814k
    } else {
773
814k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
814k
        enum TxfmType txtp;
775
814k
        uint8_t cf_ctx;
776
814k
        int eob;
777
814k
        coef *cf;
778
779
814k
        if (t->frame_thread.pass) {
780
814k
            const int p = t->frame_thread.pass & 1;
781
814k
            assert(ts->frame_thread[p].cf);
782
814k
            cf = ts->frame_thread[p].cf;
783
814k
            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
814k
        if (t->frame_thread.pass != 2) {
788
562k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
562k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
562k
            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
562k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
562k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
562k
#define set_ctx(rep_macro) \
796
2.42M
            for (int y = 0; y < txh; y++) { \
797
1.86M
                rep_macro(txtp_map, 0, txtp); \
798
1.86M
                txtp_map += 32; \
799
1.86M
            }
800
562k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
562k
            case_set_upto16(t_dim->lw);
802
562k
#undef set_ctx
803
562k
            if (t->frame_thread.pass == 1)
804
562k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
562k
        } else {
806
252k
            const int cbi = *ts->frame_thread[0].cbi++;
807
252k
            eob  = cbi >> 5;
808
252k
            txtp = cbi & 0x1f;
809
252k
        }
810
814k
        if (!(t->frame_thread.pass & 1)) {
811
252k
            assert(dst);
812
252k
            if (eob >= 0) {
813
197k
                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
197k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
197k
                                              HIGHBD_CALL_SUFFIX);
817
197k
                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
197k
            }
820
252k
        }
821
814k
    }
822
911k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.53M
{
827
2.53M
    const Dav1dFrameContext *const f = t->f;
828
2.53M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.53M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.53M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.53M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.53M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.53M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.53M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.53M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.99M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.76M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.53M
    if (b->skip) {
840
1.44M
        BlockContext *const a = t->a;
841
1.44M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.44M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.44M
        if (has_chroma) {
844
893k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
893k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
893k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
893k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
893k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
893k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
893k
        }
851
1.44M
        return;
852
1.44M
    }
853
854
1.09M
    Dav1dTileState *const ts = t->ts;
855
1.09M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.09M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.09M
    assert(t->frame_thread.pass == 1);
858
1.09M
    assert(!b->skip);
859
1.09M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.09M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.09M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.21M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.12M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.28M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.16M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.16M
            int y_off = !!init_y, y, x;
868
2.51M
            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.49M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.14M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.14M
                {
875
2.14M
                    if (!b->intra) {
876
428k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
428k
                                       x_off, y_off, NULL);
878
1.72M
                    } else {
879
1.72M
                        uint8_t cf_ctx = 0x40;
880
1.72M
                        enum TxfmType txtp;
881
1.72M
                        const int eob =
882
1.72M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.72M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.72M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.72M
                        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.72M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.72M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.72M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.72M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.72M
                    }
893
2.14M
                }
894
1.34M
                t->bx -= x;
895
1.34M
            }
896
1.16M
            t->by -= y;
897
898
1.16M
            if (!has_chroma) continue;
899
900
783k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
783k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.35M
            for (int pl = 0; pl < 2; pl++) {
903
3.24M
                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.77M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.09M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.09M
                    {
909
2.09M
                        uint8_t cf_ctx = 0x40;
910
2.09M
                        enum TxfmType txtp;
911
2.09M
                        if (!b->intra)
912
522k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
522k
                                                        bx4 + (x << ss_hor)];
914
2.09M
                        const int eob =
915
2.09M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.09M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.09M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.09M
                                         &txtp, &cf_ctx);
919
2.09M
                        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.09M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.09M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.09M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.09M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.09M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.09M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.09M
                    }
930
1.67M
                    t->bx -= x << ss_hor;
931
1.67M
                }
932
1.56M
                t->by -= y << ss_ver;
933
1.56M
            }
934
783k
        }
935
1.12M
    }
936
1.09M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.23M
{
827
1.23M
    const Dav1dFrameContext *const f = t->f;
828
1.23M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.23M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.23M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.23M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.23M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.23M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.23M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.23M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
968k
                           (bw4 > ss_hor || t->bx & 1) &&
837
828k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.23M
    if (b->skip) {
840
731k
        BlockContext *const a = t->a;
841
731k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
731k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
731k
        if (has_chroma) {
844
400k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
400k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
400k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
400k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
400k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
400k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
400k
        }
851
731k
        return;
852
731k
    }
853
854
507k
    Dav1dTileState *const ts = t->ts;
855
507k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
507k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
507k
    assert(t->frame_thread.pass == 1);
858
507k
    assert(!b->skip);
859
507k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
507k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
507k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.03M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
524k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.07M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
553k
            const int sub_w4 = imin(w4, init_x + 16);
867
553k
            int y_off = !!init_y, y, x;
868
1.17M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
626k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
626k
            {
871
626k
                int x_off = !!init_x;
872
1.60M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
980k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
980k
                {
875
980k
                    if (!b->intra) {
876
169k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
169k
                                       x_off, y_off, NULL);
878
811k
                    } else {
879
811k
                        uint8_t cf_ctx = 0x40;
880
811k
                        enum TxfmType txtp;
881
811k
                        const int eob =
882
811k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
811k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
811k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
811k
                        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
811k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
811k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
811k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
811k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
811k
                    }
893
980k
                }
894
626k
                t->bx -= x;
895
626k
            }
896
553k
            t->by -= y;
897
898
553k
            if (!has_chroma) continue;
899
900
372k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
372k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.11M
            for (int pl = 0; pl < 2; pl++) {
903
1.53M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
793k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
793k
                {
906
1.76M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
973k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
973k
                    {
909
973k
                        uint8_t cf_ctx = 0x40;
910
973k
                        enum TxfmType txtp;
911
973k
                        if (!b->intra)
912
263k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
263k
                                                        bx4 + (x << ss_hor)];
914
973k
                        const int eob =
915
973k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
973k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
973k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
973k
                                         &txtp, &cf_ctx);
919
973k
                        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
973k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
973k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
973k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
973k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
973k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
973k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
973k
                    }
930
793k
                    t->bx -= x << ss_hor;
931
793k
                }
932
745k
                t->by -= y << ss_ver;
933
745k
            }
934
372k
        }
935
524k
    }
936
507k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.29M
{
827
1.29M
    const Dav1dFrameContext *const f = t->f;
828
1.29M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.29M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.29M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.29M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.29M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.29M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.29M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.29M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.02M
                           (bw4 > ss_hor || t->bx & 1) &&
837
939k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.29M
    if (b->skip) {
840
714k
        BlockContext *const a = t->a;
841
714k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
714k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
714k
        if (has_chroma) {
844
493k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
493k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
493k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
493k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
493k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
493k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
493k
        }
851
714k
        return;
852
714k
    }
853
854
583k
    Dav1dTileState *const ts = t->ts;
855
583k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
583k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
583k
    assert(t->frame_thread.pass == 1);
858
583k
    assert(!b->skip);
859
583k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
583k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
583k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.17M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
595k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.20M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
614k
            const int sub_w4 = imin(w4, init_x + 16);
867
614k
            int y_off = !!init_y, y, x;
868
1.33M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
716k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
716k
            {
871
716k
                int x_off = !!init_x;
872
1.88M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.16M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.16M
                {
875
1.16M
                    if (!b->intra) {
876
259k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
259k
                                       x_off, y_off, NULL);
878
908k
                    } else {
879
908k
                        uint8_t cf_ctx = 0x40;
880
908k
                        enum TxfmType txtp;
881
908k
                        const int eob =
882
908k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
908k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
908k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
908k
                        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
908k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
908k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
908k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
908k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
908k
                    }
893
1.16M
                }
894
716k
                t->bx -= x;
895
716k
            }
896
614k
            t->by -= y;
897
898
614k
            if (!has_chroma) continue;
899
900
410k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
410k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.23M
            for (int pl = 0; pl < 2; pl++) {
903
1.70M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
884k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
884k
                {
906
2.00M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.12M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.12M
                    {
909
1.12M
                        uint8_t cf_ctx = 0x40;
910
1.12M
                        enum TxfmType txtp;
911
1.12M
                        if (!b->intra)
912
258k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
258k
                                                        bx4 + (x << ss_hor)];
914
1.12M
                        const int eob =
915
1.12M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.12M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.12M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.12M
                                         &txtp, &cf_ctx);
919
1.12M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.12M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.12M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.12M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.12M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.12M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.12M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.12M
                    }
930
884k
                    t->bx -= x << ss_hor;
931
884k
                }
932
821k
                t->by -= y << ss_ver;
933
821k
            }
934
410k
        }
935
595k
    }
936
583k
}
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.06M
{
945
1.06M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.06M
    const Dav1dFrameContext *const f = t->f;
947
1.06M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.06M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.06M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.06M
    const int mvx = mv.x, mvy = mv.y;
951
1.06M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.06M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.06M
    const pixel *ref;
954
955
1.06M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
186k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
186k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
186k
        int w, h;
959
960
186k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
102k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
102k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
102k
        } else {
964
84.3k
            w = f->bw * 4 >> ss_hor;
965
84.3k
            h = f->bh * 4 >> ss_ver;
966
84.3k
        }
967
186k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
143k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
108k
            dy + bh4 * v_mul + !!my * 4 > h)
970
103k
        {
971
103k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
103k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
103k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
103k
                                emu_edge_buf, 192 * sizeof(pixel),
975
103k
                                refp->p.data[pl], ref_stride);
976
103k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
103k
            ref_stride = 192 * sizeof(pixel);
978
103k
        } else {
979
83.5k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
83.5k
        }
981
982
186k
        if (dst8 != NULL) {
983
156k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
156k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
156k
                                     HIGHBD_CALL_SUFFIX);
986
156k
        } else {
987
30.5k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
30.5k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
30.5k
                                      HIGHBD_CALL_SUFFIX);
990
30.5k
        }
991
880k
    } else {
992
880k
        assert(refp != &f->sr_cur);
993
994
880k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
880k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
1.76M
#define scale_mv(res, val, scale) do { \
997
1.76M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
1.76M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
1.76M
        } while (0)
1000
880k
        int pos_y, pos_x;
1001
880k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
880k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
880k
#undef scale_mv
1004
880k
        const int left = pos_x >> 10;
1005
880k
        const int top = pos_y >> 10;
1006
880k
        const int right =
1007
880k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
880k
        const int bottom =
1009
880k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
880k
        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
880k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
880k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
880k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
415k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
415k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
415k
                                w, h, left - 3, top - 3,
1023
415k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
415k
                                refp->p.data[pl], ref_stride);
1025
415k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
415k
            ref_stride = 320 * sizeof(pixel);
1027
415k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
465k
        } else {
1029
465k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
465k
        }
1031
1032
880k
        if (dst8 != NULL) {
1033
652k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
652k
                                            bw4 * h_mul, bh4 * v_mul,
1035
652k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
652k
                                            f->svc[refidx][0].step,
1037
652k
                                            f->svc[refidx][1].step
1038
652k
                                            HIGHBD_CALL_SUFFIX);
1039
652k
        } else {
1040
228k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
228k
                                             bw4 * h_mul, bh4 * v_mul,
1042
228k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
228k
                                             f->svc[refidx][0].step,
1044
228k
                                             f->svc[refidx][1].step
1045
228k
                                             HIGHBD_CALL_SUFFIX);
1046
228k
        }
1047
880k
    }
1048
1049
1.06M
    return 0;
1050
1.06M
}
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
116k
{
1057
116k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
116k
    const Dav1dFrameContext *const f = t->f;
1059
116k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
116k
    pixel *const lap = bitfn(t->scratch.lap);
1061
116k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
116k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
116k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
116k
    int res;
1065
1066
116k
    if (t->by > t->ts->tiling.row_start &&
1067
101k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
56.7k
    {
1069
121k
        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
64.6k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
64.6k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
64.6k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
64.6k
            if (a_r->ref.ref[0] > 0) {
1076
61.8k
                const int ow4 = imin(step4, b_dim[0]);
1077
61.8k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
61.8k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
61.8k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
61.8k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
61.8k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
61.8k
                if (res) return res;
1083
61.8k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
61.8k
                                   h_mul * ow4, v_mul * oh4);
1085
61.8k
                i++;
1086
61.8k
            }
1087
64.6k
            x += step4;
1088
64.6k
        }
1089
56.7k
    }
1090
1091
116k
    if (t->bx > t->ts->tiling.col_start)
1092
235k
        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
123k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
123k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
123k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
123k
            if (l_r->ref.ref[0] > 0) {
1099
119k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
119k
                const int oh4 = imin(step4, b_dim[1]);
1101
119k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
119k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
119k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
119k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
119k
                if (res) return res;
1106
119k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
119k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
119k
                i++;
1109
119k
            }
1110
123k
            y += step4;
1111
123k
        }
1112
116k
    return 0;
1113
116k
}
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
6.95k
{
1121
6.95k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
6.95k
    const Dav1dFrameContext *const f = t->f;
1123
6.95k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
6.95k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
6.95k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
6.95k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
6.95k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
6.95k
    const int32_t *const mat = wmp->matrix;
1129
6.95k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
6.95k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
22.7k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
15.8k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
15.8k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
15.8k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
57.8k
        for (int x = 0; x < b_dim[0] * h_mul; x += 8) {
1137
            // calculate transformation relative to center of 8x8 block in
1138
            // luma pixel units
1139
42.0k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
42.0k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
42.0k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
42.0k
            const int dx = (int) (mvx >> 16) - 4;
1144
42.0k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
42.0k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
42.0k
            const int dy = (int) (mvy >> 16) - 4;
1147
42.0k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
42.0k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
42.0k
            const pixel *ref_ptr;
1151
42.0k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
42.0k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
25.4k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
25.4k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
25.4k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
25.4k
                                    refp->p.data[pl], ref_stride);
1158
25.4k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
25.4k
                ref_stride = 32 * sizeof(pixel);
1160
25.4k
            } else {
1161
16.5k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
16.5k
            }
1163
42.0k
            if (dst16 != NULL)
1164
6.84k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
6.84k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
35.1k
            else
1167
35.1k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
35.1k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
42.0k
        }
1170
15.8k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
2.30k
        else      dst16 += 8 * dstride;
1172
15.8k
    }
1173
6.95k
    return 0;
1174
6.95k
}
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
635k
{
1180
635k
    Dav1dTileState *const ts = t->ts;
1181
635k
    const Dav1dFrameContext *const f = t->f;
1182
635k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
635k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
635k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
635k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
635k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
635k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
635k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
635k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
635k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
635k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
537k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
494k
                           (bh4 > ss_ver || t->by & 1);
1194
635k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
635k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
635k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
635k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
635k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.29M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
659k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
659k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.35M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
693k
            if (b->pal_sz[0]) {
1208
2.27k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
2.27k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
2.27k
                const uint8_t *pal_idx;
1211
2.27k
                if (t->frame_thread.pass) {
1212
2.27k
                    const int p = t->frame_thread.pass & 1;
1213
2.27k
                    assert(ts->frame_thread[p].pal_idx);
1214
2.27k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
2.27k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
2.27k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
2.27k
                const pixel *const pal = t->frame_thread.pass ?
1220
2.27k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
2.27k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
2.27k
                    bytefn(t->scratch.pal)[0];
1223
2.27k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
2.27k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
2.27k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
2.27k
            }
1229
1230
693k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
693k
                                     sm_flag(&t->l, by4) |
1232
693k
                                     intra_edge_filter_flag);
1233
693k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
659k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
693k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
659k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
693k
            int y, x;
1238
693k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.58M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
891k
                 y += t_dim->h, t->by += t_dim->h)
1241
891k
            {
1242
891k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
891k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
891k
                                    t->bx + init_x);
1245
2.28M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.39M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.39M
                {
1248
1.39M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.39M
                    int angle = b->y_angle;
1251
1.39M
                    const enum EdgeFlags edge_flags =
1252
1.39M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.05M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.39M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
844k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.39M
                    const pixel *top_sb_edge = NULL;
1257
1.39M
                    if (!(t->by & (f->sb_step - 1))) {
1258
474k
                        top_sb_edge = f->ipred_edge[0];
1259
474k
                        const int sby = t->by >> f->sb_shift;
1260
474k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
474k
                    }
1262
1.39M
                    const enum IntraPredMode m =
1263
1.39M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.39M
                                                          t->bx > ts->tiling.col_start,
1265
1.39M
                                                          t->by,
1266
1.39M
                                                          t->by > ts->tiling.row_start,
1267
1.39M
                                                          ts->tiling.col_end,
1268
1.39M
                                                          ts->tiling.row_end,
1269
1.39M
                                                          edge_flags, dst,
1270
1.39M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.39M
                                                          b->y_mode, &angle,
1272
1.39M
                                                          t_dim->w, t_dim->h,
1273
1.39M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.39M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.39M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.39M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.39M
                                             angle | intra_flags,
1278
1.39M
                                             4 * f->bw - 4 * t->bx,
1279
1.39M
                                             4 * f->bh - 4 * t->by
1280
1.39M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.39M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.39M
                skip_y_pred: {}
1293
1.39M
                    if (!b->skip) {
1294
470k
                        coef *cf;
1295
470k
                        int eob;
1296
470k
                        enum TxfmType txtp;
1297
470k
                        if (t->frame_thread.pass) {
1298
470k
                            const int p = t->frame_thread.pass & 1;
1299
470k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
470k
                            cf = ts->frame_thread[p].cf;
1301
470k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
470k
                            eob  = cbi >> 5;
1303
470k
                            txtp = cbi & 0x1f;
1304
470k
                        } 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
470k
                        if (eob >= 0) {
1317
309k
                            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
309k
                            dsp->itx.itxfm_add[b->tx]
1321
309k
                                              [txtp](dst,
1322
309k
                                                     f->cur.stride[0],
1323
309k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
309k
                            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
309k
                        }
1328
923k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.39M
                    dst += 4 * t_dim->w;
1333
1.39M
                }
1334
891k
                t->bx -= x;
1335
891k
            }
1336
693k
            t->by -= y;
1337
1338
693k
            if (!has_chroma) continue;
1339
1340
514k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
514k
            if (b->uv_mode == CFL_PRED) {
1343
90.5k
                assert(!init_x && !init_y);
1344
1345
90.5k
                int16_t *const ac = t->scratch.ac;
1346
90.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
90.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
90.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
90.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
90.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
90.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
90.5k
                const int furthest_r =
1354
90.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
90.5k
                const int furthest_b =
1356
90.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
90.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
90.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
90.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
90.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
271k
                for (int pl = 0; pl < 2; pl++) {
1362
181k
                    if (!b->cfl_alpha[pl]) continue;
1363
150k
                    int angle = 0;
1364
150k
                    const pixel *top_sb_edge = NULL;
1365
150k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
62.1k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
62.1k
                        const int sby = t->by >> f->sb_shift;
1368
62.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
62.1k
                    }
1370
150k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
150k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
150k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
150k
                    const enum IntraPredMode m =
1374
150k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
150k
                                                          ypos, ypos > ystart,
1376
150k
                                                          ts->tiling.col_end >> ss_hor,
1377
150k
                                                          ts->tiling.row_end >> ss_ver,
1378
150k
                                                          0, uv_dst[pl], stride,
1379
150k
                                                          top_sb_edge, DC_PRED, &angle,
1380
150k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
150k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
150k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
150k
                                           uv_t_dim->w * 4,
1384
150k
                                           uv_t_dim->h * 4,
1385
150k
                                           ac, b->cfl_alpha[pl]
1386
150k
                                           HIGHBD_CALL_SUFFIX);
1387
150k
                }
1388
90.5k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
423k
            } else if (b->pal_sz[1]) {
1394
1.37k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.37k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.37k
                const pixel (*pal)[8];
1397
1.37k
                const uint8_t *pal_idx;
1398
1.37k
                if (t->frame_thread.pass) {
1399
1.37k
                    const int p = t->frame_thread.pass & 1;
1400
1.37k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.37k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.37k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.37k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.37k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.37k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.37k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.37k
                                       f->cur.stride[1], pal[1],
1412
1.37k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.37k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.37k
                                       f->cur.stride[1], pal[2],
1415
1.37k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.37k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.37k
            }
1425
1426
514k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
514k
                                 sm_uv_flag(&t->l, cby4);
1428
514k
            const int uv_sb_has_tr =
1429
514k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
484k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
514k
            const int uv_sb_has_bl =
1432
514k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
484k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
514k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.54M
            for (int pl = 0; pl < 2; pl++) {
1436
2.17M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.14M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.14M
                {
1439
1.14M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.14M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.14M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.63M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.49M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.49M
                    {
1445
1.49M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.34M
                            b->pal_sz[1])
1447
154k
                        {
1448
154k
                            goto skip_uv_pred;
1449
154k
                        }
1450
1451
1.34M
                        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.34M
                        const enum EdgeFlags edge_flags =
1456
1.34M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
535k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.07M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.34M
                            ((x > (init_x >> ss_hor) ||
1460
988k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
791k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.34M
                        const pixel *top_sb_edge = NULL;
1463
1.34M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
581k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
581k
                            const int sby = t->by >> f->sb_shift;
1466
581k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
581k
                        }
1468
1.34M
                        const enum IntraPredMode uv_mode =
1469
1.34M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.34M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.34M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.34M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.34M
                        const enum IntraPredMode m =
1474
1.34M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.34M
                                                              ypos, ypos > ystart,
1476
1.34M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.34M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.34M
                                                              edge_flags, dst, stride,
1479
1.34M
                                                              top_sb_edge, uv_mode,
1480
1.34M
                                                              &angle, uv_t_dim->w,
1481
1.34M
                                                              uv_t_dim->h,
1482
1.34M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.34M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.34M
                        angle |= intra_edge_filter_flag;
1485
1.34M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.34M
                                                 uv_t_dim->w * 4,
1487
1.34M
                                                 uv_t_dim->h * 4,
1488
1.34M
                                                 angle | sm_uv_fl,
1489
1.34M
                                                 (4 * f->bw + ss_hor -
1490
1.34M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.34M
                                                 (4 * f->bh + ss_ver -
1492
1.34M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.34M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.34M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.49M
                    skip_uv_pred: {}
1505
1.49M
                        if (!b->skip) {
1506
512k
                            enum TxfmType txtp;
1507
512k
                            int eob;
1508
512k
                            coef *cf;
1509
512k
                            if (t->frame_thread.pass) {
1510
512k
                                const int p = t->frame_thread.pass & 1;
1511
512k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
512k
                                cf = ts->frame_thread[p].cf;
1513
512k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
512k
                                eob  = cbi >> 5;
1515
512k
                                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
512k
                            if (eob >= 0) {
1533
142k
                                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
142k
                                dsp->itx.itxfm_add[b->uvtx]
1537
142k
                                                  [txtp](dst, stride,
1538
142k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
142k
                                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
142k
                            }
1543
982k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.49M
                        dst += uv_t_dim->w * 4;
1548
1.49M
                    }
1549
1.14M
                    t->bx -= x << ss_hor;
1550
1.14M
                }
1551
1.02M
                t->by -= y << ss_ver;
1552
1.02M
            }
1553
514k
        }
1554
659k
    }
1555
635k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
320k
{
1180
320k
    Dav1dTileState *const ts = t->ts;
1181
320k
    const Dav1dFrameContext *const f = t->f;
1182
320k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
320k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
320k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
320k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
320k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
320k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
320k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
320k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
320k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
320k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
273k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
246k
                           (bh4 > ss_ver || t->by & 1);
1194
320k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
320k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
320k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
320k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
320k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
653k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
333k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
333k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
688k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
355k
            if (b->pal_sz[0]) {
1208
1.08k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.08k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.08k
                const uint8_t *pal_idx;
1211
1.08k
                if (t->frame_thread.pass) {
1212
1.08k
                    const int p = t->frame_thread.pass & 1;
1213
1.08k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.08k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.08k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.08k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.08k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.08k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.08k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.08k
                    bytefn(t->scratch.pal)[0];
1223
1.08k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.08k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.08k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
1.08k
            }
1229
1230
355k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
355k
                                     sm_flag(&t->l, by4) |
1232
355k
                                     intra_edge_filter_flag);
1233
355k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
333k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
355k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
333k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
355k
            int y, x;
1238
355k
            const int sub_w4 = imin(w4, init_x + 16);
1239
814k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
459k
                 y += t_dim->h, t->by += t_dim->h)
1241
459k
            {
1242
459k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
459k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
459k
                                    t->bx + init_x);
1245
1.19M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
733k
                     x += t_dim->w, t->bx += t_dim->w)
1247
733k
                {
1248
733k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
731k
                    int angle = b->y_angle;
1251
731k
                    const enum EdgeFlags edge_flags =
1252
731k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
558k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
731k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
447k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
731k
                    const pixel *top_sb_edge = NULL;
1257
731k
                    if (!(t->by & (f->sb_step - 1))) {
1258
233k
                        top_sb_edge = f->ipred_edge[0];
1259
233k
                        const int sby = t->by >> f->sb_shift;
1260
233k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
233k
                    }
1262
731k
                    const enum IntraPredMode m =
1263
731k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
731k
                                                          t->bx > ts->tiling.col_start,
1265
731k
                                                          t->by,
1266
731k
                                                          t->by > ts->tiling.row_start,
1267
731k
                                                          ts->tiling.col_end,
1268
731k
                                                          ts->tiling.row_end,
1269
731k
                                                          edge_flags, dst,
1270
731k
                                                          f->cur.stride[0], top_sb_edge,
1271
731k
                                                          b->y_mode, &angle,
1272
731k
                                                          t_dim->w, t_dim->h,
1273
731k
                                                          f->seq_hdr->intra_edge_filter,
1274
731k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
731k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
731k
                                             t_dim->w * 4, t_dim->h * 4,
1277
731k
                                             angle | intra_flags,
1278
731k
                                             4 * f->bw - 4 * t->bx,
1279
731k
                                             4 * f->bh - 4 * t->by
1280
731k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
731k
                    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
733k
                skip_y_pred: {}
1293
733k
                    if (!b->skip) {
1294
209k
                        coef *cf;
1295
209k
                        int eob;
1296
209k
                        enum TxfmType txtp;
1297
209k
                        if (t->frame_thread.pass) {
1298
209k
                            const int p = t->frame_thread.pass & 1;
1299
209k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
209k
                            cf = ts->frame_thread[p].cf;
1301
209k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
209k
                            eob  = cbi >> 5;
1303
209k
                            txtp = cbi & 0x1f;
1304
209k
                        } 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
209k
                        if (eob >= 0) {
1317
133k
                            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
133k
                            dsp->itx.itxfm_add[b->tx]
1321
133k
                                              [txtp](dst,
1322
133k
                                                     f->cur.stride[0],
1323
133k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
133k
                            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
133k
                        }
1328
524k
                    } 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
733k
                    dst += 4 * t_dim->w;
1333
733k
                }
1334
459k
                t->bx -= x;
1335
459k
            }
1336
354k
            t->by -= y;
1337
1338
354k
            if (!has_chroma) continue;
1339
1340
257k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
257k
            if (b->uv_mode == CFL_PRED) {
1343
50.0k
                assert(!init_x && !init_y);
1344
1345
50.0k
                int16_t *const ac = t->scratch.ac;
1346
50.0k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
50.0k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
50.0k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
50.0k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
50.0k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
50.0k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
50.0k
                const int furthest_r =
1354
50.0k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
50.0k
                const int furthest_b =
1356
50.0k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
50.0k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
50.0k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
50.0k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
50.0k
                                                         cbw4 * 4, cbh4 * 4);
1361
150k
                for (int pl = 0; pl < 2; pl++) {
1362
100k
                    if (!b->cfl_alpha[pl]) continue;
1363
85.0k
                    int angle = 0;
1364
85.0k
                    const pixel *top_sb_edge = NULL;
1365
85.0k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
31.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
31.5k
                        const int sby = t->by >> f->sb_shift;
1368
31.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
31.5k
                    }
1370
85.0k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
85.0k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
85.0k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
85.0k
                    const enum IntraPredMode m =
1374
85.0k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
85.0k
                                                          ypos, ypos > ystart,
1376
85.0k
                                                          ts->tiling.col_end >> ss_hor,
1377
85.0k
                                                          ts->tiling.row_end >> ss_ver,
1378
85.0k
                                                          0, uv_dst[pl], stride,
1379
85.0k
                                                          top_sb_edge, DC_PRED, &angle,
1380
85.0k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
85.0k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
85.0k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
85.0k
                                           uv_t_dim->w * 4,
1384
85.0k
                                           uv_t_dim->h * 4,
1385
85.0k
                                           ac, b->cfl_alpha[pl]
1386
85.0k
                                           HIGHBD_CALL_SUFFIX);
1387
85.0k
                }
1388
50.0k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
207k
            } else if (b->pal_sz[1]) {
1394
768
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
768
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
768
                const pixel (*pal)[8];
1397
768
                const uint8_t *pal_idx;
1398
768
                if (t->frame_thread.pass) {
1399
768
                    const int p = t->frame_thread.pass & 1;
1400
768
                    assert(ts->frame_thread[p].pal_idx);
1401
768
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
768
                                              ((t->bx >> 1) + (t->by & 1))];
1403
768
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
768
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
768
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
768
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
768
                                       f->cur.stride[1], pal[1],
1412
768
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
768
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
768
                                       f->cur.stride[1], pal[2],
1415
768
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
768
                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
768
            }
1425
1426
257k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
257k
                                 sm_uv_flag(&t->l, cby4);
1428
257k
            const int uv_sb_has_tr =
1429
257k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
240k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
257k
            const int uv_sb_has_bl =
1432
257k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
240k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
257k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
773k
            for (int pl = 0; pl < 2; pl++) {
1436
1.09M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
583k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
583k
                {
1439
583k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
583k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
583k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.36M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
785k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
785k
                    {
1445
785k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
700k
                            b->pal_sz[1])
1447
86.9k
                        {
1448
86.9k
                            goto skip_uv_pred;
1449
86.9k
                        }
1450
1451
698k
                        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
698k
                        const enum EdgeFlags edge_flags =
1456
698k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
301k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
557k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
698k
                            ((x > (init_x >> ss_hor) ||
1460
496k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
412k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
698k
                        const pixel *top_sb_edge = NULL;
1463
698k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
284k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
284k
                            const int sby = t->by >> f->sb_shift;
1466
284k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
284k
                        }
1468
698k
                        const enum IntraPredMode uv_mode =
1469
698k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
698k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
698k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
698k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
698k
                        const enum IntraPredMode m =
1474
698k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
698k
                                                              ypos, ypos > ystart,
1476
698k
                                                              ts->tiling.col_end >> ss_hor,
1477
698k
                                                              ts->tiling.row_end >> ss_ver,
1478
698k
                                                              edge_flags, dst, stride,
1479
698k
                                                              top_sb_edge, uv_mode,
1480
698k
                                                              &angle, uv_t_dim->w,
1481
698k
                                                              uv_t_dim->h,
1482
698k
                                                              f->seq_hdr->intra_edge_filter,
1483
698k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
698k
                        angle |= intra_edge_filter_flag;
1485
698k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
698k
                                                 uv_t_dim->w * 4,
1487
698k
                                                 uv_t_dim->h * 4,
1488
698k
                                                 angle | sm_uv_fl,
1489
698k
                                                 (4 * f->bw + ss_hor -
1490
698k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
698k
                                                 (4 * f->bh + ss_ver -
1492
698k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
698k
                                                 HIGHBD_CALL_SUFFIX);
1494
698k
                        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
785k
                    skip_uv_pred: {}
1505
785k
                        if (!b->skip) {
1506
239k
                            enum TxfmType txtp;
1507
239k
                            int eob;
1508
239k
                            coef *cf;
1509
239k
                            if (t->frame_thread.pass) {
1510
239k
                                const int p = t->frame_thread.pass & 1;
1511
239k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
239k
                                cf = ts->frame_thread[p].cf;
1513
239k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
239k
                                eob  = cbi >> 5;
1515
239k
                                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
239k
                            if (eob >= 0) {
1533
64.0k
                                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
64.0k
                                dsp->itx.itxfm_add[b->uvtx]
1537
64.0k
                                                  [txtp](dst, stride,
1538
64.0k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
64.0k
                                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
64.0k
                            }
1543
546k
                        } 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
785k
                        dst += uv_t_dim->w * 4;
1548
785k
                    }
1549
583k
                    t->bx -= x << ss_hor;
1550
583k
                }
1551
515k
                t->by -= y << ss_ver;
1552
515k
            }
1553
257k
        }
1554
333k
    }
1555
320k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
315k
{
1180
315k
    Dav1dTileState *const ts = t->ts;
1181
315k
    const Dav1dFrameContext *const f = t->f;
1182
315k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
315k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
315k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
315k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
315k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
315k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
315k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
315k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
315k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
315k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
264k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
248k
                           (bh4 > ss_ver || t->by & 1);
1194
315k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
315k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
315k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
315k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
315k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
640k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
325k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
325k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
663k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
338k
            if (b->pal_sz[0]) {
1208
1.19k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.19k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.19k
                const uint8_t *pal_idx;
1211
1.19k
                if (t->frame_thread.pass) {
1212
1.19k
                    const int p = t->frame_thread.pass & 1;
1213
1.19k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.19k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.19k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.19k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.19k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.19k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.19k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.19k
                    bytefn(t->scratch.pal)[0];
1223
1.19k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.19k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.19k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
1.19k
            }
1229
1230
338k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
338k
                                     sm_flag(&t->l, by4) |
1232
338k
                                     intra_edge_filter_flag);
1233
338k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
325k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
338k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
325k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
338k
            int y, x;
1238
338k
            const int sub_w4 = imin(w4, init_x + 16);
1239
769k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
431k
                 y += t_dim->h, t->by += t_dim->h)
1241
431k
            {
1242
431k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
431k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
431k
                                    t->bx + init_x);
1245
1.09M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
660k
                     x += t_dim->w, t->bx += t_dim->w)
1247
660k
                {
1248
660k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
658k
                    int angle = b->y_angle;
1251
658k
                    const enum EdgeFlags edge_flags =
1252
658k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
499k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
658k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
396k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
658k
                    const pixel *top_sb_edge = NULL;
1257
658k
                    if (!(t->by & (f->sb_step - 1))) {
1258
240k
                        top_sb_edge = f->ipred_edge[0];
1259
240k
                        const int sby = t->by >> f->sb_shift;
1260
240k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
240k
                    }
1262
658k
                    const enum IntraPredMode m =
1263
658k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
658k
                                                          t->bx > ts->tiling.col_start,
1265
658k
                                                          t->by,
1266
658k
                                                          t->by > ts->tiling.row_start,
1267
658k
                                                          ts->tiling.col_end,
1268
658k
                                                          ts->tiling.row_end,
1269
658k
                                                          edge_flags, dst,
1270
658k
                                                          f->cur.stride[0], top_sb_edge,
1271
658k
                                                          b->y_mode, &angle,
1272
658k
                                                          t_dim->w, t_dim->h,
1273
658k
                                                          f->seq_hdr->intra_edge_filter,
1274
658k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
658k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
658k
                                             t_dim->w * 4, t_dim->h * 4,
1277
658k
                                             angle | intra_flags,
1278
658k
                                             4 * f->bw - 4 * t->bx,
1279
658k
                                             4 * f->bh - 4 * t->by
1280
658k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
658k
                    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
660k
                skip_y_pred: {}
1293
660k
                    if (!b->skip) {
1294
261k
                        coef *cf;
1295
261k
                        int eob;
1296
261k
                        enum TxfmType txtp;
1297
261k
                        if (t->frame_thread.pass) {
1298
261k
                            const int p = t->frame_thread.pass & 1;
1299
261k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
261k
                            cf = ts->frame_thread[p].cf;
1301
261k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
261k
                            eob  = cbi >> 5;
1303
261k
                            txtp = cbi & 0x1f;
1304
261k
                        } 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
261k
                        if (eob >= 0) {
1317
176k
                            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
176k
                            dsp->itx.itxfm_add[b->tx]
1321
176k
                                              [txtp](dst,
1322
176k
                                                     f->cur.stride[0],
1323
176k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
176k
                            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
176k
                        }
1328
399k
                    } 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
660k
                    dst += 4 * t_dim->w;
1333
660k
                }
1334
431k
                t->bx -= x;
1335
431k
            }
1336
338k
            t->by -= y;
1337
1338
338k
            if (!has_chroma) continue;
1339
1340
256k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
256k
            if (b->uv_mode == CFL_PRED) {
1343
40.5k
                assert(!init_x && !init_y);
1344
1345
40.5k
                int16_t *const ac = t->scratch.ac;
1346
40.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
40.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
40.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
40.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
40.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
40.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
40.5k
                const int furthest_r =
1354
40.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
40.5k
                const int furthest_b =
1356
40.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
40.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
40.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
40.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
40.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
121k
                for (int pl = 0; pl < 2; pl++) {
1362
81.0k
                    if (!b->cfl_alpha[pl]) continue;
1363
65.7k
                    int angle = 0;
1364
65.7k
                    const pixel *top_sb_edge = NULL;
1365
65.7k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
30.6k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
30.6k
                        const int sby = t->by >> f->sb_shift;
1368
30.6k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
30.6k
                    }
1370
65.7k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
65.7k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
65.7k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
65.7k
                    const enum IntraPredMode m =
1374
65.7k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
65.7k
                                                          ypos, ypos > ystart,
1376
65.7k
                                                          ts->tiling.col_end >> ss_hor,
1377
65.7k
                                                          ts->tiling.row_end >> ss_ver,
1378
65.7k
                                                          0, uv_dst[pl], stride,
1379
65.7k
                                                          top_sb_edge, DC_PRED, &angle,
1380
65.7k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
65.7k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
65.7k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
65.7k
                                           uv_t_dim->w * 4,
1384
65.7k
                                           uv_t_dim->h * 4,
1385
65.7k
                                           ac, b->cfl_alpha[pl]
1386
65.7k
                                           HIGHBD_CALL_SUFFIX);
1387
65.7k
                }
1388
40.5k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
215k
            } else if (b->pal_sz[1]) {
1394
610
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
610
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
610
                const pixel (*pal)[8];
1397
610
                const uint8_t *pal_idx;
1398
610
                if (t->frame_thread.pass) {
1399
610
                    const int p = t->frame_thread.pass & 1;
1400
610
                    assert(ts->frame_thread[p].pal_idx);
1401
610
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
610
                                              ((t->bx >> 1) + (t->by & 1))];
1403
610
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
610
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
610
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
610
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
610
                                       f->cur.stride[1], pal[1],
1412
610
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
610
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
610
                                       f->cur.stride[1], pal[2],
1415
610
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
610
                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
610
            }
1425
1426
256k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
256k
                                 sm_uv_flag(&t->l, cby4);
1428
256k
            const int uv_sb_has_tr =
1429
256k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
244k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
256k
            const int uv_sb_has_bl =
1432
256k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
244k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
256k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
768k
            for (int pl = 0; pl < 2; pl++) {
1436
1.07M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
558k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
558k
                {
1439
558k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
558k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
558k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.26M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
708k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
709k
                    {
1445
709k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
643k
                            b->pal_sz[1])
1447
67.1k
                        {
1448
67.1k
                            goto skip_uv_pred;
1449
67.1k
                        }
1450
1451
641k
                        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
641k
                        const enum EdgeFlags edge_flags =
1456
641k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
234k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
519k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
641k
                            ((x > (init_x >> ss_hor) ||
1460
491k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
378k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
641k
                        const pixel *top_sb_edge = NULL;
1463
641k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
297k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
297k
                            const int sby = t->by >> f->sb_shift;
1466
297k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
297k
                        }
1468
641k
                        const enum IntraPredMode uv_mode =
1469
641k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
641k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
641k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
641k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
641k
                        const enum IntraPredMode m =
1474
641k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
641k
                                                              ypos, ypos > ystart,
1476
641k
                                                              ts->tiling.col_end >> ss_hor,
1477
641k
                                                              ts->tiling.row_end >> ss_ver,
1478
641k
                                                              edge_flags, dst, stride,
1479
641k
                                                              top_sb_edge, uv_mode,
1480
641k
                                                              &angle, uv_t_dim->w,
1481
641k
                                                              uv_t_dim->h,
1482
641k
                                                              f->seq_hdr->intra_edge_filter,
1483
641k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
641k
                        angle |= intra_edge_filter_flag;
1485
641k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
641k
                                                 uv_t_dim->w * 4,
1487
641k
                                                 uv_t_dim->h * 4,
1488
641k
                                                 angle | sm_uv_fl,
1489
641k
                                                 (4 * f->bw + ss_hor -
1490
641k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
641k
                                                 (4 * f->bh + ss_ver -
1492
641k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
641k
                                                 HIGHBD_CALL_SUFFIX);
1494
641k
                        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
708k
                    skip_uv_pred: {}
1505
708k
                        if (!b->skip) {
1506
273k
                            enum TxfmType txtp;
1507
273k
                            int eob;
1508
273k
                            coef *cf;
1509
273k
                            if (t->frame_thread.pass) {
1510
273k
                                const int p = t->frame_thread.pass & 1;
1511
273k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
273k
                                cf = ts->frame_thread[p].cf;
1513
273k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
273k
                                eob  = cbi >> 5;
1515
273k
                                txtp = cbi & 0x1f;
1516
273k
                            } 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
273k
                            if (eob >= 0) {
1533
78.9k
                                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
78.9k
                                dsp->itx.itxfm_add[b->uvtx]
1537
78.9k
                                                  [txtp](dst, stride,
1538
78.9k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
78.9k
                                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
78.9k
                            }
1543
435k
                        } 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
708k
                        dst += uv_t_dim->w * 4;
1548
708k
                    }
1549
558k
                    t->bx -= x << ss_hor;
1550
558k
                }
1551
512k
                t->by -= y << ss_ver;
1552
512k
            }
1553
256k
        }
1554
325k
    }
1555
315k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
310k
{
1560
310k
    Dav1dTileState *const ts = t->ts;
1561
310k
    const Dav1dFrameContext *const f = t->f;
1562
310k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
310k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
310k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
310k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
310k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
310k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
310k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
310k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
310k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
230k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
212k
                           (bh4 > ss_ver || t->by & 1);
1573
310k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
310k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
310k
    int res;
1576
1577
    // prediction
1578
310k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
310k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
310k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
310k
    const ptrdiff_t uvdstoff =
1582
310k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
310k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
31.2k
        assert(!f->frame_hdr->super_res.enabled);
1586
31.2k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
31.2k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
31.2k
        if (res) return res;
1589
79.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
53.1k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
53.1k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
53.1k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
53.1k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
53.1k
            if (res) return res;
1595
53.1k
        }
1596
279k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
220k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
220k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
220k
        if (imin(bw4, bh4) > 1 &&
1601
131k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
129k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.62k
        {
1604
3.62k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.62k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.62k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.62k
            if (res) return res;
1608
216k
        } else {
1609
216k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
216k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
216k
            if (res) return res;
1612
216k
            if (b->motion_mode == MM_OBMC) {
1613
41.4k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
41.4k
                if (res) return res;
1615
41.4k
            }
1616
216k
        }
1617
220k
        if (b->interintra_type) {
1618
9.65k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
9.65k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
7.89k
                                   SMOOTH_PRED : b->interintra_mode;
1621
9.65k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
9.65k
            int angle = 0;
1623
9.65k
            const pixel *top_sb_edge = NULL;
1624
9.65k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.60k
                top_sb_edge = f->ipred_edge[0];
1626
1.60k
                const int sby = t->by >> f->sb_shift;
1627
1.60k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.60k
            }
1629
9.65k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
9.65k
                                                  t->by, t->by > ts->tiling.row_start,
1631
9.65k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
9.65k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
9.65k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
9.65k
                                                  HIGHBD_CALL_SUFFIX);
1635
9.65k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
9.65k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
9.65k
                                     HIGHBD_CALL_SUFFIX);
1638
9.65k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
9.65k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
9.65k
        }
1641
1642
220k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
130k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
130k
        refmvs_block *const *r;
1647
130k
        if (is_sub8x8) {
1648
27.3k
            assert(ss_hor == 1);
1649
27.3k
            r = &t->rt.r[(t->by & 31) + 5];
1650
27.3k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
27.3k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
27.3k
            if (bw4 == 1 && bh4 == ss_ver)
1653
3.59k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
27.3k
        }
1655
1656
        // chroma prediction
1657
130k
        if (is_sub8x8) {
1658
26.5k
            assert(ss_hor == 1);
1659
26.5k
            ptrdiff_t h_off = 0, v_off = 0;
1660
26.5k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
10.1k
                for (int pl = 0; pl < 2; pl++) {
1662
6.74k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
6.74k
                             NULL, f->cur.stride[1],
1664
6.74k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
6.74k
                             r[-1][t->bx - 1].mv.mv[0],
1666
6.74k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
6.74k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
6.74k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
6.74k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
6.74k
                    if (res) return res;
1671
6.74k
                }
1672
3.37k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
3.37k
                h_off = 2;
1674
3.37k
            }
1675
26.5k
            if (bw4 == 1) {
1676
12.9k
                const enum Filter2d left_filter_2d =
1677
12.9k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
38.8k
                for (int pl = 0; pl < 2; pl++) {
1679
25.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
25.9k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
25.9k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
25.9k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
25.9k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
25.9k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
25.9k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
25.9k
                    if (res) return res;
1687
25.9k
                }
1688
12.9k
                h_off = 2;
1689
12.9k
            }
1690
26.5k
            if (bh4 == ss_ver) {
1691
16.9k
                const enum Filter2d top_filter_2d =
1692
16.9k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
50.7k
                for (int pl = 0; pl < 2; pl++) {
1694
33.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
33.8k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
33.8k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
33.8k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
33.8k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
33.8k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
33.8k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
33.8k
                    if (res) return res;
1702
33.8k
                }
1703
16.9k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
16.9k
            }
1705
79.5k
            for (int pl = 0; pl < 2; pl++) {
1706
53.0k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
53.0k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
53.0k
                         refp, b->ref[0], filter_2d);
1709
53.0k
                if (res) return res;
1710
53.0k
            }
1711
104k
        } else {
1712
104k
            if (imin(cbw4, cbh4) > 1 &&
1713
42.3k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
41.2k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.21k
            {
1716
3.63k
                for (int pl = 0; pl < 2; pl++) {
1717
2.42k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.42k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.42k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.42k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.42k
                    if (res) return res;
1722
2.42k
                }
1723
103k
            } else {
1724
309k
                for (int pl = 0; pl < 2; pl++) {
1725
206k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
206k
                             NULL, f->cur.stride[1],
1727
206k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
206k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
206k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
206k
                    if (res) return res;
1731
206k
                    if (b->motion_mode == MM_OBMC) {
1732
75.4k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
75.4k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
75.4k
                        if (res) return res;
1735
75.4k
                    }
1736
206k
                }
1737
103k
            }
1738
104k
            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.70k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
20.1k
                for (int pl = 0; pl < 2; pl++) {
1745
13.4k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
13.4k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
13.4k
                    enum IntraPredMode m =
1748
13.4k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
10.9k
                        SMOOTH_PRED : b->interintra_mode;
1750
13.4k
                    int angle = 0;
1751
13.4k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
13.4k
                    const pixel *top_sb_edge = NULL;
1753
13.4k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.10k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.10k
                        const int sby = t->by >> f->sb_shift;
1756
2.10k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.10k
                    }
1758
13.4k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
13.4k
                                                          (t->bx >> ss_hor) >
1760
13.4k
                                                              (ts->tiling.col_start >> ss_hor),
1761
13.4k
                                                          t->by >> ss_ver,
1762
13.4k
                                                          (t->by >> ss_ver) >
1763
13.4k
                                                              (ts->tiling.row_start >> ss_ver),
1764
13.4k
                                                          ts->tiling.col_end >> ss_hor,
1765
13.4k
                                                          ts->tiling.row_end >> ss_ver,
1766
13.4k
                                                          0, uvdst, f->cur.stride[1],
1767
13.4k
                                                          top_sb_edge, m,
1768
13.4k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
13.4k
                                                          HIGHBD_CALL_SUFFIX);
1770
13.4k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
13.4k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
13.4k
                                             HIGHBD_CALL_SUFFIX);
1773
13.4k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
13.4k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
13.4k
                }
1776
6.70k
            }
1777
104k
        }
1778
1779
220k
    skip_inter_chroma_pred: {}
1780
220k
        t->tl_4x4_filter = filter_2d;
1781
220k
    } else {
1782
58.8k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
58.8k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
58.8k
        int jnt_weight;
1786
58.8k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
58.8k
        const uint8_t *mask;
1788
1789
176k
        for (int i = 0; i < 2; i++) {
1790
117k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
117k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
594
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
594
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
594
                if (res) return res;
1796
117k
            } else {
1797
117k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
117k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
117k
                if (res) return res;
1800
117k
            }
1801
117k
        }
1802
58.8k
        switch (b->comp_type) {
1803
50.1k
        case COMP_INTER_AVG:
1804
50.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
50.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
50.1k
            break;
1807
324
        case COMP_INTER_WEIGHTED_AVG:
1808
324
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
324
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
324
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
324
            break;
1812
5.31k
        case COMP_INTER_SEG:
1813
5.31k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
5.31k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
5.31k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
5.31k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
5.31k
            mask = seg_mask;
1818
5.31k
            break;
1819
3.05k
        case COMP_INTER_WEDGE:
1820
3.05k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.05k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.05k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.05k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.05k
            if (has_chroma)
1825
1.41k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.05k
            break;
1827
58.8k
        }
1828
1829
        // chroma
1830
106k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
212k
            for (int i = 0; i < 2; i++) {
1832
141k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
141k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
13.9k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
324
                {
1836
324
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
324
                                      b_dim, 1 + pl,
1838
324
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
324
                    if (res) return res;
1840
141k
                } else {
1841
141k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
141k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
141k
                    if (res) return res;
1844
141k
                }
1845
141k
            }
1846
70.9k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
70.9k
            switch (b->comp_type) {
1848
62.0k
            case COMP_INTER_AVG:
1849
62.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
62.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
62.0k
                            HIGHBD_CALL_SUFFIX);
1852
62.0k
                break;
1853
398
            case COMP_INTER_WEIGHTED_AVG:
1854
398
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
398
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
398
                              HIGHBD_CALL_SUFFIX);
1857
398
                break;
1858
2.82k
            case COMP_INTER_WEDGE:
1859
8.44k
            case COMP_INTER_SEG:
1860
8.44k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
8.44k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
8.44k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
8.44k
                             HIGHBD_CALL_SUFFIX);
1864
8.44k
                break;
1865
70.9k
            }
1866
70.9k
        }
1867
58.8k
    }
1868
1869
310k
    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
310k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
310k
    if (b->skip) {
1882
        // reset coef contexts
1883
132k
        BlockContext *const a = t->a;
1884
132k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
132k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
132k
        if (has_chroma) {
1887
87.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
87.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
87.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
87.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
87.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
87.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
87.3k
        }
1894
132k
        return 0;
1895
132k
    }
1896
1897
177k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
177k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
177k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
358k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
368k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
187k
            int y_off = !!init_y, y;
1905
187k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
376k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
188k
                 y += ytx->h, y_off++)
1908
188k
            {
1909
188k
                int x, x_off = !!init_x;
1910
382k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
193k
                     x += ytx->w, x_off++)
1912
193k
                {
1913
193k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
193k
                                   x_off, y_off, &dst[x * 4]);
1915
193k
                    t->bx += ytx->w;
1916
193k
                }
1917
188k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
188k
                t->bx -= x;
1919
188k
                t->by += ytx->h;
1920
188k
            }
1921
187k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
187k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
337k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
224k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
224k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
224k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
455k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
230k
                {
1931
230k
                    int x;
1932
230k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
473k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
242k
                    {
1935
242k
                        coef *cf;
1936
242k
                        int eob;
1937
242k
                        enum TxfmType txtp;
1938
242k
                        if (t->frame_thread.pass) {
1939
242k
                            const int p = t->frame_thread.pass & 1;
1940
242k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
242k
                            cf = ts->frame_thread[p].cf;
1942
242k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
242k
                            eob  = cbi >> 5;
1944
242k
                            txtp = cbi & 0x1f;
1945
242k
                        } 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
242k
                        if (eob >= 0) {
1964
54.6k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
54.6k
                            dsp->itx.itxfm_add[b->uvtx]
1967
54.6k
                                              [txtp](&uvdst[4 * x],
1968
54.6k
                                                     f->cur.stride[1],
1969
54.6k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
54.6k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
54.6k
                        }
1974
242k
                        t->bx += uvtx->w << ss_hor;
1975
242k
                    }
1976
230k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
230k
                    t->bx -= x << ss_hor;
1978
230k
                    t->by += uvtx->h << ss_ver;
1979
230k
                }
1980
224k
                t->by -= y << ss_ver;
1981
224k
            }
1982
187k
        }
1983
181k
    }
1984
177k
    return 0;
1985
310k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
133k
{
1560
133k
    Dav1dTileState *const ts = t->ts;
1561
133k
    const Dav1dFrameContext *const f = t->f;
1562
133k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
133k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
133k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
133k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
133k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
133k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
133k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
133k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
133k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
115k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
105k
                           (bh4 > ss_ver || t->by & 1);
1573
133k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
133k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
133k
    int res;
1576
1577
    // prediction
1578
133k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
133k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
133k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
133k
    const ptrdiff_t uvdstoff =
1582
133k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
133k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
17.5k
        assert(!f->frame_hdr->super_res.enabled);
1586
17.5k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
17.5k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
17.5k
        if (res) return res;
1589
46.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
31.1k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
31.1k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
31.1k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
31.1k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
31.1k
            if (res) return res;
1595
31.1k
        }
1596
115k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
94.9k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
94.9k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
94.9k
        if (imin(bw4, bh4) > 1 &&
1601
56.5k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
55.3k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.59k
        {
1604
1.59k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.59k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.59k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.59k
            if (res) return res;
1608
93.3k
        } else {
1609
93.3k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
93.3k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
93.3k
            if (res) return res;
1612
93.3k
            if (b->motion_mode == MM_OBMC) {
1613
16.5k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
16.5k
                if (res) return res;
1615
16.5k
            }
1616
93.3k
        }
1617
94.9k
        if (b->interintra_type) {
1618
5.77k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
5.77k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
4.82k
                                   SMOOTH_PRED : b->interintra_mode;
1621
5.77k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
5.77k
            int angle = 0;
1623
5.77k
            const pixel *top_sb_edge = NULL;
1624
5.77k
            if (!(t->by & (f->sb_step - 1))) {
1625
765
                top_sb_edge = f->ipred_edge[0];
1626
765
                const int sby = t->by >> f->sb_shift;
1627
765
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
765
            }
1629
5.77k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
5.77k
                                                  t->by, t->by > ts->tiling.row_start,
1631
5.77k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
5.77k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
5.77k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
5.77k
                                                  HIGHBD_CALL_SUFFIX);
1635
5.77k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
5.77k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
5.77k
                                     HIGHBD_CALL_SUFFIX);
1638
5.77k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
5.77k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
5.77k
        }
1641
1642
94.9k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
63.1k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
63.1k
        refmvs_block *const *r;
1647
63.1k
        if (is_sub8x8) {
1648
13.8k
            assert(ss_hor == 1);
1649
13.8k
            r = &t->rt.r[(t->by & 31) + 5];
1650
13.8k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
13.8k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
13.8k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.75k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
13.8k
        }
1655
1656
        // chroma prediction
1657
63.1k
        if (is_sub8x8) {
1658
13.6k
            assert(ss_hor == 1);
1659
13.6k
            ptrdiff_t h_off = 0, v_off = 0;
1660
13.6k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.13k
                for (int pl = 0; pl < 2; pl++) {
1662
3.42k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.42k
                             NULL, f->cur.stride[1],
1664
3.42k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.42k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.42k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.42k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.42k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.42k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.42k
                    if (res) return res;
1671
3.42k
                }
1672
1.71k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.71k
                h_off = 2;
1674
1.71k
            }
1675
13.6k
            if (bw4 == 1) {
1676
6.93k
                const enum Filter2d left_filter_2d =
1677
6.93k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
20.7k
                for (int pl = 0; pl < 2; pl++) {
1679
13.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
13.8k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
13.8k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
13.8k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
13.8k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
13.8k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
13.8k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
13.8k
                    if (res) return res;
1687
13.8k
                }
1688
6.93k
                h_off = 2;
1689
6.93k
            }
1690
13.6k
            if (bh4 == ss_ver) {
1691
8.42k
                const enum Filter2d top_filter_2d =
1692
8.42k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
25.2k
                for (int pl = 0; pl < 2; pl++) {
1694
16.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
16.8k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
16.8k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
16.8k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
16.8k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
16.8k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
16.8k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
16.8k
                    if (res) return res;
1702
16.8k
                }
1703
8.42k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
8.42k
            }
1705
40.9k
            for (int pl = 0; pl < 2; pl++) {
1706
27.2k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
27.2k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
27.2k
                         refp, b->ref[0], filter_2d);
1709
27.2k
                if (res) return res;
1710
27.2k
            }
1711
49.5k
        } else {
1712
49.5k
            if (imin(cbw4, cbh4) > 1 &&
1713
21.1k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
20.7k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
489
            {
1716
1.46k
                for (int pl = 0; pl < 2; pl++) {
1717
978
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
978
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
978
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
978
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
978
                    if (res) return res;
1722
978
                }
1723
49.0k
            } else {
1724
147k
                for (int pl = 0; pl < 2; pl++) {
1725
98.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
98.0k
                             NULL, f->cur.stride[1],
1727
98.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
98.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
98.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
98.0k
                    if (res) return res;
1731
98.0k
                    if (b->motion_mode == MM_OBMC) {
1732
29.5k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
29.5k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
29.5k
                        if (res) return res;
1735
29.5k
                    }
1736
98.0k
                }
1737
49.0k
            }
1738
49.5k
            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.81k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
14.4k
                for (int pl = 0; pl < 2; pl++) {
1745
9.62k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
9.62k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
9.62k
                    enum IntraPredMode m =
1748
9.62k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
8.04k
                        SMOOTH_PRED : b->interintra_mode;
1750
9.62k
                    int angle = 0;
1751
9.62k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
9.62k
                    const pixel *top_sb_edge = NULL;
1753
9.62k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.09k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.09k
                        const int sby = t->by >> f->sb_shift;
1756
1.09k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.09k
                    }
1758
9.62k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
9.62k
                                                          (t->bx >> ss_hor) >
1760
9.62k
                                                              (ts->tiling.col_start >> ss_hor),
1761
9.62k
                                                          t->by >> ss_ver,
1762
9.62k
                                                          (t->by >> ss_ver) >
1763
9.62k
                                                              (ts->tiling.row_start >> ss_ver),
1764
9.62k
                                                          ts->tiling.col_end >> ss_hor,
1765
9.62k
                                                          ts->tiling.row_end >> ss_ver,
1766
9.62k
                                                          0, uvdst, f->cur.stride[1],
1767
9.62k
                                                          top_sb_edge, m,
1768
9.62k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
9.62k
                                                          HIGHBD_CALL_SUFFIX);
1770
9.62k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
9.62k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
9.62k
                                             HIGHBD_CALL_SUFFIX);
1773
9.62k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
9.62k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
9.62k
                }
1776
4.81k
            }
1777
49.5k
        }
1778
1779
94.9k
    skip_inter_chroma_pred: {}
1780
94.9k
        t->tl_4x4_filter = filter_2d;
1781
94.9k
    } else {
1782
20.8k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
20.8k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
20.8k
        int jnt_weight;
1786
20.8k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
20.8k
        const uint8_t *mask;
1788
1789
62.5k
        for (int i = 0; i < 2; i++) {
1790
41.7k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
41.7k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
284
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
284
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
284
                if (res) return res;
1796
41.4k
            } else {
1797
41.4k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
41.4k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
41.4k
                if (res) return res;
1800
41.4k
            }
1801
41.7k
        }
1802
20.8k
        switch (b->comp_type) {
1803
17.7k
        case COMP_INTER_AVG:
1804
17.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
17.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
17.7k
            break;
1807
208
        case COMP_INTER_WEIGHTED_AVG:
1808
208
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
208
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
208
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
208
            break;
1812
1.86k
        case COMP_INTER_SEG:
1813
1.86k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.86k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.86k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.86k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.86k
            mask = seg_mask;
1818
1.86k
            break;
1819
1.07k
        case COMP_INTER_WEDGE:
1820
1.07k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.07k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.07k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.07k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.07k
            if (has_chroma)
1825
853
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.07k
            break;
1827
20.8k
        }
1828
1829
        // chroma
1830
53.0k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
106k
            for (int i = 0; i < 2; i++) {
1832
70.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
70.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
7.59k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
142
                {
1836
142
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
142
                                      b_dim, 1 + pl,
1838
142
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
142
                    if (res) return res;
1840
70.5k
                } else {
1841
70.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
70.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
70.5k
                    if (res) return res;
1844
70.5k
                }
1845
70.7k
            }
1846
35.3k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
35.3k
            switch (b->comp_type) {
1848
30.3k
            case COMP_INTER_AVG:
1849
30.3k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
30.3k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
30.3k
                            HIGHBD_CALL_SUFFIX);
1852
30.3k
                break;
1853
300
            case COMP_INTER_WEIGHTED_AVG:
1854
300
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
300
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
300
                              HIGHBD_CALL_SUFFIX);
1857
300
                break;
1858
1.70k
            case COMP_INTER_WEDGE:
1859
4.68k
            case COMP_INTER_SEG:
1860
4.68k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
4.68k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
4.68k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
4.68k
                             HIGHBD_CALL_SUFFIX);
1864
4.68k
                break;
1865
35.3k
            }
1866
35.3k
        }
1867
20.8k
    }
1868
1869
133k
    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
133k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
133k
    if (b->skip) {
1882
        // reset coef contexts
1883
56.8k
        BlockContext *const a = t->a;
1884
56.8k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
56.8k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
56.8k
        if (has_chroma) {
1887
39.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
39.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
39.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
39.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
39.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
39.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
39.3k
        }
1894
56.8k
        return 0;
1895
56.8k
    }
1896
1897
76.4k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
76.4k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
76.4k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
155k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
160k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
82.3k
            int y_off = !!init_y, y;
1905
82.3k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
165k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
82.7k
                 y += ytx->h, y_off++)
1908
82.7k
            {
1909
82.7k
                int x, x_off = !!init_x;
1910
167k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
84.6k
                     x += ytx->w, x_off++)
1912
84.6k
                {
1913
84.6k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
84.6k
                                   x_off, y_off, &dst[x * 4]);
1915
84.6k
                    t->bx += ytx->w;
1916
84.6k
                }
1917
82.7k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
82.7k
                t->bx -= x;
1919
82.7k
                t->by += ytx->h;
1920
82.7k
            }
1921
82.3k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
82.3k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
186k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
124k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
124k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
124k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
253k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
129k
                {
1931
129k
                    int x;
1932
129k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
267k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
138k
                    {
1935
138k
                        coef *cf;
1936
138k
                        int eob;
1937
138k
                        enum TxfmType txtp;
1938
138k
                        if (t->frame_thread.pass) {
1939
138k
                            const int p = t->frame_thread.pass & 1;
1940
138k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
138k
                            cf = ts->frame_thread[p].cf;
1942
138k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
138k
                            eob  = cbi >> 5;
1944
138k
                            txtp = cbi & 0x1f;
1945
138k
                        } 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
138k
                        if (eob >= 0) {
1964
33.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
33.7k
                            dsp->itx.itxfm_add[b->uvtx]
1967
33.7k
                                              [txtp](&uvdst[4 * x],
1968
33.7k
                                                     f->cur.stride[1],
1969
33.7k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
33.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
33.7k
                        }
1974
138k
                        t->bx += uvtx->w << ss_hor;
1975
138k
                    }
1976
129k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
129k
                    t->bx -= x << ss_hor;
1978
129k
                    t->by += uvtx->h << ss_ver;
1979
129k
                }
1980
124k
                t->by -= y << ss_ver;
1981
124k
            }
1982
82.3k
        }
1983
78.6k
    }
1984
76.4k
    return 0;
1985
133k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
177k
{
1560
177k
    Dav1dTileState *const ts = t->ts;
1561
177k
    const Dav1dFrameContext *const f = t->f;
1562
177k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
177k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
177k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
177k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
177k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
177k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
177k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
177k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
177k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
115k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
106k
                           (bh4 > ss_ver || t->by & 1);
1573
177k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
177k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
177k
    int res;
1576
1577
    // prediction
1578
177k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
177k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
177k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
177k
    const ptrdiff_t uvdstoff =
1582
177k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
177k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
13.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
13.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
13.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
13.7k
        if (res) return res;
1589
32.9k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
21.9k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
21.9k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
21.9k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
21.9k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
21.9k
            if (res) return res;
1595
21.9k
        }
1596
163k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
125k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
125k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
125k
        if (imin(bw4, bh4) > 1 &&
1601
75.3k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
73.7k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.02k
        {
1604
2.02k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.02k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.02k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.02k
            if (res) return res;
1608
123k
        } else {
1609
123k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
123k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
123k
            if (res) return res;
1612
123k
            if (b->motion_mode == MM_OBMC) {
1613
24.8k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
24.8k
                if (res) return res;
1615
24.8k
            }
1616
123k
        }
1617
125k
        if (b->interintra_type) {
1618
3.88k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.88k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.06k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.88k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.88k
            int angle = 0;
1623
3.88k
            const pixel *top_sb_edge = NULL;
1624
3.88k
            if (!(t->by & (f->sb_step - 1))) {
1625
841
                top_sb_edge = f->ipred_edge[0];
1626
841
                const int sby = t->by >> f->sb_shift;
1627
841
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
841
            }
1629
3.88k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.88k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.88k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.88k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.88k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.88k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.88k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.88k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.88k
                                     HIGHBD_CALL_SUFFIX);
1638
3.88k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.88k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.88k
        }
1641
1642
125k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
67.7k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
67.7k
        refmvs_block *const *r;
1647
67.7k
        if (is_sub8x8) {
1648
13.5k
            assert(ss_hor == 1);
1649
13.5k
            r = &t->rt.r[(t->by & 31) + 5];
1650
13.5k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
13.5k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
13.5k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.84k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
13.5k
        }
1655
1656
        // chroma prediction
1657
67.7k
        if (is_sub8x8) {
1658
12.8k
            assert(ss_hor == 1);
1659
12.8k
            ptrdiff_t h_off = 0, v_off = 0;
1660
12.8k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.98k
                for (int pl = 0; pl < 2; pl++) {
1662
3.32k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.32k
                             NULL, f->cur.stride[1],
1664
3.32k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.32k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.32k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.32k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.32k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.32k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.32k
                    if (res) return res;
1671
3.32k
                }
1672
1.66k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.66k
                h_off = 2;
1674
1.66k
            }
1675
12.8k
            if (bw4 == 1) {
1676
6.03k
                const enum Filter2d left_filter_2d =
1677
6.03k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
18.0k
                for (int pl = 0; pl < 2; pl++) {
1679
12.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
12.0k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
12.0k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
12.0k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
12.0k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
12.0k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
12.0k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
12.0k
                    if (res) return res;
1687
12.0k
                }
1688
6.03k
                h_off = 2;
1689
6.03k
            }
1690
12.8k
            if (bh4 == ss_ver) {
1691
8.49k
                const enum Filter2d top_filter_2d =
1692
8.49k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
25.4k
                for (int pl = 0; pl < 2; pl++) {
1694
16.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
16.9k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
16.9k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
16.9k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
16.9k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
16.9k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
16.9k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
16.9k
                    if (res) return res;
1702
16.9k
                }
1703
8.49k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
8.49k
            }
1705
38.6k
            for (int pl = 0; pl < 2; pl++) {
1706
25.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
25.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
25.7k
                         refp, b->ref[0], filter_2d);
1709
25.7k
                if (res) return res;
1710
25.7k
            }
1711
54.9k
        } else {
1712
54.9k
            if (imin(cbw4, cbh4) > 1 &&
1713
21.1k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
20.5k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
721
            {
1716
2.16k
                for (int pl = 0; pl < 2; pl++) {
1717
1.44k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.44k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.44k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.44k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.44k
                    if (res) return res;
1722
1.44k
                }
1723
54.2k
            } else {
1724
162k
                for (int pl = 0; pl < 2; pl++) {
1725
108k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
108k
                             NULL, f->cur.stride[1],
1727
108k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
108k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
108k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
108k
                    if (res) return res;
1731
108k
                    if (b->motion_mode == MM_OBMC) {
1732
45.9k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
45.9k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
45.9k
                        if (res) return res;
1735
45.9k
                    }
1736
108k
                }
1737
54.2k
            }
1738
54.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
1.89k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.69k
                for (int pl = 0; pl < 2; pl++) {
1745
3.79k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.79k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.79k
                    enum IntraPredMode m =
1748
3.79k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.86k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.79k
                    int angle = 0;
1751
3.79k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.79k
                    const pixel *top_sb_edge = NULL;
1753
3.79k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.00k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.00k
                        const int sby = t->by >> f->sb_shift;
1756
1.00k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.00k
                    }
1758
3.79k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.79k
                                                          (t->bx >> ss_hor) >
1760
3.79k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.79k
                                                          t->by >> ss_ver,
1762
3.79k
                                                          (t->by >> ss_ver) >
1763
3.79k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.79k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.79k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.79k
                                                          0, uvdst, f->cur.stride[1],
1767
3.79k
                                                          top_sb_edge, m,
1768
3.79k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.79k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.79k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.79k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.79k
                                             HIGHBD_CALL_SUFFIX);
1773
3.79k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.79k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.79k
                }
1776
1.89k
            }
1777
54.9k
        }
1778
1779
125k
    skip_inter_chroma_pred: {}
1780
125k
        t->tl_4x4_filter = filter_2d;
1781
125k
    } else {
1782
37.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
37.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
37.9k
        int jnt_weight;
1786
37.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
37.9k
        const uint8_t *mask;
1788
1789
113k
        for (int i = 0; i < 2; i++) {
1790
75.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
75.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
310
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
310
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
310
                if (res) return res;
1796
75.6k
            } else {
1797
75.6k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
75.6k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
75.6k
                if (res) return res;
1800
75.6k
            }
1801
75.9k
        }
1802
37.9k
        switch (b->comp_type) {
1803
32.4k
        case COMP_INTER_AVG:
1804
32.4k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
32.4k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
32.4k
            break;
1807
116
        case COMP_INTER_WEIGHTED_AVG:
1808
116
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
116
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
116
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
116
            break;
1812
3.44k
        case COMP_INTER_SEG:
1813
3.44k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
3.44k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
3.44k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
3.44k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
3.44k
            mask = seg_mask;
1818
3.44k
            break;
1819
1.97k
        case COMP_INTER_WEDGE:
1820
1.97k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.97k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.97k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.97k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.97k
            if (has_chroma)
1825
557
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.97k
            break;
1827
37.9k
        }
1828
1829
        // chroma
1830
53.3k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
106k
            for (int i = 0; i < 2; i++) {
1832
71.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
71.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.33k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
182
                {
1836
182
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
182
                                      b_dim, 1 + pl,
1838
182
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
182
                    if (res) return res;
1840
70.9k
                } else {
1841
70.9k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
70.9k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
70.9k
                    if (res) return res;
1844
70.9k
                }
1845
71.1k
            }
1846
35.5k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
35.5k
            switch (b->comp_type) {
1848
31.7k
            case COMP_INTER_AVG:
1849
31.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
31.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
31.7k
                            HIGHBD_CALL_SUFFIX);
1852
31.7k
                break;
1853
98
            case COMP_INTER_WEIGHTED_AVG:
1854
98
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
98
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
98
                              HIGHBD_CALL_SUFFIX);
1857
98
                break;
1858
1.11k
            case COMP_INTER_WEDGE:
1859
3.75k
            case COMP_INTER_SEG:
1860
3.75k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.75k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.75k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.75k
                             HIGHBD_CALL_SUFFIX);
1864
3.75k
                break;
1865
35.5k
            }
1866
35.5k
        }
1867
37.9k
    }
1868
1869
177k
    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
177k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
177k
    if (b->skip) {
1882
        // reset coef contexts
1883
76.0k
        BlockContext *const a = t->a;
1884
76.0k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
76.0k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
76.0k
        if (has_chroma) {
1887
47.9k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
47.9k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
47.9k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
47.9k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
47.9k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
47.9k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
47.9k
        }
1894
76.0k
        return 0;
1895
76.0k
    }
1896
1897
101k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
101k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
101k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
203k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
207k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
105k
            int y_off = !!init_y, y;
1905
105k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
211k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
106k
                 y += ytx->h, y_off++)
1908
106k
            {
1909
106k
                int x, x_off = !!init_x;
1910
215k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
109k
                     x += ytx->w, x_off++)
1912
109k
                {
1913
109k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
109k
                                   x_off, y_off, &dst[x * 4]);
1915
109k
                    t->bx += ytx->w;
1916
109k
                }
1917
106k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
106k
                t->bx -= x;
1919
106k
                t->by += ytx->h;
1920
106k
            }
1921
105k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
105k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
150k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
100k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
100k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
100k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
202k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
101k
                {
1931
101k
                    int x;
1932
101k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
205k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
103k
                    {
1935
103k
                        coef *cf;
1936
103k
                        int eob;
1937
103k
                        enum TxfmType txtp;
1938
103k
                        if (t->frame_thread.pass) {
1939
103k
                            const int p = t->frame_thread.pass & 1;
1940
103k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
103k
                            cf = ts->frame_thread[p].cf;
1942
103k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
103k
                            eob  = cbi >> 5;
1944
103k
                            txtp = cbi & 0x1f;
1945
103k
                        } 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
103k
                        if (eob >= 0) {
1964
20.8k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
20.8k
                            dsp->itx.itxfm_add[b->uvtx]
1967
20.8k
                                              [txtp](&uvdst[4 * x],
1968
20.8k
                                                     f->cur.stride[1],
1969
20.8k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
20.8k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
20.8k
                        }
1974
103k
                        t->bx += uvtx->w << ss_hor;
1975
103k
                    }
1976
101k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
101k
                    t->bx -= x << ss_hor;
1978
101k
                    t->by += uvtx->h << ss_ver;
1979
101k
                }
1980
100k
                t->by -= y << ss_ver;
1981
100k
            }
1982
105k
        }
1983
102k
    }
1984
101k
    return 0;
1985
177k
}
1986
1987
87.5k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
87.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
87.5k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
87.5k
    const int y = sby * f->sb_step * 4;
1994
87.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
87.5k
    pixel *const p[3] = {
1996
87.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
87.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
87.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
87.5k
    };
2000
87.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
87.5k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
87.5k
                                        f->lf.start_of_tile_row[sby]);
2003
87.5k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
46.6k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
46.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
46.6k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
46.6k
    const int y = sby * f->sb_step * 4;
1994
46.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
46.6k
    pixel *const p[3] = {
1996
46.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
46.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
46.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
46.6k
    };
2000
46.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
46.6k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
46.6k
                                        f->lf.start_of_tile_row[sby]);
2003
46.6k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
40.9k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
40.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
40.9k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
40.9k
    const int y = sby * f->sb_step * 4;
1994
40.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
40.9k
    pixel *const p[3] = {
1996
40.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
40.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
40.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
40.9k
    };
2000
40.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
40.9k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
40.9k
                                        f->lf.start_of_tile_row[sby]);
2003
40.9k
}
2004
2005
97.3k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
97.3k
    const int y = sby * f->sb_step * 4;
2007
97.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
97.3k
    pixel *const p[3] = {
2009
97.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
97.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
97.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
97.3k
    };
2013
97.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
97.3k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
97.3k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
87.1k
    {
2017
87.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
87.1k
    }
2019
97.3k
    if (f->lf.cdef_planes || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
64.1k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
64.1k
    }
2023
97.3k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
50.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
50.0k
    const int y = sby * f->sb_step * 4;
2007
50.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
50.0k
    pixel *const p[3] = {
2009
50.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
50.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
50.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
50.0k
    };
2013
50.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
50.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
50.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
46.3k
    {
2017
46.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
46.3k
    }
2019
50.0k
    if (f->lf.cdef_planes || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
27.6k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
27.6k
    }
2023
50.0k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
47.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
47.2k
    const int y = sby * f->sb_step * 4;
2007
47.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
47.2k
    pixel *const p[3] = {
2009
47.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
47.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
47.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
47.2k
    };
2013
47.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
47.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
47.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
40.7k
    {
2017
40.7k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
40.7k
    }
2019
47.2k
    if (f->lf.cdef_planes || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
36.4k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
36.4k
    }
2023
47.2k
}
2024
2025
47.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
47.8k
    const Dav1dFrameContext *const f = tc->f;
2027
47.8k
    const int sbsz = f->sb_step;
2028
47.8k
    const int y = sby * sbsz * 4;
2029
47.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2030
47.8k
    pixel *const p[3] = {
2031
47.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2032
47.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2033
47.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2034
47.8k
    };
2035
47.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2036
47.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2037
47.8k
    const int start = sby * sbsz;
2038
47.8k
    if (sby) {
2039
31.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2040
31.3k
        pixel *p_up[3] = {
2041
31.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2042
31.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2043
31.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
31.3k
        };
2045
31.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2046
31.3k
    }
2047
47.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2048
47.8k
    const int end = imin(start + n_blks, f->bh);
2049
47.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2050
47.8k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
19.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
19.8k
    const Dav1dFrameContext *const f = tc->f;
2027
19.8k
    const int sbsz = f->sb_step;
2028
19.8k
    const int y = sby * sbsz * 4;
2029
19.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2030
19.8k
    pixel *const p[3] = {
2031
19.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2032
19.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2033
19.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2034
19.8k
    };
2035
19.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2036
19.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2037
19.8k
    const int start = sby * sbsz;
2038
19.8k
    if (sby) {
2039
11.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2040
11.3k
        pixel *p_up[3] = {
2041
11.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2042
11.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2043
11.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
11.3k
        };
2045
11.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2046
11.3k
    }
2047
19.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2048
19.8k
    const int end = imin(start + n_blks, f->bh);
2049
19.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2050
19.8k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
28.0k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
28.0k
    const Dav1dFrameContext *const f = tc->f;
2027
28.0k
    const int sbsz = f->sb_step;
2028
28.0k
    const int y = sby * sbsz * 4;
2029
28.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2030
28.0k
    pixel *const p[3] = {
2031
28.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2032
28.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2033
28.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2034
28.0k
    };
2035
28.0k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2036
28.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2037
28.0k
    const int start = sby * sbsz;
2038
28.0k
    if (sby) {
2039
20.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2040
20.0k
        pixel *p_up[3] = {
2041
20.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2042
20.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2043
20.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
20.0k
        };
2045
20.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2046
20.0k
    }
2047
28.0k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2048
28.0k
    const int end = imin(start + n_blks, f->bh);
2049
28.0k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2050
28.0k
}
2051
2052
27.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2053
27.0k
    const int sbsz = f->sb_step;
2054
27.0k
    const int y = sby * sbsz * 4;
2055
27.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2056
27.0k
    const pixel *const p[3] = {
2057
27.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2058
27.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2059
27.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2060
27.0k
    };
2061
27.0k
    pixel *const sr_p[3] = {
2062
27.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2063
27.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2064
27.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2065
27.0k
    };
2066
27.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2067
96.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2068
69.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2069
69.9k
        const int h_start = 8 * !!sby >> ss_ver;
2070
69.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2071
69.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2072
69.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2073
69.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2074
69.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2075
69.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2076
69.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2077
69.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2078
69.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2079
2080
69.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2081
69.9k
                          imin(img_h, h_end) + h_start, src_w,
2082
69.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2083
69.9k
                          HIGHBD_CALL_SUFFIX);
2084
69.9k
    }
2085
27.0k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2052
11.4k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2053
11.4k
    const int sbsz = f->sb_step;
2054
11.4k
    const int y = sby * sbsz * 4;
2055
11.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2056
11.4k
    const pixel *const p[3] = {
2057
11.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2058
11.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2059
11.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2060
11.4k
    };
2061
11.4k
    pixel *const sr_p[3] = {
2062
11.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2063
11.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2064
11.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2065
11.4k
    };
2066
11.4k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2067
41.1k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2068
29.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2069
29.7k
        const int h_start = 8 * !!sby >> ss_ver;
2070
29.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2071
29.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2072
29.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2073
29.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2074
29.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2075
29.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2076
29.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2077
29.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2078
29.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2079
2080
29.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2081
29.7k
                          imin(img_h, h_end) + h_start, src_w,
2082
29.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2083
29.7k
                          HIGHBD_CALL_SUFFIX);
2084
29.7k
    }
2085
11.4k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2052
15.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2053
15.6k
    const int sbsz = f->sb_step;
2054
15.6k
    const int y = sby * sbsz * 4;
2055
15.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2056
15.6k
    const pixel *const p[3] = {
2057
15.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2058
15.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2059
15.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2060
15.6k
    };
2061
15.6k
    pixel *const sr_p[3] = {
2062
15.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2063
15.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2064
15.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2065
15.6k
    };
2066
15.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2067
55.8k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2068
40.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2069
40.1k
        const int h_start = 8 * !!sby >> ss_ver;
2070
40.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2071
40.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2072
40.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2073
40.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2074
40.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2075
40.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2076
40.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2077
40.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2078
40.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2079
2080
40.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2081
40.1k
                          imin(img_h, h_end) + h_start, src_w,
2082
40.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2083
40.1k
                          HIGHBD_CALL_SUFFIX);
2084
40.1k
    }
2085
15.6k
}
2086
2087
35.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2088
35.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2089
35.8k
    const int y = sby * f->sb_step * 4;
2090
35.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2091
35.8k
    pixel *const sr_p[3] = {
2092
35.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2093
35.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2094
35.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2095
35.8k
    };
2096
35.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2097
35.8k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2087
16.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2088
16.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2089
16.4k
    const int y = sby * f->sb_step * 4;
2090
16.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2091
16.4k
    pixel *const sr_p[3] = {
2092
16.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2093
16.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2094
16.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2095
16.4k
    };
2096
16.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2097
16.4k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2087
19.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2088
19.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2089
19.4k
    const int y = sby * f->sb_step * 4;
2090
19.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2091
19.4k
    pixel *const sr_p[3] = {
2092
19.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2093
19.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2094
19.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2095
19.4k
    };
2096
19.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2097
19.4k
}
2098
2099
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2100
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2101
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2102
0
    if (f->lf.cdef_planes)
2103
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2104
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2105
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2106
0
    if (f->lf.restore_planes)
2107
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2108
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2109
2110
133k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2111
133k
    const Dav1dFrameContext *const f = t->f;
2112
133k
    Dav1dTileState *const ts = t->ts;
2113
133k
    const int sby = t->by >> f->sb_shift;
2114
133k
    const int sby_off = f->sb128w * 128 * sby;
2115
133k
    const int x_off = ts->tiling.col_start;
2116
2117
133k
    const pixel *const y =
2118
133k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2119
133k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2120
133k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2121
133k
               4 * (ts->tiling.col_end - x_off));
2122
2123
133k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2124
104k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2125
104k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2126
2127
104k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2128
104k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2129
314k
        for (int pl = 1; pl <= 2; pl++)
2130
209k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2131
107k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2132
107k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2133
104k
    }
2134
133k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2110
66.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2111
66.8k
    const Dav1dFrameContext *const f = t->f;
2112
66.8k
    Dav1dTileState *const ts = t->ts;
2113
66.8k
    const int sby = t->by >> f->sb_shift;
2114
66.8k
    const int sby_off = f->sb128w * 128 * sby;
2115
66.8k
    const int x_off = ts->tiling.col_start;
2116
2117
66.8k
    const pixel *const y =
2118
66.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2119
66.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2120
66.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2121
66.8k
               4 * (ts->tiling.col_end - x_off));
2122
2123
66.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2124
53.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2125
53.8k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2126
2127
53.8k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2128
53.8k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2129
161k
        for (int pl = 1; pl <= 2; pl++)
2130
107k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2131
107k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2132
107k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2133
53.8k
    }
2134
66.8k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2110
66.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2111
66.8k
    const Dav1dFrameContext *const f = t->f;
2112
66.8k
    Dav1dTileState *const ts = t->ts;
2113
66.8k
    const int sby = t->by >> f->sb_shift;
2114
66.8k
    const int sby_off = f->sb128w * 128 * sby;
2115
66.8k
    const int x_off = ts->tiling.col_start;
2116
2117
66.8k
    const pixel *const y =
2118
66.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2119
66.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2120
66.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2121
66.8k
               4 * (ts->tiling.col_end - x_off));
2122
2123
66.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2124
50.9k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2125
50.9k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2126
2127
50.9k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2128
50.9k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2129
152k
        for (int pl = 1; pl <= 2; pl++)
2130
101k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2131
50.9k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2132
50.9k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2133
50.9k
    }
2134
66.8k
}
2135
2136
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2137
                                    const int bx4, const int by4,
2138
                                    const int bw4, const int bh4)
2139
2140
21.4k
{
2141
21.4k
    const Dav1dFrameContext *const f = t->f;
2142
21.4k
    pixel *const pal = t->frame_thread.pass ?
2143
21.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2144
21.4k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2145
21.4k
        bytefn(t->scratch.pal)[0];
2146
106k
    for (int x = 0; x < bw4; x++)
2147
85.0k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2148
88.0k
    for (int y = 0; y < bh4; y++)
2149
66.5k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2150
21.4k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2140
10.8k
{
2141
10.8k
    const Dav1dFrameContext *const f = t->f;
2142
10.8k
    pixel *const pal = t->frame_thread.pass ?
2143
10.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2144
10.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2145
10.8k
        bytefn(t->scratch.pal)[0];
2146
53.1k
    for (int x = 0; x < bw4; x++)
2147
42.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2148
43.4k
    for (int y = 0; y < bh4; y++)
2149
32.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2150
10.8k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2140
10.6k
{
2141
10.6k
    const Dav1dFrameContext *const f = t->f;
2142
10.6k
    pixel *const pal = t->frame_thread.pass ?
2143
10.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2144
10.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2145
10.6k
        bytefn(t->scratch.pal)[0];
2146
53.3k
    for (int x = 0; x < bw4; x++)
2147
42.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2148
44.5k
    for (int y = 0; y < bh4; y++)
2149
33.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2150
10.6k
}
2151
2152
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2153
                                     const int bx4, const int by4,
2154
                                     const int bw4, const int bh4)
2155
2156
6.11k
{
2157
6.11k
    const Dav1dFrameContext *const f = t->f;
2158
6.11k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2159
6.11k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2160
6.11k
                            ((t->bx >> 1) + (t->by & 1))] :
2161
6.11k
        bytefn(t->scratch.pal);
2162
    // see aomedia bug 2183 for why we use luma coordinates here
2163
18.3k
    for (int pl = 1; pl <= 2; pl++) {
2164
71.5k
        for (int x = 0; x < bw4; x++)
2165
59.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2166
65.7k
        for (int y = 0; y < bh4; y++)
2167
53.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2168
12.2k
    }
2169
6.11k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2156
3.09k
{
2157
3.09k
    const Dav1dFrameContext *const f = t->f;
2158
3.09k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2159
3.09k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2160
3.09k
                            ((t->bx >> 1) + (t->by & 1))] :
2161
3.09k
        bytefn(t->scratch.pal);
2162
    // see aomedia bug 2183 for why we use luma coordinates here
2163
9.28k
    for (int pl = 1; pl <= 2; pl++) {
2164
36.3k
        for (int x = 0; x < bw4; x++)
2165
30.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2166
31.3k
        for (int y = 0; y < bh4; y++)
2167
25.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2168
6.19k
    }
2169
3.09k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2156
3.01k
{
2157
3.01k
    const Dav1dFrameContext *const f = t->f;
2158
3.01k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2159
3.01k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2160
3.01k
                            ((t->bx >> 1) + (t->by & 1))] :
2161
3.01k
        bytefn(t->scratch.pal);
2162
    // see aomedia bug 2183 for why we use luma coordinates here
2163
9.05k
    for (int pl = 1; pl <= 2; pl++) {
2164
35.1k
        for (int x = 0; x < bw4; x++)
2165
29.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2166
34.4k
        for (int y = 0; y < bh4; y++)
2167
28.4k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2168
6.03k
    }
2169
3.01k
}
2170
2171
void bytefn(dav1d_read_pal_plane)(Dav1dTaskContext *const t, Av1Block *const b,
2172
                                  const int pl, const int sz_ctx,
2173
                                  const int bx4, const int by4)
2174
27.5k
{
2175
27.5k
    Dav1dTileState *const ts = t->ts;
2176
27.5k
    const Dav1dFrameContext *const f = t->f;
2177
27.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2178
27.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2179
27.5k
    pixel cache[16], used_cache[8];
2180
27.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2181
27.5k
    int n_cache = 0;
2182
    // don't reuse above palette outside SB64 boundaries
2183
27.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2184
27.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2185
27.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2186
2187
    // fill/sort cache
2188
54.0k
    while (l_cache && a_cache) {
2189
26.4k
        if (*l < *a) {
2190
10.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2191
9.90k
                cache[n_cache++] = *l;
2192
10.0k
            l++;
2193
10.0k
            l_cache--;
2194
16.4k
        } else {
2195
16.4k
            if (*a == *l) {
2196
6.41k
                l++;
2197
6.41k
                l_cache--;
2198
6.41k
            }
2199
16.4k
            if (!n_cache || cache[n_cache - 1] != *a)
2200
15.9k
                cache[n_cache++] = *a;
2201
16.4k
            a++;
2202
16.4k
            a_cache--;
2203
16.4k
        }
2204
26.4k
    }
2205
27.5k
    if (l_cache) {
2206
38.0k
        do {
2207
38.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2208
31.0k
                cache[n_cache++] = *l;
2209
38.0k
            l++;
2210
38.0k
        } while (--l_cache > 0);
2211
18.2k
    } else if (a_cache) {
2212
23.5k
        do {
2213
23.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2214
19.0k
                cache[n_cache++] = *a;
2215
23.5k
            a++;
2216
23.5k
        } while (--a_cache > 0);
2217
6.18k
    }
2218
2219
    // find reused cache entries
2220
27.5k
    int i = 0;
2221
93.9k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2222
66.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2223
32.9k
            used_cache[i++] = cache[n];
2224
27.5k
    const int n_used_cache = i;
2225
2226
    // parse new entries
2227
27.5k
    pixel *const pal = t->frame_thread.pass ?
2228
27.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2229
27.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2230
27.5k
        bytefn(t->scratch.pal)[pl];
2231
27.5k
    if (i < pal_sz) {
2232
23.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2233
23.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2234
2235
23.2k
        if (i < pal_sz) {
2236
20.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2237
20.8k
            const int max = (1 << bpc) - 1;
2238
2239
48.2k
            do {
2240
48.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2241
48.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2242
48.2k
                if (prev + !pl >= max) {
2243
26.5k
                    for (; i < pal_sz; i++)
2244
17.0k
                        pal[i] = max;
2245
9.50k
                    break;
2246
9.50k
                }
2247
38.7k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2248
38.7k
            } while (i < pal_sz);
2249
20.8k
        }
2250
2251
        // merge cache+new entries
2252
23.2k
        int n = 0, m = n_used_cache;
2253
132k
        for (i = 0; i < pal_sz; i++) {
2254
109k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2255
21.1k
                pal[i] = used_cache[n++];
2256
88.6k
            } else {
2257
88.6k
                assert(m < pal_sz);
2258
88.6k
                pal[i] = pal[m++];
2259
88.6k
            }
2260
109k
        }
2261
23.2k
    } else {
2262
4.34k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2263
4.34k
    }
2264
2265
27.5k
    if (DEBUG_BLOCK_INFO) {
2266
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2267
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2268
0
        for (int n = 0; n < n_cache; n++)
2269
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2270
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2271
0
        for (int n = 0; n < pal_sz; n++)
2272
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2273
0
        printf("]\n");
2274
0
    }
2275
27.5k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2174
13.9k
{
2175
13.9k
    Dav1dTileState *const ts = t->ts;
2176
13.9k
    const Dav1dFrameContext *const f = t->f;
2177
13.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2178
13.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2179
13.9k
    pixel cache[16], used_cache[8];
2180
13.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2181
13.9k
    int n_cache = 0;
2182
    // don't reuse above palette outside SB64 boundaries
2183
13.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2184
13.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2185
13.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2186
2187
    // fill/sort cache
2188
28.0k
    while (l_cache && a_cache) {
2189
14.0k
        if (*l < *a) {
2190
5.27k
            if (!n_cache || cache[n_cache - 1] != *l)
2191
5.20k
                cache[n_cache++] = *l;
2192
5.27k
            l++;
2193
5.27k
            l_cache--;
2194
8.81k
        } else {
2195
8.81k
            if (*a == *l) {
2196
3.49k
                l++;
2197
3.49k
                l_cache--;
2198
3.49k
            }
2199
8.81k
            if (!n_cache || cache[n_cache - 1] != *a)
2200
8.53k
                cache[n_cache++] = *a;
2201
8.81k
            a++;
2202
8.81k
            a_cache--;
2203
8.81k
        }
2204
14.0k
    }
2205
13.9k
    if (l_cache) {
2206
19.3k
        do {
2207
19.3k
            if (!n_cache || cache[n_cache - 1] != *l)
2208
15.4k
                cache[n_cache++] = *l;
2209
19.3k
            l++;
2210
19.3k
        } while (--l_cache > 0);
2211
9.10k
    } else if (a_cache) {
2212
11.9k
        do {
2213
11.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2214
9.54k
                cache[n_cache++] = *a;
2215
11.9k
            a++;
2216
11.9k
        } while (--a_cache > 0);
2217
3.16k
    }
2218
2219
    // find reused cache entries
2220
13.9k
    int i = 0;
2221
48.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2222
34.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2223
17.1k
            used_cache[i++] = cache[n];
2224
13.9k
    const int n_used_cache = i;
2225
2226
    // parse new entries
2227
13.9k
    pixel *const pal = t->frame_thread.pass ?
2228
13.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2229
13.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2230
13.9k
        bytefn(t->scratch.pal)[pl];
2231
13.9k
    if (i < pal_sz) {
2232
11.7k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2233
11.7k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2234
2235
11.7k
        if (i < pal_sz) {
2236
10.4k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2237
10.4k
            const int max = (1 << bpc) - 1;
2238
2239
24.0k
            do {
2240
24.0k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2241
24.0k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2242
24.0k
                if (prev + !pl >= max) {
2243
13.3k
                    for (; i < pal_sz; i++)
2244
8.55k
                        pal[i] = max;
2245
4.80k
                    break;
2246
4.80k
                }
2247
19.2k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2248
19.2k
            } while (i < pal_sz);
2249
10.4k
        }
2250
2251
        // merge cache+new entries
2252
11.7k
        int n = 0, m = n_used_cache;
2253
67.2k
        for (i = 0; i < pal_sz; i++) {
2254
55.5k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2255
11.1k
                pal[i] = used_cache[n++];
2256
44.4k
            } else {
2257
44.4k
                assert(m < pal_sz);
2258
44.4k
                pal[i] = pal[m++];
2259
44.4k
            }
2260
55.5k
        }
2261
11.7k
    } else {
2262
2.16k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2263
2.16k
    }
2264
2265
13.9k
    if (DEBUG_BLOCK_INFO) {
2266
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2267
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2268
0
        for (int n = 0; n < n_cache; n++)
2269
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2270
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2271
0
        for (int n = 0; n < pal_sz; n++)
2272
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2273
0
        printf("]\n");
2274
0
    }
2275
13.9k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2174
13.6k
{
2175
13.6k
    Dav1dTileState *const ts = t->ts;
2176
13.6k
    const Dav1dFrameContext *const f = t->f;
2177
13.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2178
13.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2179
13.6k
    pixel cache[16], used_cache[8];
2180
13.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2181
13.6k
    int n_cache = 0;
2182
    // don't reuse above palette outside SB64 boundaries
2183
13.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2184
13.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2185
13.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2186
2187
    // fill/sort cache
2188
26.0k
    while (l_cache && a_cache) {
2189
12.3k
        if (*l < *a) {
2190
4.74k
            if (!n_cache || cache[n_cache - 1] != *l)
2191
4.69k
                cache[n_cache++] = *l;
2192
4.74k
            l++;
2193
4.74k
            l_cache--;
2194
7.61k
        } else {
2195
7.61k
            if (*a == *l) {
2196
2.91k
                l++;
2197
2.91k
                l_cache--;
2198
2.91k
            }
2199
7.61k
            if (!n_cache || cache[n_cache - 1] != *a)
2200
7.40k
                cache[n_cache++] = *a;
2201
7.61k
            a++;
2202
7.61k
            a_cache--;
2203
7.61k
        }
2204
12.3k
    }
2205
13.6k
    if (l_cache) {
2206
18.7k
        do {
2207
18.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2208
15.5k
                cache[n_cache++] = *l;
2209
18.7k
            l++;
2210
18.7k
        } while (--l_cache > 0);
2211
9.10k
    } else if (a_cache) {
2212
11.6k
        do {
2213
11.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2214
9.53k
                cache[n_cache++] = *a;
2215
11.6k
            a++;
2216
11.6k
        } while (--a_cache > 0);
2217
3.02k
    }
2218
2219
    // find reused cache entries
2220
13.6k
    int i = 0;
2221
45.6k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2222
31.9k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2223
15.8k
            used_cache[i++] = cache[n];
2224
13.6k
    const int n_used_cache = i;
2225
2226
    // parse new entries
2227
13.6k
    pixel *const pal = t->frame_thread.pass ?
2228
13.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2229
13.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2230
13.6k
        bytefn(t->scratch.pal)[pl];
2231
13.6k
    if (i < pal_sz) {
2232
11.4k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2233
11.4k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2234
2235
11.4k
        if (i < pal_sz) {
2236
10.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2237
10.3k
            const int max = (1 << bpc) - 1;
2238
2239
24.1k
            do {
2240
24.1k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2241
24.1k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2242
24.1k
                if (prev + !pl >= max) {
2243
13.2k
                    for (; i < pal_sz; i++)
2244
8.53k
                        pal[i] = max;
2245
4.69k
                    break;
2246
4.69k
                }
2247
19.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2248
19.5k
            } while (i < pal_sz);
2249
10.3k
        }
2250
2251
        // merge cache+new entries
2252
11.4k
        int n = 0, m = n_used_cache;
2253
65.6k
        for (i = 0; i < pal_sz; i++) {
2254
54.2k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2255
10.0k
                pal[i] = used_cache[n++];
2256
44.2k
            } else {
2257
44.2k
                assert(m < pal_sz);
2258
44.2k
                pal[i] = pal[m++];
2259
44.2k
            }
2260
54.2k
        }
2261
11.4k
    } else {
2262
2.18k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2263
2.18k
    }
2264
2265
13.6k
    if (DEBUG_BLOCK_INFO) {
2266
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2267
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2268
0
        for (int n = 0; n < n_cache; n++)
2269
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2270
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2271
0
        for (int n = 0; n < pal_sz; n++)
2272
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2273
0
        printf("]\n");
2274
0
    }
2275
13.6k
}
2276
2277
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2278
                               const int sz_ctx, const int bx4, const int by4)
2279
6.11k
{
2280
6.11k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2281
2282
    // V pal coding
2283
6.11k
    Dav1dTileState *const ts = t->ts;
2284
6.11k
    const Dav1dFrameContext *const f = t->f;
2285
6.11k
    pixel *const pal = t->frame_thread.pass ?
2286
6.11k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2287
6.11k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2288
6.11k
        bytefn(t->scratch.pal)[2];
2289
6.11k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2290
6.11k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2291
3.15k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2292
3.15k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2293
3.15k
        const int max = (1 << bpc) - 1;
2294
13.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2295
10.1k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2296
10.1k
            if (delta) {
2297
9.83k
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
2298
9.83k
                delta = apply_sign_bool(delta, sign);
2299
9.83k
            }
2300
10.1k
            prev = pal[i] = (prev + delta) & max;
2301
10.1k
        }
2302
3.15k
    } else {
2303
15.3k
        for (int i = 0; i < b->pal_sz[1]; i++)
2304
12.3k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2305
2.96k
    }
2306
6.11k
    if (DEBUG_BLOCK_INFO) {
2307
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2308
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2309
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2310
0
        printf("]\n");
2311
0
    }
2312
6.11k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2279
3.09k
{
2280
3.09k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2281
2282
    // V pal coding
2283
3.09k
    Dav1dTileState *const ts = t->ts;
2284
3.09k
    const Dav1dFrameContext *const f = t->f;
2285
3.09k
    pixel *const pal = t->frame_thread.pass ?
2286
3.09k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2287
3.09k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2288
3.09k
        bytefn(t->scratch.pal)[2];
2289
3.09k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2290
3.09k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2291
1.65k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2292
1.65k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2293
1.65k
        const int max = (1 << bpc) - 1;
2294
7.02k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2295
5.37k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2296
5.37k
            if (delta) {
2297
5.14k
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
2298
5.14k
                delta = apply_sign_bool(delta, sign);
2299
5.14k
            }
2300
5.37k
            prev = pal[i] = (prev + delta) & max;
2301
5.37k
        }
2302
1.65k
    } else {
2303
7.38k
        for (int i = 0; i < b->pal_sz[1]; i++)
2304
5.94k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2305
1.44k
    }
2306
3.09k
    if (DEBUG_BLOCK_INFO) {
2307
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2308
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2309
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2310
0
        printf("]\n");
2311
0
    }
2312
3.09k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2279
3.01k
{
2280
3.01k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2281
2282
    // V pal coding
2283
3.01k
    Dav1dTileState *const ts = t->ts;
2284
3.01k
    const Dav1dFrameContext *const f = t->f;
2285
3.01k
    pixel *const pal = t->frame_thread.pass ?
2286
3.01k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2287
3.01k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2288
3.01k
        bytefn(t->scratch.pal)[2];
2289
3.01k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2290
3.01k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2291
1.50k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2292
1.50k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2293
1.50k
        const int max = (1 << bpc) - 1;
2294
6.27k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2295
4.77k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2296
4.77k
            if (delta) {
2297
4.68k
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
2298
4.68k
                delta = apply_sign_bool(delta, sign);
2299
4.68k
            }
2300
4.77k
            prev = pal[i] = (prev + delta) & max;
2301
4.77k
        }
2302
1.51k
    } else {
2303
7.91k
        for (int i = 0; i < b->pal_sz[1]; i++)
2304
6.39k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2305
1.51k
    }
2306
3.01k
    if (DEBUG_BLOCK_INFO) {
2307
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2308
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2309
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2310
0
        printf("]\n");
2311
0
    }
2312
3.01k
}