Coverage Report

Created: 2026-09-13 06:32

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