Coverage Report

Created: 2026-08-31 06:21

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