Coverage Report

Created: 2026-07-16 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
1.25M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.25M
    int len = 0;
51
1.25M
    unsigned val = 1;
52
53
2.26M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
2.26M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.25M
    return val - 1;
57
1.25M
}
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
10.3M
{
66
10.3M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
10.3M
    if (chroma) {
69
5.29M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
5.29M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
5.29M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
3.13M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
5.29M
        unsigned ca, cl;
74
75
5.29M
#define MERGE_CTX(dir, type, no_val) \
76
10.5M
        c##dir = *(const type *) dir != no_val; \
77
10.5M
        break
78
79
5.29M
        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
1.91M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
997k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
800k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
1.58M
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
5.29M
        }
91
5.29M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
2.15M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
987k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
623k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
1.53M
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
5.29M
        }
98
5.29M
#undef MERGE_CTX
99
100
5.29M
        return 7 + not_one_blk * 3 + ca + cl;
101
5.29M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
1.62M
        return 0;
103
3.46M
    } else {
104
3.46M
        unsigned la, ll;
105
106
3.46M
#define MERGE_CTX(dir, type, tx) \
107
6.97M
        if (tx == TX_64X64) { \
108
464k
            uint64_t tmp = *(const uint64_t *) dir; \
109
464k
            tmp |= *(const uint64_t *) &dir[8]; \
110
464k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
464k
        } else \
112
6.97M
            l##dir = *(const type *) dir; \
113
6.97M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
6.97M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
6.97M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
6.97M
        break
117
118
3.46M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
2.17M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
558k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
476k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
39.9k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
232k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
3.46M
        }
126
3.48M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
2.19M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
543k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
475k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
40.5k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
232k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
3.48M
        }
134
3.48M
#undef MERGE_CTX
135
136
3.48M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
3.48M
    }
138
10.3M
}
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
4.69M
{
144
4.69M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
4.69M
    int s;
146
147
4.69M
#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
4.69M
    __asm__("" : "+r"(mask), "+r"(mul));
151
4.69M
#endif
152
153
4.69M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
2.14M
    case TX_4X4: {
156
2.14M
        int t = *(const uint8_t *) a >> 6;
157
2.14M
        t    += *(const uint8_t *) l >> 6;
158
2.14M
        s = t - 1 - 1;
159
2.14M
        break;
160
0
    }
161
419k
    case TX_8X8: {
162
419k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
419k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
419k
        t *= 0x04040404U;
165
419k
        s = (int) (t >> 24) - 2 - 2;
166
419k
        break;
167
0
    }
168
344k
    case TX_16X16: {
169
344k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
344k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
344k
        t *= (uint32_t) mul;
172
344k
        s = (int) (t >> 24) - 4 - 4;
173
344k
        break;
174
0
    }
175
447k
    case TX_32X32: {
176
447k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
447k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
447k
        t *= mul;
179
447k
        s = (int) (t >> 56) - 8 - 8;
180
447k
        break;
181
0
    }
182
193k
    case TX_64X64: {
183
193k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
193k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
193k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
193k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
193k
        t *= mul;
188
193k
        s = (int) (t >> 56) - 16 - 16;
189
193k
        break;
190
0
    }
191
122k
    case RTX_4X8: {
192
122k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
122k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
122k
        t *= 0x04040404U;
195
122k
        s = (int) (t >> 24) - 1 - 2;
196
122k
        break;
197
0
    }
198
192k
    case RTX_8X4: {
199
192k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
192k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
192k
        t *= 0x04040404U;
202
192k
        s = (int) (t >> 24) - 2 - 1;
203
192k
        break;
204
0
    }
205
109k
    case RTX_8X16: {
206
109k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
109k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
109k
        t = (t >> 6) * (uint32_t) mul;
209
109k
        s = (int) (t >> 24) - 2 - 4;
210
109k
        break;
211
0
    }
212
201k
    case RTX_16X8: {
213
201k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
201k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
201k
        t = (t >> 6) * (uint32_t) mul;
216
201k
        s = (int) (t >> 24) - 4 - 2;
217
201k
        break;
218
0
    }
219
67.4k
    case RTX_16X32: {
220
67.4k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
67.4k
        t         += *(const uint64_t *) l & mask;
222
67.4k
        t = (t >> 6) * mul;
223
67.4k
        s = (int) (t >> 56) - 4 - 8;
224
67.4k
        break;
225
0
    }
226
102k
    case RTX_32X16: {
227
102k
        uint64_t t = *(const uint64_t *) a & mask;
228
102k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
102k
        t = (t >> 6) * mul;
230
102k
        s = (int) (t >> 56) - 8 - 4;
231
102k
        break;
232
0
    }
233
39.5k
    case RTX_32X64: {
234
39.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
39.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
39.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
39.5k
        t *= mul;
238
39.5k
        s = (int) (t >> 56) - 8 - 16;
239
39.5k
        break;
240
0
    }
241
36.8k
    case RTX_64X32: {
242
36.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
36.8k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
36.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
36.8k
        t *= mul;
246
36.8k
        s = (int) (t >> 56) - 16 - 8;
247
36.8k
        break;
248
0
    }
249
56.2k
    case RTX_4X16: {
250
56.2k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
56.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
56.2k
        t = (t >> 6) * (uint32_t) mul;
253
56.2k
        s = (int) (t >> 24) - 1 - 4;
254
56.2k
        break;
255
0
    }
256
113k
    case RTX_16X4: {
257
113k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
113k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
113k
        t = (t >> 6) * (uint32_t) mul;
260
113k
        s = (int) (t >> 24) - 4 - 1;
261
113k
        break;
262
0
    }
263
36.4k
    case RTX_8X32: {
264
36.4k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
36.4k
        t         += *(const uint64_t *) l & mask;
266
36.4k
        t = (t >> 6) * mul;
267
36.4k
        s = (int) (t >> 56) - 2 - 8;
268
36.4k
        break;
269
0
    }
270
51.7k
    case RTX_32X8: {
271
51.7k
        uint64_t t = *(const uint64_t *) a & mask;
272
51.7k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
51.7k
        t = (t >> 6) * mul;
274
51.7k
        s = (int) (t >> 56) - 8 - 2;
275
51.7k
        break;
276
0
    }
277
11.7k
    case RTX_16X64: {
278
11.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
11.7k
        t         += *(const uint64_t *) &l[0] & mask;
280
11.7k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
11.7k
        t *= mul;
282
11.7k
        s = (int) (t >> 56) - 4 - 16;
283
11.7k
        break;
284
0
    }
285
9.24k
    case RTX_64X16: {
286
9.24k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
9.24k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
9.24k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
9.24k
        t *= mul;
290
9.24k
        s = (int) (t >> 56) - 16 - 4;
291
9.24k
        break;
292
0
    }
293
4.69M
    }
294
295
4.69M
    return (s != 0) + (s > 0);
296
4.69M
}
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
85.0M
{
305
85.0M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
85.0M
    unsigned offset;
307
85.0M
    if (tx_class == TX_CLASS_2D) {
308
80.1M
        mag += levels[1 * stride + 1];
309
80.1M
        *hi_mag = mag;
310
80.1M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
80.1M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
80.1M
    } else {
313
4.91M
        mag += levels[0 * stride + 2];
314
4.91M
        *hi_mag = mag;
315
4.91M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
4.91M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
4.91M
    }
318
85.0M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
85.0M
}
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
10.3M
{
328
10.3M
    Dav1dTileState *const ts = t->ts;
329
10.3M
    const int chroma = !!plane;
330
10.3M
    const Dav1dFrameContext *const f = t->f;
331
10.3M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
10.3M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
10.3M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
10.3M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
10.3M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
10.3M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
10.3M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
10.3M
    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
10.3M
    if (all_skip) {
346
4.91M
        *res_ctx = 0x40;
347
4.91M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
4.91M
        return -1;
349
4.91M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
5.47M
    if (lossless) {
353
1.99M
        assert(t_dim->max == TX_4X4);
354
1.99M
        *txtp = WHT_WHT;
355
3.48M
    } else if (t_dim->max + intra >= TX_64X64) {
356
997k
        *txtp = DCT_DCT;
357
2.48M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
654k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
654k
                        get_uv_inter_txtp(t_dim, *txtp);
361
1.83M
    } else if (!f->frame_hdr->segmentation.qidx[b->seg_id]) {
362
        // In libaom, lossless is checked by a literal qidx == 0, but not all
363
        // such blocks are actually lossless. The remainder gets an implicit
364
        // transform type (for luma)
365
25.9k
        *txtp = DCT_DCT;
366
1.80M
    } else {
367
1.80M
        unsigned idx;
368
1.80M
        if (intra) {
369
1.32M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
1.13M
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.32M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
598k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
598k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
598k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
724k
            } else {
376
724k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
724k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
724k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
724k
            }
380
1.32M
            if (dbg)
381
0
                printf("Post-txtp-intra[%d->%d][%d][%d->%d]: r=%d\n",
382
0
                       tx, t_dim->min, y_mode_nofilt, idx, *txtp, ts->msac.rng);
383
1.32M
        } else {
384
481k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
140k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
140k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
140k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
341k
            } else if (t_dim->min == TX_16X16) {
389
38.4k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
38.4k
                          ts->cdf.m.txtp_inter2, 11);
391
38.4k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
302k
            } else {
393
302k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
302k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
302k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
302k
            }
397
481k
            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
481k
        }
401
1.80M
    }
402
403
    // find end-of-block (eob)
404
5.47M
    int eob;
405
5.47M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
5.47M
    const int tx2dszctx = slw + slh;
407
5.47M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
5.47M
    const int is_1d = tx_class != TX_CLASS_2D;
409
5.47M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
5.47M
    case sz: { \
412
5.47M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
5.47M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
5.47M
        break; \
415
5.47M
    }
416
2.39M
    case_sz(0,   16,  8, [is_1d]);
417
408k
    case_sz(1,   32,  8, [is_1d]);
418
754k
    case_sz(2,   64,  8, [is_1d]);
419
402k
    case_sz(3,  128,  8, [is_1d]);
420
538k
    case_sz(4,  256, 16, [is_1d]);
421
217k
    case_sz(5,  512, 16,        );
422
759k
    case_sz(6, 1024, 16,        );
423
5.47M
#undef case_sz
424
5.47M
    }
425
5.46M
    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
5.46M
    if (eob > 1) {
429
3.05M
        const int eob_bin = eob - 2;
430
3.05M
        uint16_t *const eob_hi_bit_cdf =
431
3.05M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
3.05M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
3.05M
        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
3.05M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
3.05M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
3.05M
    }
440
5.46M
    assert(eob >= 0);
441
442
    // base tokens
443
5.46M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
5.46M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
5.46M
    unsigned rc, dc_tok;
446
447
5.46M
    if (eob) {
448
3.24M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
3.24M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
3.24M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
3.24M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
3.24M
        int tok = eob_tok + 1;
455
3.24M
        int level_tok = tok * 0x41;
456
3.24M
        unsigned mag;
457
458
3.24M
#define DECODE_COEFS_CLASS(tx_class) \
459
3.24M
        unsigned x, y; \
460
3.24M
        uint8_t *level; \
461
3.24M
        if (tx_class == TX_CLASS_2D) \
462
3.24M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
3.24M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
244k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
244k
        else /* tx_class == TX_CLASS_V */ \
467
244k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
3.24M
        if (dbg) \
469
3.24M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
3.24M
        if (eob_tok == 2) { \
472
76.3k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
76.3k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
76.3k
            level_tok = tok + (3 << 6); \
475
76.3k
            if (dbg) \
476
76.3k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
76.3k
        } \
480
3.24M
        cf[rc] = tok << 11; \
481
3.24M
        if (tx_class == TX_CLASS_2D) \
482
3.24M
            level = levels + rc; \
483
3.24M
        else \
484
3.24M
            level = levels + x * stride + y; \
485
3.24M
        *level = (uint8_t) level_tok; \
486
88.0M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
84.8M
            unsigned rc_i; \
488
84.8M
            if (tx_class == TX_CLASS_2D) \
489
84.8M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
84.8M
            else if (tx_class == TX_CLASS_H) \
491
4.82M
                x = i & mask, y = i >> shift, rc_i = i; \
492
4.82M
            else /* tx_class == TX_CLASS_V */ \
493
4.82M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
84.8M
            assert(x < 32 && y < 32); \
495
84.8M
            if (tx_class == TX_CLASS_2D) \
496
84.8M
                level = levels + rc_i; \
497
84.8M
            else \
498
84.8M
                level = levels + x * stride + y; \
499
84.8M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
84.8M
            if (tx_class == TX_CLASS_2D) \
501
84.8M
                y |= x; \
502
84.8M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
84.8M
            if (dbg) \
504
84.8M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
84.8M
            if (tok == 3) { \
507
6.93M
                mag &= 63; \
508
6.93M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
6.93M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
6.93M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
6.93M
                if (dbg) \
512
6.93M
                    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
6.93M
                *level = (uint8_t) (tok + (3 << 6)); \
516
6.93M
                cf[rc_i] = (tok << 11) | rc; \
517
6.93M
                rc = rc_i; \
518
77.8M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
77.8M
                tok *= 0x17ff41; \
521
77.8M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
77.8M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
77.8M
                if (tok) rc = rc_i; \
525
77.8M
                cf[rc_i] = tok; \
526
77.8M
            } \
527
84.8M
        } \
528
        /* dc */ \
529
3.24M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
3.24M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
3.24M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
3.24M
        if (dbg) \
533
3.24M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
3.24M
        if (dc_tok == 3) { \
536
1.22M
            if (tx_class == TX_CLASS_2D) \
537
1.22M
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
1.20M
                      levels[1 * stride + 1]; \
539
1.22M
            mag &= 63; \
540
1.22M
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
1.22M
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
1.22M
            if (dbg) \
543
1.22M
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n", \
544
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng); \
545
1.22M
        } \
546
3.24M
        break
547
548
3.24M
        const uint16_t *scan;
549
3.24M
        switch (tx_class) {
550
3.00M
        case TX_CLASS_2D: {
551
3.00M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
3.00M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
3.00M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
3.00M
            scan = dav1d_scans[tx];
555
3.00M
            const ptrdiff_t stride = 4 << slh;
556
3.00M
            const unsigned shift = slh + 2, shift2 = 0;
557
3.00M
            const unsigned mask = (4 << slh) - 1;
558
3.00M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
3.00M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
3.00M
        }
561
159k
        case TX_CLASS_H: {
562
159k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
159k
            const ptrdiff_t stride = 16;
564
159k
            const unsigned shift = slh + 2, shift2 = 0;
565
159k
            const unsigned mask = (4 << slh) - 1;
566
159k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
159k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
159k
        }
569
84.9k
        case TX_CLASS_V: {
570
84.9k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
84.9k
            const ptrdiff_t stride = 16;
572
84.9k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
84.9k
            const unsigned mask = (4 << slw) - 1;
574
84.9k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
84.9k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
84.9k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
3.24M
        }
580
3.24M
    } else { // dc-only
581
2.22M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
2.22M
        dc_tok = 1 + tok_br;
583
2.22M
        if (dbg)
584
0
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n",
585
0
                   t_dim->ctx, chroma, 0, dc_tok, ts->msac.rng);
586
2.22M
        if (tok_br == 2) {
587
56.8k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
56.8k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
56.8k
        }
592
2.22M
        rc = 0;
593
2.22M
    }
594
595
    // residual and sign
596
5.46M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
5.46M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
5.46M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
5.46M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
5.46M
    unsigned cul_level, dc_sign_level;
601
602
5.46M
    if (!dc_tok) {
603
779k
        cul_level = 0;
604
779k
        dc_sign_level = 1 << 6;
605
779k
        if (qm_tbl) goto ac_qm;
606
569k
        goto ac_noqm;
607
779k
    }
608
609
4.68M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
4.68M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
4.68M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
4.68M
    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
4.68M
    int dc_dq = dq_tbl[0];
617
4.68M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
4.68M
    if (qm_tbl) {
620
1.30M
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
1.30M
        if (dc_tok == 15) {
623
43.0k
            dc_tok = read_golomb(&ts->msac) + 15;
624
43.0k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
43.0k
            dc_tok &= 0xfffff;
629
43.0k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
1.26M
        } else {
631
1.26M
            dc_dq *= dc_tok;
632
1.26M
            assert(dc_dq <= 0xffffff);
633
1.26M
        }
634
1.30M
        cul_level = dc_tok;
635
1.30M
        dc_dq >>= dq_shift;
636
1.30M
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
1.30M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
1.74M
        if (rc) ac_qm: {
640
1.74M
            const unsigned ac_dq = dq_tbl[1];
641
13.9M
            do {
642
13.9M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
13.9M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
13.9M
                const unsigned rc_tok = cf[rc];
646
13.9M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
13.9M
                int dq_sat;
648
649
13.9M
                if (rc_tok >= (15 << 11)) {
650
713k
                    tok = read_golomb(&ts->msac) + 15;
651
713k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
713k
                    tok &= 0xfffff;
656
713k
                    dq = (dq * tok) & 0xffffff;
657
13.2M
                } else {
658
13.2M
                    tok = rc_tok >> 11;
659
13.2M
                    dq *= tok;
660
13.2M
                    assert(dq <= 0xffffff);
661
13.2M
                }
662
13.9M
                cul_level += tok;
663
13.9M
                dq >>= dq_shift;
664
13.9M
                dq_sat = umin(dq, cf_max + sign);
665
13.9M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
13.9M
                rc = rc_tok & 0x3ff;
668
13.9M
            } while (rc);
669
1.74M
        }
670
3.37M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
3.37M
        if (dc_tok == 15) {
673
101k
            dc_tok = read_golomb(&ts->msac) + 15;
674
101k
            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
101k
            dc_tok &= 0xfffff;
679
101k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
101k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
3.27M
        } else {
682
3.27M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
3.27M
            assert(dc_dq <= cf_max);
684
3.27M
        }
685
3.37M
        cul_level = dc_tok;
686
3.37M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
3.97M
        if (rc) ac_noqm: {
689
3.97M
            const unsigned ac_dq = dq_tbl[1];
690
19.9M
            do {
691
19.9M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
19.9M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
19.9M
                const unsigned rc_tok = cf[rc];
695
19.9M
                unsigned tok;
696
19.9M
                int dq;
697
698
                // residual
699
19.9M
                if (rc_tok >= (15 << 11)) {
700
397k
                    tok = read_golomb(&ts->msac) + 15;
701
397k
                    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
397k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
397k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
397k
                    dq = umin(dq, cf_max + sign);
711
19.5M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
19.5M
                    tok = rc_tok >> 11;
714
19.5M
                    dq = ((ac_dq * tok) >> dq_shift);
715
19.5M
                    assert(dq <= cf_max);
716
19.5M
                }
717
19.9M
                cul_level += tok;
718
19.9M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
19.9M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
19.9M
            } while (rc);
722
3.97M
        }
723
3.37M
    }
724
725
    // context
726
5.45M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
5.45M
    return eob;
729
4.68M
}
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
1.42M
{
737
1.42M
    const Dav1dFrameContext *const f = t->f;
738
1.42M
    Dav1dTileState *const ts = t->ts;
739
1.42M
    const Dav1dDSPContext *const dsp = f->dsp;
740
1.42M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
1.42M
    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
1.42M
    if (depth < 2 && tx_split[depth] &&
746
149k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
116k
    {
748
116k
        const enum RectTxfmSize sub = t_dim->sub;
749
116k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
116k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
116k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
116k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
116k
        t->bx += txsw;
755
116k
        if (txw >= txh && t->bx < f->bw)
756
85.6k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
85.6k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
116k
        t->bx -= txsw;
759
116k
        t->by += txsh;
760
116k
        if (txh >= txw && t->by < f->bh) {
761
78.9k
            if (dst)
762
21.1k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
78.9k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
78.9k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
78.9k
            t->bx += txsw;
766
78.9k
            if (txw >= txh && t->bx < f->bw)
767
49.3k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
49.3k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
78.9k
            t->bx -= txsw;
770
78.9k
        }
771
116k
        t->by -= txsh;
772
1.31M
    } else {
773
1.31M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
1.31M
        enum TxfmType txtp;
775
1.31M
        uint8_t cf_ctx;
776
1.31M
        int eob;
777
1.31M
        coef *cf;
778
779
1.31M
        if (t->frame_thread.pass) {
780
1.31M
            const int p = t->frame_thread.pass & 1;
781
1.31M
            assert(ts->frame_thread[p].cf);
782
1.31M
            cf = ts->frame_thread[p].cf;
783
1.31M
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
18.4E
        } else {
785
18.4E
            cf = bitfn(t->cf);
786
18.4E
        }
787
1.31M
        if (t->frame_thread.pass != 2) {
788
925k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
925k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
925k
            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
925k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
925k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
925k
#define set_ctx(rep_macro) \
796
3.46M
            for (int y = 0; y < txh; y++) { \
797
2.53M
                rep_macro(txtp_map, 0, txtp); \
798
2.53M
                txtp_map += 32; \
799
2.53M
            }
800
925k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
925k
            case_set_upto16(t_dim->lw);
802
925k
#undef set_ctx
803
925k
            if (t->frame_thread.pass == 1)
804
925k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
925k
        } else {
806
386k
            const int cbi = *ts->frame_thread[0].cbi++;
807
386k
            eob  = cbi >> 5;
808
386k
            txtp = cbi & 0x1f;
809
386k
        }
810
1.31M
        if (!(t->frame_thread.pass & 1)) {
811
386k
            assert(dst);
812
386k
            if (eob >= 0) {
813
253k
                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
253k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
253k
                                              HIGHBD_CALL_SUFFIX);
817
253k
                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
253k
            }
820
386k
        }
821
1.31M
    }
822
1.42M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
5.00M
{
827
5.00M
    const Dav1dFrameContext *const f = t->f;
828
5.00M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
5.00M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
5.00M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
5.00M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
5.00M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
5.00M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
5.00M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
5.00M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
4.49M
                           (bw4 > ss_hor || t->bx & 1) &&
837
4.17M
                           (bh4 > ss_ver || t->by & 1);
838
839
5.00M
    if (b->skip) {
840
2.98M
        BlockContext *const a = t->a;
841
2.98M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
2.98M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
2.98M
        if (has_chroma) {
844
2.26M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
2.26M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
2.26M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
2.26M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
2.26M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
2.26M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
2.26M
        }
851
2.98M
        return;
852
2.98M
    }
853
854
2.01M
    Dav1dTileState *const ts = t->ts;
855
2.01M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
2.01M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
2.01M
    assert(t->frame_thread.pass == 1);
858
2.01M
    assert(!b->skip);
859
2.01M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
2.01M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
2.01M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
4.10M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
2.08M
        const int sub_h4 = imin(h4, 16 + init_y);
865
4.28M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
2.19M
            const int sub_w4 = imin(w4, init_x + 16);
867
2.19M
            int y_off = !!init_y, y, x;
868
4.83M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
2.63M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
2.63M
            {
871
2.63M
                int x_off = !!init_x;
872
7.58M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
4.95M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
4.95M
                {
875
4.95M
                    if (!b->intra) {
876
764k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
764k
                                       x_off, y_off, NULL);
878
4.18M
                    } else {
879
4.18M
                        uint8_t cf_ctx = 0x40;
880
4.18M
                        enum TxfmType txtp;
881
4.18M
                        const int eob =
882
4.18M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
4.18M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
4.18M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
4.18M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
4.18M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
4.18M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
4.18M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
4.18M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
4.18M
                    }
893
4.95M
                }
894
2.63M
                t->bx -= x;
895
2.63M
            }
896
2.19M
            t->by -= y;
897
898
2.19M
            if (!has_chroma) continue;
899
900
1.79M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.79M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
5.37M
            for (int pl = 0; pl < 2; pl++) {
903
7.60M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
4.01M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
4.01M
                {
906
9.31M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
5.29M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
5.29M
                    {
909
5.29M
                        uint8_t cf_ctx = 0x40;
910
5.29M
                        enum TxfmType txtp;
911
5.29M
                        if (!b->intra)
912
1.07M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.07M
                                                        bx4 + (x << ss_hor)];
914
5.29M
                        const int eob =
915
5.29M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
5.29M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
5.29M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
5.29M
                                         &txtp, &cf_ctx);
919
5.29M
                        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
5.29M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
5.29M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
5.29M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
5.29M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
5.29M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
5.29M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
5.29M
                    }
930
4.01M
                    t->bx -= x << ss_hor;
931
4.01M
                }
932
3.58M
                t->by -= y << ss_ver;
933
3.58M
            }
934
1.79M
        }
935
2.08M
    }
936
2.01M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
2.48M
{
827
2.48M
    const Dav1dFrameContext *const f = t->f;
828
2.48M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.48M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.48M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.48M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.48M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.48M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.48M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.48M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.26M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.09M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.48M
    if (b->skip) {
840
1.54M
        BlockContext *const a = t->a;
841
1.54M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.54M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.54M
        if (has_chroma) {
844
1.18M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.18M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.18M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.18M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.18M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.18M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.18M
        }
851
1.54M
        return;
852
1.54M
    }
853
854
948k
    Dav1dTileState *const ts = t->ts;
855
948k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
948k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
948k
    assert(t->frame_thread.pass == 1);
858
948k
    assert(!b->skip);
859
948k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
948k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
948k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.92M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
980k
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.00M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.02M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.02M
            int y_off = !!init_y, y, x;
868
2.25M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.23M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.23M
            {
871
1.23M
                int x_off = !!init_x;
872
3.62M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.39M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.39M
                {
875
2.39M
                    if (!b->intra) {
876
445k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
445k
                                       x_off, y_off, NULL);
878
1.95M
                    } else {
879
1.95M
                        uint8_t cf_ctx = 0x40;
880
1.95M
                        enum TxfmType txtp;
881
1.95M
                        const int eob =
882
1.95M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.95M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.95M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.95M
                        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.95M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.95M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.95M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.95M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.95M
                    }
893
2.39M
                }
894
1.23M
                t->bx -= x;
895
1.23M
            }
896
1.02M
            t->by -= y;
897
898
1.02M
            if (!has_chroma) continue;
899
900
833k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
833k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.50M
            for (int pl = 0; pl < 2; pl++) {
903
3.51M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.85M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.85M
                {
906
4.23M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.38M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.38M
                    {
909
2.38M
                        uint8_t cf_ctx = 0x40;
910
2.38M
                        enum TxfmType txtp;
911
2.38M
                        if (!b->intra)
912
584k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
584k
                                                        bx4 + (x << ss_hor)];
914
2.38M
                        const int eob =
915
2.38M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.38M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.38M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.38M
                                         &txtp, &cf_ctx);
919
2.38M
                        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.38M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.38M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.38M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.38M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.38M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.38M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.38M
                    }
930
1.85M
                    t->bx -= x << ss_hor;
931
1.85M
                }
932
1.66M
                t->by -= y << ss_ver;
933
1.66M
            }
934
833k
        }
935
980k
    }
936
948k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
2.51M
{
827
2.51M
    const Dav1dFrameContext *const f = t->f;
828
2.51M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.51M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.51M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.51M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.51M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.51M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.51M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.51M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.23M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.08M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.51M
    if (b->skip) {
840
1.44M
        BlockContext *const a = t->a;
841
1.44M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.44M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.44M
        if (has_chroma) {
844
1.07M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.07M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.07M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.07M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.07M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.07M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.07M
        }
851
1.44M
        return;
852
1.44M
    }
853
854
1.06M
    Dav1dTileState *const ts = t->ts;
855
1.06M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.06M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.06M
    assert(t->frame_thread.pass == 1);
858
1.06M
    assert(!b->skip);
859
1.06M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.06M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.06M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.17M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.10M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.27M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.16M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.16M
            int y_off = !!init_y, y, x;
868
2.57M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.40M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.40M
            {
871
1.40M
                int x_off = !!init_x;
872
3.95M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.55M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.55M
                {
875
2.55M
                    if (!b->intra) {
876
319k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
319k
                                       x_off, y_off, NULL);
878
2.23M
                    } else {
879
2.23M
                        uint8_t cf_ctx = 0x40;
880
2.23M
                        enum TxfmType txtp;
881
2.23M
                        const int eob =
882
2.23M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.23M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.23M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.23M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
2.23M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.23M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.23M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.23M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.23M
                    }
893
2.55M
                }
894
1.40M
                t->bx -= x;
895
1.40M
            }
896
1.16M
            t->by -= y;
897
898
1.16M
            if (!has_chroma) continue;
899
900
960k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
960k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.87M
            for (int pl = 0; pl < 2; pl++) {
903
4.08M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.16M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.16M
                {
906
5.07M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.91M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.91M
                    {
909
2.91M
                        uint8_t cf_ctx = 0x40;
910
2.91M
                        enum TxfmType txtp;
911
2.91M
                        if (!b->intra)
912
491k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
491k
                                                        bx4 + (x << ss_hor)];
914
2.91M
                        const int eob =
915
2.91M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.91M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.91M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.91M
                                         &txtp, &cf_ctx);
919
2.91M
                        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.91M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.91M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.91M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.91M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.91M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.91M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.91M
                    }
930
2.16M
                    t->bx -= x << ss_hor;
931
2.16M
                }
932
1.91M
                t->by -= y << ss_ver;
933
1.91M
            }
934
960k
        }
935
1.10M
    }
936
1.06M
}
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.30M
{
945
1.30M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.30M
    const Dav1dFrameContext *const f = t->f;
947
1.30M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.30M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.30M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.30M
    const int mvx = mv.x, mvy = mv.y;
951
1.30M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.30M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.30M
    const pixel *ref;
954
955
1.30M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
902k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
902k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
902k
        int w, h;
959
960
902k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
604k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
604k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
604k
        } else {
964
297k
            w = f->bw * 4 >> ss_hor;
965
297k
            h = f->bh * 4 >> ss_ver;
966
297k
        }
967
902k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
722k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
522k
            dy + bh4 * v_mul + !!my * 4 > h)
970
467k
        {
971
467k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
467k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
467k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
467k
                                emu_edge_buf, 192 * sizeof(pixel),
975
467k
                                refp->p.data[pl], ref_stride);
976
467k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
467k
            ref_stride = 192 * sizeof(pixel);
978
467k
        } else {
979
434k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
434k
        }
981
982
902k
        if (dst8 != NULL) {
983
765k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
765k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
765k
                                     HIGHBD_CALL_SUFFIX);
986
765k
        } else {
987
137k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
137k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
137k
                                      HIGHBD_CALL_SUFFIX);
990
137k
        }
991
902k
    } else {
992
399k
        assert(refp != &f->sr_cur);
993
994
399k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
399k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
799k
#define scale_mv(res, val, scale) do { \
997
799k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
799k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
799k
        } while (0)
1000
399k
        int pos_y, pos_x;
1001
399k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
399k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
399k
#undef scale_mv
1004
399k
        const int left = pos_x >> 10;
1005
399k
        const int top = pos_y >> 10;
1006
399k
        const int right =
1007
399k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
399k
        const int bottom =
1009
399k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
399k
        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
399k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
399k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
399k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
341k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
341k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
341k
                                w, h, left - 3, top - 3,
1023
341k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
341k
                                refp->p.data[pl], ref_stride);
1025
341k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
341k
            ref_stride = 320 * sizeof(pixel);
1027
341k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
341k
        } else {
1029
57.9k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
57.9k
        }
1031
1032
399k
        if (dst8 != NULL) {
1033
298k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
298k
                                            bw4 * h_mul, bh4 * v_mul,
1035
298k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
298k
                                            f->svc[refidx][0].step,
1037
298k
                                            f->svc[refidx][1].step
1038
298k
                                            HIGHBD_CALL_SUFFIX);
1039
298k
        } else {
1040
101k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
101k
                                             bw4 * h_mul, bh4 * v_mul,
1042
101k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
101k
                                             f->svc[refidx][0].step,
1044
101k
                                             f->svc[refidx][1].step
1045
101k
                                             HIGHBD_CALL_SUFFIX);
1046
101k
        }
1047
399k
    }
1048
1049
1.30M
    return 0;
1050
1.30M
}
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
97.9k
{
1057
97.9k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
97.9k
    const Dav1dFrameContext *const f = t->f;
1059
97.9k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
97.9k
    pixel *const lap = bitfn(t->scratch.lap);
1061
97.9k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
97.9k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
97.9k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
97.9k
    int res;
1065
1066
97.9k
    if (t->by > t->ts->tiling.row_start &&
1067
82.8k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
66.0k
    {
1069
139k
        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
73.2k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
73.2k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
73.2k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
73.2k
            if (a_r->ref.ref[0] > 0) {
1076
72.5k
                const int ow4 = imin(step4, b_dim[0]);
1077
72.5k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
72.5k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
72.5k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
72.5k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
72.5k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
72.5k
                if (res) return res;
1083
72.5k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
72.5k
                                   h_mul * ow4, v_mul * oh4);
1085
72.5k
                i++;
1086
72.5k
            }
1087
73.2k
            x += step4;
1088
73.2k
        }
1089
66.0k
    }
1090
1091
97.9k
    if (t->bx > t->ts->tiling.col_start)
1092
156k
        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
81.0k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
81.0k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
81.0k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
81.0k
            if (l_r->ref.ref[0] > 0) {
1099
80.0k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
80.0k
                const int oh4 = imin(step4, b_dim[1]);
1101
80.0k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
80.0k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
80.0k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
80.0k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
80.0k
                if (res) return res;
1106
80.0k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
80.0k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
80.0k
                i++;
1109
80.0k
            }
1110
81.0k
            y += step4;
1111
81.0k
        }
1112
97.9k
    return 0;
1113
97.9k
}
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
39.3k
{
1121
39.3k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
39.3k
    const Dav1dFrameContext *const f = t->f;
1123
39.3k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
39.3k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
39.3k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
39.3k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
39.3k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
39.3k
    const int32_t *const mat = wmp->matrix;
1129
39.3k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
39.3k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
129k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
90.4k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
90.4k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
90.4k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
429k
        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
338k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
338k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
338k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
338k
            const int dx = (int) (mvx >> 16) - 4;
1144
338k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
338k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
338k
            const int dy = (int) (mvy >> 16) - 4;
1147
338k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
338k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
338k
            const pixel *ref_ptr;
1151
338k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
338k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
231k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
231k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
231k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
231k
                                    refp->p.data[pl], ref_stride);
1158
231k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
231k
                ref_stride = 32 * sizeof(pixel);
1160
231k
            } else {
1161
107k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
107k
            }
1163
338k
            if (dst16 != NULL)
1164
47.8k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
47.8k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
290k
            else
1167
290k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
290k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
338k
        }
1170
90.4k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
15.9k
        else      dst16 += 8 * dstride;
1172
90.4k
    }
1173
39.3k
    return 0;
1174
39.3k
}
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
1.81M
{
1180
1.81M
    Dav1dTileState *const ts = t->ts;
1181
1.81M
    const Dav1dFrameContext *const f = t->f;
1182
1.81M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.81M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.81M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.81M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.81M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.81M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.81M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.81M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.81M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.81M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.62M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.52M
                           (bh4 > ss_ver || t->by & 1);
1194
1.81M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.81M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.81M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.81M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.81M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
3.73M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.90M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.90M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.95M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
2.04M
            if (b->pal_sz[0]) {
1208
9.04k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
9.04k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
9.04k
                const uint8_t *pal_idx;
1211
9.04k
                if (t->frame_thread.pass) {
1212
9.04k
                    const int p = t->frame_thread.pass & 1;
1213
9.04k
                    assert(ts->frame_thread[p].pal_idx);
1214
9.04k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
9.04k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
9.04k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
9.04k
                const pixel *const pal = t->frame_thread.pass ?
1220
9.04k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
9.04k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
9.04k
                    bytefn(t->scratch.pal)[0];
1223
9.04k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
9.04k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
9.04k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
9.04k
            }
1229
1230
2.04M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
2.04M
                                     sm_flag(&t->l, by4) |
1232
2.04M
                                     intra_edge_filter_flag);
1233
2.04M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.90M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
2.04M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.90M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
2.04M
            int y, x;
1238
2.04M
            const int sub_w4 = imin(w4, init_x + 16);
1239
4.72M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
2.68M
                 y += t_dim->h, t->by += t_dim->h)
1241
2.68M
            {
1242
2.68M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
2.68M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
2.68M
                                    t->bx + init_x);
1245
9.04M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
6.35M
                     x += t_dim->w, t->bx += t_dim->w)
1247
6.35M
                {
1248
6.35M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
6.34M
                    int angle = b->y_angle;
1251
6.34M
                    const enum EdgeFlags edge_flags =
1252
6.34M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
5.10M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
6.34M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
4.80M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
6.34M
                    const pixel *top_sb_edge = NULL;
1257
6.34M
                    if (!(t->by & (f->sb_step - 1))) {
1258
1.01M
                        top_sb_edge = f->ipred_edge[0];
1259
1.01M
                        const int sby = t->by >> f->sb_shift;
1260
1.01M
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
1.01M
                    }
1262
6.34M
                    const enum IntraPredMode m =
1263
6.34M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
6.34M
                                                          t->bx > ts->tiling.col_start,
1265
6.34M
                                                          t->by,
1266
6.34M
                                                          t->by > ts->tiling.row_start,
1267
6.34M
                                                          ts->tiling.col_end,
1268
6.34M
                                                          ts->tiling.row_end,
1269
6.34M
                                                          edge_flags, dst,
1270
6.34M
                                                          f->cur.stride[0], top_sb_edge,
1271
6.34M
                                                          b->y_mode, &angle,
1272
6.34M
                                                          t_dim->w, t_dim->h,
1273
6.34M
                                                          f->seq_hdr->intra_edge_filter,
1274
6.34M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
6.34M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
6.34M
                                             t_dim->w * 4, t_dim->h * 4,
1277
6.34M
                                             angle | intra_flags,
1278
6.34M
                                             4 * f->bw - 4 * t->bx,
1279
6.34M
                                             4 * f->bh - 4 * t->by
1280
6.34M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
6.34M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
6.35M
                skip_y_pred: {}
1293
6.35M
                    if (!b->skip) {
1294
1.89M
                        coef *cf;
1295
1.89M
                        int eob;
1296
1.89M
                        enum TxfmType txtp;
1297
1.89M
                        if (t->frame_thread.pass) {
1298
1.89M
                            const int p = t->frame_thread.pass & 1;
1299
1.89M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.89M
                            cf = ts->frame_thread[p].cf;
1301
1.89M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.89M
                            eob  = cbi >> 5;
1303
1.89M
                            txtp = cbi & 0x1f;
1304
1.89M
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
1.89M
                        if (eob >= 0) {
1317
1.46M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
1.46M
                            dsp->itx.itxfm_add[b->tx]
1321
1.46M
                                              [txtp](dst,
1322
1.46M
                                                     f->cur.stride[0],
1323
1.46M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.46M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
1.46M
                        }
1328
4.46M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
6.35M
                    dst += 4 * t_dim->w;
1333
6.35M
                }
1334
2.68M
                t->bx -= x;
1335
2.68M
            }
1336
2.04M
            t->by -= y;
1337
1338
2.04M
            if (!has_chroma) continue;
1339
1340
1.59M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.59M
            if (b->uv_mode == CFL_PRED) {
1343
297k
                assert(!init_x && !init_y);
1344
1345
297k
                int16_t *const ac = t->scratch.ac;
1346
297k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
297k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
297k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
297k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
297k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
297k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
297k
                const int furthest_r =
1354
297k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
297k
                const int furthest_b =
1356
297k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
297k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
297k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
297k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
297k
                                                         cbw4 * 4, cbh4 * 4);
1361
893k
                for (int pl = 0; pl < 2; pl++) {
1362
595k
                    if (!b->cfl_alpha[pl]) continue;
1363
490k
                    int angle = 0;
1364
490k
                    const pixel *top_sb_edge = NULL;
1365
490k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
129k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
129k
                        const int sby = t->by >> f->sb_shift;
1368
129k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
129k
                    }
1370
490k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
490k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
490k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
490k
                    const enum IntraPredMode m =
1374
490k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
490k
                                                          ypos, ypos > ystart,
1376
490k
                                                          ts->tiling.col_end >> ss_hor,
1377
490k
                                                          ts->tiling.row_end >> ss_ver,
1378
490k
                                                          0, uv_dst[pl], stride,
1379
490k
                                                          top_sb_edge, DC_PRED, &angle,
1380
490k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
490k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
490k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
490k
                                           uv_t_dim->w * 4,
1384
490k
                                           uv_t_dim->h * 4,
1385
490k
                                           ac, b->cfl_alpha[pl]
1386
490k
                                           HIGHBD_CALL_SUFFIX);
1387
490k
                }
1388
297k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
1.29M
            } else if (b->pal_sz[1]) {
1394
3.93k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.93k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.93k
                const pixel (*pal)[8];
1397
3.93k
                const uint8_t *pal_idx;
1398
3.93k
                if (t->frame_thread.pass) {
1399
3.93k
                    const int p = t->frame_thread.pass & 1;
1400
3.93k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.93k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.93k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.93k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.93k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.93k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.93k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.93k
                                       f->cur.stride[1], pal[1],
1412
3.93k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.93k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.93k
                                       f->cur.stride[1], pal[2],
1415
3.93k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.93k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
3.93k
            }
1425
1426
1.59M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.59M
                                 sm_uv_flag(&t->l, cby4);
1428
1.59M
            const int uv_sb_has_tr =
1429
1.59M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.49M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.59M
            const int uv_sb_has_bl =
1432
1.59M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.49M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.59M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
4.77M
            for (int pl = 0; pl < 2; pl++) {
1436
6.85M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
3.67M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
3.67M
                {
1439
3.67M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
3.67M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
3.67M
                                        ((t->bx + init_x) >> ss_hor));
1442
8.90M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
5.23M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
5.23M
                    {
1445
5.23M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
4.74M
                            b->pal_sz[1])
1447
499k
                        {
1448
499k
                            goto skip_uv_pred;
1449
499k
                        }
1450
1451
4.73M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
4.73M
                        const enum EdgeFlags edge_flags =
1456
4.73M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
2.50M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
3.49M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
4.73M
                            ((x > (init_x >> ss_hor) ||
1460
3.17M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
3.09M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
4.73M
                        const pixel *top_sb_edge = NULL;
1463
4.73M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
1.28M
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
1.28M
                            const int sby = t->by >> f->sb_shift;
1466
1.28M
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
1.28M
                        }
1468
4.73M
                        const enum IntraPredMode uv_mode =
1469
4.73M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
4.73M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
4.73M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
4.73M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
4.73M
                        const enum IntraPredMode m =
1474
4.73M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
4.73M
                                                              ypos, ypos > ystart,
1476
4.73M
                                                              ts->tiling.col_end >> ss_hor,
1477
4.73M
                                                              ts->tiling.row_end >> ss_ver,
1478
4.73M
                                                              edge_flags, dst, stride,
1479
4.73M
                                                              top_sb_edge, uv_mode,
1480
4.73M
                                                              &angle, uv_t_dim->w,
1481
4.73M
                                                              uv_t_dim->h,
1482
4.73M
                                                              f->seq_hdr->intra_edge_filter,
1483
4.73M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
4.73M
                        angle |= intra_edge_filter_flag;
1485
4.73M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
4.73M
                                                 uv_t_dim->w * 4,
1487
4.73M
                                                 uv_t_dim->h * 4,
1488
4.73M
                                                 angle | sm_uv_fl,
1489
4.73M
                                                 (4 * f->bw + ss_hor -
1490
4.73M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
4.73M
                                                 (4 * f->bh + ss_ver -
1492
4.73M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
4.73M
                                                 HIGHBD_CALL_SUFFIX);
1494
4.73M
                        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
5.23M
                    skip_uv_pred: {}
1505
5.23M
                        if (!b->skip) {
1506
1.57M
                            enum TxfmType txtp;
1507
1.57M
                            int eob;
1508
1.57M
                            coef *cf;
1509
1.57M
                            if (t->frame_thread.pass) {
1510
1.57M
                                const int p = t->frame_thread.pass & 1;
1511
1.57M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.57M
                                cf = ts->frame_thread[p].cf;
1513
1.57M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.57M
                                eob  = cbi >> 5;
1515
1.57M
                                txtp = cbi & 0x1f;
1516
1.57M
                            } 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
1.57M
                            if (eob >= 0) {
1533
525k
                                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
525k
                                dsp->itx.itxfm_add[b->uvtx]
1537
525k
                                                  [txtp](dst, stride,
1538
525k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
525k
                                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
525k
                            }
1543
3.66M
                        } 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
5.23M
                        dst += uv_t_dim->w * 4;
1548
5.23M
                    }
1549
3.67M
                    t->bx -= x << ss_hor;
1550
3.67M
                }
1551
3.18M
                t->by -= y << ss_ver;
1552
3.18M
            }
1553
1.59M
        }
1554
1.90M
    }
1555
1.81M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
817k
{
1180
817k
    Dav1dTileState *const ts = t->ts;
1181
817k
    const Dav1dFrameContext *const f = t->f;
1182
817k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
817k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
817k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
817k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
817k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
817k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
817k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
817k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
817k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
817k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
752k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
703k
                           (bh4 > ss_ver || t->by & 1);
1194
817k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
817k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
817k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
817k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
817k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.67M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
856k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
856k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.77M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
912k
            if (b->pal_sz[0]) {
1208
4.81k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.81k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.81k
                const uint8_t *pal_idx;
1211
4.81k
                if (t->frame_thread.pass) {
1212
4.81k
                    const int p = t->frame_thread.pass & 1;
1213
4.81k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.81k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.81k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.81k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.81k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.81k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.81k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.81k
                    bytefn(t->scratch.pal)[0];
1223
4.81k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.81k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.81k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.81k
            }
1229
1230
912k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
912k
                                     sm_flag(&t->l, by4) |
1232
912k
                                     intra_edge_filter_flag);
1233
912k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
856k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
912k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
856k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
912k
            int y, x;
1238
912k
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.06M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.15M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.15M
            {
1242
1.15M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.15M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.15M
                                    t->bx + init_x);
1245
3.39M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.24M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.23M
                {
1248
2.23M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.23M
                    int angle = b->y_angle;
1251
2.23M
                    const enum EdgeFlags edge_flags =
1252
2.23M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.74M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.23M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.59M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.23M
                    const pixel *top_sb_edge = NULL;
1257
2.23M
                    if (!(t->by & (f->sb_step - 1))) {
1258
457k
                        top_sb_edge = f->ipred_edge[0];
1259
457k
                        const int sby = t->by >> f->sb_shift;
1260
457k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
457k
                    }
1262
2.23M
                    const enum IntraPredMode m =
1263
2.23M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.23M
                                                          t->bx > ts->tiling.col_start,
1265
2.23M
                                                          t->by,
1266
2.23M
                                                          t->by > ts->tiling.row_start,
1267
2.23M
                                                          ts->tiling.col_end,
1268
2.23M
                                                          ts->tiling.row_end,
1269
2.23M
                                                          edge_flags, dst,
1270
2.23M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.23M
                                                          b->y_mode, &angle,
1272
2.23M
                                                          t_dim->w, t_dim->h,
1273
2.23M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.23M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.23M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.23M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.23M
                                             angle | intra_flags,
1278
2.23M
                                             4 * f->bw - 4 * t->bx,
1279
2.23M
                                             4 * f->bh - 4 * t->by
1280
2.23M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.23M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.24M
                skip_y_pred: {}
1293
2.24M
                    if (!b->skip) {
1294
877k
                        coef *cf;
1295
877k
                        int eob;
1296
877k
                        enum TxfmType txtp;
1297
877k
                        if (t->frame_thread.pass) {
1298
877k
                            const int p = t->frame_thread.pass & 1;
1299
877k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
877k
                            cf = ts->frame_thread[p].cf;
1301
877k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
877k
                            eob  = cbi >> 5;
1303
877k
                            txtp = cbi & 0x1f;
1304
877k
                        } 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
877k
                        if (eob >= 0) {
1317
702k
                            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
702k
                            dsp->itx.itxfm_add[b->tx]
1321
702k
                                              [txtp](dst,
1322
702k
                                                     f->cur.stride[0],
1323
702k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
702k
                            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
702k
                        }
1328
1.36M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.24M
                    dst += 4 * t_dim->w;
1333
2.24M
                }
1334
1.15M
                t->bx -= x;
1335
1.15M
            }
1336
914k
            t->by -= y;
1337
1338
914k
            if (!has_chroma) continue;
1339
1340
739k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
739k
            if (b->uv_mode == CFL_PRED) {
1343
140k
                assert(!init_x && !init_y);
1344
1345
140k
                int16_t *const ac = t->scratch.ac;
1346
140k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
140k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
140k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
140k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
140k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
140k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
140k
                const int furthest_r =
1354
140k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
140k
                const int furthest_b =
1356
140k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
140k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
140k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
140k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
140k
                                                         cbw4 * 4, cbh4 * 4);
1361
420k
                for (int pl = 0; pl < 2; pl++) {
1362
280k
                    if (!b->cfl_alpha[pl]) continue;
1363
233k
                    int angle = 0;
1364
233k
                    const pixel *top_sb_edge = NULL;
1365
233k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
64.2k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
64.2k
                        const int sby = t->by >> f->sb_shift;
1368
64.2k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
64.2k
                    }
1370
233k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
233k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
233k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
233k
                    const enum IntraPredMode m =
1374
233k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
233k
                                                          ypos, ypos > ystart,
1376
233k
                                                          ts->tiling.col_end >> ss_hor,
1377
233k
                                                          ts->tiling.row_end >> ss_ver,
1378
233k
                                                          0, uv_dst[pl], stride,
1379
233k
                                                          top_sb_edge, DC_PRED, &angle,
1380
233k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
233k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
233k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
233k
                                           uv_t_dim->w * 4,
1384
233k
                                           uv_t_dim->h * 4,
1385
233k
                                           ac, b->cfl_alpha[pl]
1386
233k
                                           HIGHBD_CALL_SUFFIX);
1387
233k
                }
1388
140k
                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
599k
            } else if (b->pal_sz[1]) {
1394
2.52k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.52k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.52k
                const pixel (*pal)[8];
1397
2.52k
                const uint8_t *pal_idx;
1398
2.52k
                if (t->frame_thread.pass) {
1399
2.52k
                    const int p = t->frame_thread.pass & 1;
1400
2.52k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.52k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.52k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.52k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.52k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.52k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.52k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.52k
                                       f->cur.stride[1], pal[1],
1412
2.52k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.52k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.52k
                                       f->cur.stride[1], pal[2],
1415
2.52k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.52k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.52k
            }
1425
1426
739k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
739k
                                 sm_uv_flag(&t->l, cby4);
1428
739k
            const int uv_sb_has_tr =
1429
739k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
692k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
739k
            const int uv_sb_has_bl =
1432
739k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
692k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
739k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.21M
            for (int pl = 0; pl < 2; pl++) {
1436
3.19M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.71M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.71M
                {
1439
1.71M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.71M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.71M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.14M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.43M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.42M
                    {
1445
2.42M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.19M
                            b->pal_sz[1])
1447
238k
                        {
1448
238k
                            goto skip_uv_pred;
1449
238k
                        }
1450
1451
2.19M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.19M
                        const enum EdgeFlags edge_flags =
1456
2.19M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.13M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.62M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.19M
                            ((x > (init_x >> ss_hor) ||
1460
1.47M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.42M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.19M
                        const pixel *top_sb_edge = NULL;
1463
2.19M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
630k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
630k
                            const int sby = t->by >> f->sb_shift;
1466
630k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
630k
                        }
1468
2.19M
                        const enum IntraPredMode uv_mode =
1469
2.19M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.19M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.19M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.19M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.19M
                        const enum IntraPredMode m =
1474
2.19M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.19M
                                                              ypos, ypos > ystart,
1476
2.19M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.19M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.19M
                                                              edge_flags, dst, stride,
1479
2.19M
                                                              top_sb_edge, uv_mode,
1480
2.19M
                                                              &angle, uv_t_dim->w,
1481
2.19M
                                                              uv_t_dim->h,
1482
2.19M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.19M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.19M
                        angle |= intra_edge_filter_flag;
1485
2.19M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.19M
                                                 uv_t_dim->w * 4,
1487
2.19M
                                                 uv_t_dim->h * 4,
1488
2.19M
                                                 angle | sm_uv_fl,
1489
2.19M
                                                 (4 * f->bw + ss_hor -
1490
2.19M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.19M
                                                 (4 * f->bh + ss_ver -
1492
2.19M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.19M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.19M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.43M
                    skip_uv_pred: {}
1505
2.43M
                        if (!b->skip) {
1506
665k
                            enum TxfmType txtp;
1507
665k
                            int eob;
1508
665k
                            coef *cf;
1509
665k
                            if (t->frame_thread.pass) {
1510
665k
                                const int p = t->frame_thread.pass & 1;
1511
665k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
665k
                                cf = ts->frame_thread[p].cf;
1513
665k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
665k
                                eob  = cbi >> 5;
1515
665k
                                txtp = cbi & 0x1f;
1516
665k
                            } 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
665k
                            if (eob >= 0) {
1533
268k
                                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
268k
                                dsp->itx.itxfm_add[b->uvtx]
1537
268k
                                                  [txtp](dst, stride,
1538
268k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
268k
                                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
268k
                            }
1543
1.76M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.43M
                        dst += uv_t_dim->w * 4;
1548
2.43M
                    }
1549
1.71M
                    t->bx -= x << ss_hor;
1550
1.71M
                }
1551
1.47M
                t->by -= y << ss_ver;
1552
1.47M
            }
1553
739k
        }
1554
856k
    }
1555
817k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
1.00M
{
1180
1.00M
    Dav1dTileState *const ts = t->ts;
1181
1.00M
    const Dav1dFrameContext *const f = t->f;
1182
1.00M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.00M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.00M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.00M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.00M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.00M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.00M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.00M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.00M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.00M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
872k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
819k
                           (bh4 > ss_ver || t->by & 1);
1194
1.00M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.00M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.00M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.00M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.00M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.05M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.05M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.05M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.18M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.12M
            if (b->pal_sz[0]) {
1208
4.22k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.22k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.22k
                const uint8_t *pal_idx;
1211
4.22k
                if (t->frame_thread.pass) {
1212
4.22k
                    const int p = t->frame_thread.pass & 1;
1213
4.22k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.22k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.22k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.22k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.22k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.22k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.22k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.22k
                    bytefn(t->scratch.pal)[0];
1223
4.22k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.22k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.22k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.22k
            }
1229
1230
1.12M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.12M
                                     sm_flag(&t->l, by4) |
1232
1.12M
                                     intra_edge_filter_flag);
1233
1.12M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.05M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.12M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.05M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.12M
            int y, x;
1238
1.12M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.66M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.53M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.53M
            {
1242
1.53M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.53M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.53M
                                    t->bx + init_x);
1245
5.65M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
4.11M
                     x += t_dim->w, t->bx += t_dim->w)
1247
4.11M
                {
1248
4.11M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
4.10M
                    int angle = b->y_angle;
1251
4.10M
                    const enum EdgeFlags edge_flags =
1252
4.10M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
3.35M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
4.10M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
3.20M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
4.10M
                    const pixel *top_sb_edge = NULL;
1257
4.10M
                    if (!(t->by & (f->sb_step - 1))) {
1258
559k
                        top_sb_edge = f->ipred_edge[0];
1259
559k
                        const int sby = t->by >> f->sb_shift;
1260
559k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
559k
                    }
1262
4.10M
                    const enum IntraPredMode m =
1263
4.10M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
4.10M
                                                          t->bx > ts->tiling.col_start,
1265
4.10M
                                                          t->by,
1266
4.10M
                                                          t->by > ts->tiling.row_start,
1267
4.10M
                                                          ts->tiling.col_end,
1268
4.10M
                                                          ts->tiling.row_end,
1269
4.10M
                                                          edge_flags, dst,
1270
4.10M
                                                          f->cur.stride[0], top_sb_edge,
1271
4.10M
                                                          b->y_mode, &angle,
1272
4.10M
                                                          t_dim->w, t_dim->h,
1273
4.10M
                                                          f->seq_hdr->intra_edge_filter,
1274
4.10M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
4.10M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
4.10M
                                             t_dim->w * 4, t_dim->h * 4,
1277
4.10M
                                             angle | intra_flags,
1278
4.10M
                                             4 * f->bw - 4 * t->bx,
1279
4.10M
                                             4 * f->bh - 4 * t->by
1280
4.10M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
4.10M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
4.11M
                skip_y_pred: {}
1293
4.11M
                    if (!b->skip) {
1294
1.01M
                        coef *cf;
1295
1.01M
                        int eob;
1296
1.01M
                        enum TxfmType txtp;
1297
1.01M
                        if (t->frame_thread.pass) {
1298
1.01M
                            const int p = t->frame_thread.pass & 1;
1299
1.01M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.01M
                            cf = ts->frame_thread[p].cf;
1301
1.01M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.01M
                            eob  = cbi >> 5;
1303
1.01M
                            txtp = cbi & 0x1f;
1304
1.01M
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
1.01M
                        if (eob >= 0) {
1317
763k
                            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
763k
                            dsp->itx.itxfm_add[b->tx]
1321
763k
                                              [txtp](dst,
1322
763k
                                                     f->cur.stride[0],
1323
763k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
763k
                            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
763k
                        }
1328
3.10M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
4.11M
                    dst += 4 * t_dim->w;
1333
4.11M
                }
1334
1.53M
                t->bx -= x;
1335
1.53M
            }
1336
1.12M
            t->by -= y;
1337
1338
1.12M
            if (!has_chroma) continue;
1339
1340
854k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
854k
            if (b->uv_mode == CFL_PRED) {
1343
157k
                assert(!init_x && !init_y);
1344
1345
157k
                int16_t *const ac = t->scratch.ac;
1346
157k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
157k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
157k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
157k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
157k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
157k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
157k
                const int furthest_r =
1354
157k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
157k
                const int furthest_b =
1356
157k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
157k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
157k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
157k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
157k
                                                         cbw4 * 4, cbh4 * 4);
1361
472k
                for (int pl = 0; pl < 2; pl++) {
1362
314k
                    if (!b->cfl_alpha[pl]) continue;
1363
257k
                    int angle = 0;
1364
257k
                    const pixel *top_sb_edge = NULL;
1365
257k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
65.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
65.7k
                        const int sby = t->by >> f->sb_shift;
1368
65.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
65.7k
                    }
1370
257k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
257k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
257k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
257k
                    const enum IntraPredMode m =
1374
257k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
257k
                                                          ypos, ypos > ystart,
1376
257k
                                                          ts->tiling.col_end >> ss_hor,
1377
257k
                                                          ts->tiling.row_end >> ss_ver,
1378
257k
                                                          0, uv_dst[pl], stride,
1379
257k
                                                          top_sb_edge, DC_PRED, &angle,
1380
257k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
257k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
257k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
257k
                                           uv_t_dim->w * 4,
1384
257k
                                           uv_t_dim->h * 4,
1385
257k
                                           ac, b->cfl_alpha[pl]
1386
257k
                                           HIGHBD_CALL_SUFFIX);
1387
257k
                }
1388
157k
                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
696k
            } else if (b->pal_sz[1]) {
1394
1.40k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.40k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.40k
                const pixel (*pal)[8];
1397
1.40k
                const uint8_t *pal_idx;
1398
1.40k
                if (t->frame_thread.pass) {
1399
1.40k
                    const int p = t->frame_thread.pass & 1;
1400
1.40k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.40k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.40k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.40k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.40k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.40k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.40k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.40k
                                       f->cur.stride[1], pal[1],
1412
1.40k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.40k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.40k
                                       f->cur.stride[1], pal[2],
1415
1.40k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.40k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.40k
            }
1425
1426
854k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
854k
                                 sm_uv_flag(&t->l, cby4);
1428
854k
            const int uv_sb_has_tr =
1429
854k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
804k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
854k
            const int uv_sb_has_bl =
1432
854k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
804k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
854k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.56M
            for (int pl = 0; pl < 2; pl++) {
1436
3.66M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.95M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.95M
                {
1439
1.95M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.95M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.95M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.76M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.80M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.80M
                    {
1445
2.80M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.54M
                            b->pal_sz[1])
1447
260k
                        {
1448
260k
                            goto skip_uv_pred;
1449
260k
                        }
1450
1451
2.54M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.54M
                        const enum EdgeFlags edge_flags =
1456
2.54M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.36M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.86M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.54M
                            ((x > (init_x >> ss_hor) ||
1460
1.69M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.67M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.54M
                        const pixel *top_sb_edge = NULL;
1463
2.54M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
653k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
653k
                            const int sby = t->by >> f->sb_shift;
1466
653k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
653k
                        }
1468
2.54M
                        const enum IntraPredMode uv_mode =
1469
2.54M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.54M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.54M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.54M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.54M
                        const enum IntraPredMode m =
1474
2.54M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.54M
                                                              ypos, ypos > ystart,
1476
2.54M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.54M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.54M
                                                              edge_flags, dst, stride,
1479
2.54M
                                                              top_sb_edge, uv_mode,
1480
2.54M
                                                              &angle, uv_t_dim->w,
1481
2.54M
                                                              uv_t_dim->h,
1482
2.54M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.54M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.54M
                        angle |= intra_edge_filter_flag;
1485
2.54M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.54M
                                                 uv_t_dim->w * 4,
1487
2.54M
                                                 uv_t_dim->h * 4,
1488
2.54M
                                                 angle | sm_uv_fl,
1489
2.54M
                                                 (4 * f->bw + ss_hor -
1490
2.54M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.54M
                                                 (4 * f->bh + ss_ver -
1492
2.54M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.54M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.54M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.80M
                    skip_uv_pred: {}
1505
2.80M
                        if (!b->skip) {
1506
907k
                            enum TxfmType txtp;
1507
907k
                            int eob;
1508
907k
                            coef *cf;
1509
907k
                            if (t->frame_thread.pass) {
1510
907k
                                const int p = t->frame_thread.pass & 1;
1511
907k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
907k
                                cf = ts->frame_thread[p].cf;
1513
907k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
907k
                                eob  = cbi >> 5;
1515
907k
                                txtp = cbi & 0x1f;
1516
907k
                            } 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
907k
                            if (eob >= 0) {
1533
256k
                                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
256k
                                dsp->itx.itxfm_add[b->uvtx]
1537
256k
                                                  [txtp](dst, stride,
1538
256k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
256k
                                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
256k
                            }
1543
1.89M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.80M
                        dst += uv_t_dim->w * 4;
1548
2.80M
                    }
1549
1.95M
                    t->bx -= x << ss_hor;
1550
1.95M
                }
1551
1.70M
                t->by -= y << ss_ver;
1552
1.70M
            }
1553
854k
        }
1554
1.05M
    }
1555
1.00M
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
416k
{
1560
416k
    Dav1dTileState *const ts = t->ts;
1561
416k
    const Dav1dFrameContext *const f = t->f;
1562
416k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
416k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
416k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
416k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
416k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
416k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
416k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
416k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
416k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
336k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
315k
                           (bh4 > ss_ver || t->by & 1);
1573
416k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
416k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
416k
    int res;
1576
1577
    // prediction
1578
416k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
416k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
416k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
416k
    const ptrdiff_t uvdstoff =
1582
416k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
416k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
134k
        assert(!f->frame_hdr->super_res.enabled);
1586
134k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
134k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
134k
        if (res) return res;
1589
245k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
163k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
163k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
163k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
163k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
163k
            if (res) return res;
1595
163k
        }
1596
282k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
234k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
234k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
234k
        if (imin(bw4, bh4) > 1 &&
1601
140k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
131k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
13.1k
        {
1604
13.1k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
13.1k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
13.1k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
13.1k
            if (res) return res;
1608
221k
        } else {
1609
221k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
221k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
221k
            if (res) return res;
1612
221k
            if (b->motion_mode == MM_OBMC) {
1613
35.2k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
35.2k
                if (res) return res;
1615
35.2k
            }
1616
221k
        }
1617
234k
        if (b->interintra_type) {
1618
9.89k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
9.89k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
8.27k
                                   SMOOTH_PRED : b->interintra_mode;
1621
9.89k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
9.89k
            int angle = 0;
1623
9.89k
            const pixel *top_sb_edge = NULL;
1624
9.89k
            if (!(t->by & (f->sb_step - 1))) {
1625
4.21k
                top_sb_edge = f->ipred_edge[0];
1626
4.21k
                const int sby = t->by >> f->sb_shift;
1627
4.21k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
4.21k
            }
1629
9.89k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
9.89k
                                                  t->by, t->by > ts->tiling.row_start,
1631
9.89k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
9.89k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
9.89k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
9.89k
                                                  HIGHBD_CALL_SUFFIX);
1635
9.89k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
9.89k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
9.89k
                                     HIGHBD_CALL_SUFFIX);
1638
9.89k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
9.89k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
9.89k
        }
1641
1642
234k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
175k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
175k
        refmvs_block *const *r;
1647
175k
        if (is_sub8x8) {
1648
21.8k
            assert(ss_hor == 1);
1649
21.8k
            r = &t->rt.r[(t->by & 31) + 5];
1650
21.8k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
21.8k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
21.8k
            if (bw4 == 1 && bh4 == ss_ver)
1653
3.69k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
21.8k
        }
1655
1656
        // chroma prediction
1657
175k
        if (is_sub8x8) {
1658
21.5k
            assert(ss_hor == 1);
1659
21.5k
            ptrdiff_t h_off = 0, v_off = 0;
1660
21.5k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
10.7k
                for (int pl = 0; pl < 2; pl++) {
1662
7.19k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
7.19k
                             NULL, f->cur.stride[1],
1664
7.19k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
7.19k
                             r[-1][t->bx - 1].mv.mv[0],
1666
7.19k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
7.19k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
7.19k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
7.19k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
7.19k
                    if (res) return res;
1671
7.19k
                }
1672
3.59k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
3.59k
                h_off = 2;
1674
3.59k
            }
1675
21.5k
            if (bw4 == 1) {
1676
10.8k
                const enum Filter2d left_filter_2d =
1677
10.8k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
32.3k
                for (int pl = 0; pl < 2; pl++) {
1679
21.5k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
21.5k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
21.5k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
21.5k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
21.5k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
21.5k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
21.5k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
21.5k
                    if (res) return res;
1687
21.5k
                }
1688
10.8k
                h_off = 2;
1689
10.8k
            }
1690
21.5k
            if (bh4 == ss_ver) {
1691
14.3k
                const enum Filter2d top_filter_2d =
1692
14.3k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
42.9k
                for (int pl = 0; pl < 2; pl++) {
1694
28.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
28.6k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
28.6k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
28.6k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
28.6k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
28.6k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
28.6k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
28.6k
                    if (res) return res;
1702
28.6k
                }
1703
14.3k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
14.3k
            }
1705
64.5k
            for (int pl = 0; pl < 2; pl++) {
1706
43.0k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
43.0k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
43.0k
                         refp, b->ref[0], filter_2d);
1709
43.0k
                if (res) return res;
1710
43.0k
            }
1711
154k
        } else {
1712
154k
            if (imin(cbw4, cbh4) > 1 &&
1713
79.0k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
73.8k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
8.11k
            {
1716
24.3k
                for (int pl = 0; pl < 2; pl++) {
1717
16.2k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
16.2k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
16.2k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
16.2k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
16.2k
                    if (res) return res;
1722
16.2k
                }
1723
145k
            } else {
1724
437k
                for (int pl = 0; pl < 2; pl++) {
1725
291k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
291k
                             NULL, f->cur.stride[1],
1727
291k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
291k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
291k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
291k
                    if (res) return res;
1731
291k
                    if (b->motion_mode == MM_OBMC) {
1732
62.6k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
62.6k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
62.6k
                        if (res) return res;
1735
62.6k
                    }
1736
291k
                }
1737
145k
            }
1738
154k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
8.26k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
24.7k
                for (int pl = 0; pl < 2; pl++) {
1745
16.5k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
16.5k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
16.5k
                    enum IntraPredMode m =
1748
16.5k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
13.7k
                        SMOOTH_PRED : b->interintra_mode;
1750
16.5k
                    int angle = 0;
1751
16.5k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
16.5k
                    const pixel *top_sb_edge = NULL;
1753
16.5k
                    if (!(t->by & (f->sb_step - 1))) {
1754
6.27k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
6.27k
                        const int sby = t->by >> f->sb_shift;
1756
6.27k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
6.27k
                    }
1758
16.5k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
16.5k
                                                          (t->bx >> ss_hor) >
1760
16.5k
                                                              (ts->tiling.col_start >> ss_hor),
1761
16.5k
                                                          t->by >> ss_ver,
1762
16.5k
                                                          (t->by >> ss_ver) >
1763
16.5k
                                                              (ts->tiling.row_start >> ss_ver),
1764
16.5k
                                                          ts->tiling.col_end >> ss_hor,
1765
16.5k
                                                          ts->tiling.row_end >> ss_ver,
1766
16.5k
                                                          0, uvdst, f->cur.stride[1],
1767
16.5k
                                                          top_sb_edge, m,
1768
16.5k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
16.5k
                                                          HIGHBD_CALL_SUFFIX);
1770
16.5k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
16.5k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
16.5k
                                             HIGHBD_CALL_SUFFIX);
1773
16.5k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
16.5k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
16.5k
                }
1776
8.26k
            }
1777
154k
        }
1778
1779
234k
    skip_inter_chroma_pred: {}
1780
234k
        t->tl_4x4_filter = filter_2d;
1781
234k
    } else {
1782
48.1k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
48.1k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
48.1k
        int jnt_weight;
1786
48.1k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
48.1k
        const uint8_t *mask;
1788
1789
144k
        for (int i = 0; i < 2; i++) {
1790
96.2k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
96.2k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.56k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.56k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.56k
                if (res) return res;
1796
91.6k
            } else {
1797
91.6k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
91.6k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
91.6k
                if (res) return res;
1800
91.6k
            }
1801
96.2k
        }
1802
48.1k
        switch (b->comp_type) {
1803
31.0k
        case COMP_INTER_AVG:
1804
31.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
31.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
31.0k
            break;
1807
6.60k
        case COMP_INTER_WEIGHTED_AVG:
1808
6.60k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
6.60k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
6.60k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
6.60k
            break;
1812
6.97k
        case COMP_INTER_SEG:
1813
6.97k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
6.97k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
6.97k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
6.97k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
6.97k
            mask = seg_mask;
1818
6.97k
            break;
1819
3.48k
        case COMP_INTER_WEDGE:
1820
3.48k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.48k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.48k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.48k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.48k
            if (has_chroma)
1825
2.99k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.48k
            break;
1827
48.1k
        }
1828
1829
        // chroma
1830
114k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
228k
            for (int i = 0; i < 2; i++) {
1832
152k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
152k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
26.4k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
5.43k
                {
1836
5.43k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
5.43k
                                      b_dim, 1 + pl,
1838
5.43k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
5.43k
                    if (res) return res;
1840
146k
                } else {
1841
146k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
146k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
146k
                    if (res) return res;
1844
146k
                }
1845
152k
            }
1846
76.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
76.0k
            switch (b->comp_type) {
1848
48.4k
            case COMP_INTER_AVG:
1849
48.4k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
48.4k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
48.4k
                            HIGHBD_CALL_SUFFIX);
1852
48.4k
                break;
1853
10.6k
            case COMP_INTER_WEIGHTED_AVG:
1854
10.6k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
10.6k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
10.6k
                              HIGHBD_CALL_SUFFIX);
1857
10.6k
                break;
1858
5.99k
            case COMP_INTER_WEDGE:
1859
17.0k
            case COMP_INTER_SEG:
1860
17.0k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
17.0k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
17.0k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
17.0k
                             HIGHBD_CALL_SUFFIX);
1864
17.0k
                break;
1865
76.0k
            }
1866
76.0k
        }
1867
48.1k
    }
1868
1869
416k
    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
416k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
416k
    if (b->skip) {
1882
        // reset coef contexts
1883
202k
        BlockContext *const a = t->a;
1884
202k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
202k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
202k
        if (has_chroma) {
1887
131k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
131k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
131k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
131k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
131k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
131k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
131k
        }
1894
202k
        return 0;
1895
202k
    }
1896
1897
214k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
214k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
214k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
438k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
452k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
228k
            int y_off = !!init_y, y;
1905
228k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
480k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
252k
                 y += ytx->h, y_off++)
1908
252k
            {
1909
252k
                int x, x_off = !!init_x;
1910
586k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
333k
                     x += ytx->w, x_off++)
1912
333k
                {
1913
333k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
333k
                                   x_off, y_off, &dst[x * 4]);
1915
333k
                    t->bx += ytx->w;
1916
333k
                }
1917
252k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
252k
                t->bx -= x;
1919
252k
                t->by += ytx->h;
1920
252k
            }
1921
228k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
228k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
524k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
349k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
349k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
349k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
748k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
399k
                {
1931
399k
                    int x;
1932
399k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
937k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
538k
                    {
1935
538k
                        coef *cf;
1936
538k
                        int eob;
1937
538k
                        enum TxfmType txtp;
1938
538k
                        if (t->frame_thread.pass) {
1939
538k
                            const int p = t->frame_thread.pass & 1;
1940
538k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
538k
                            cf = ts->frame_thread[p].cf;
1942
538k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
538k
                            eob  = cbi >> 5;
1944
538k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
538k
                        if (eob >= 0) {
1964
172k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
172k
                            dsp->itx.itxfm_add[b->uvtx]
1967
172k
                                              [txtp](&uvdst[4 * x],
1968
172k
                                                     f->cur.stride[1],
1969
172k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
172k
                            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
172k
                        }
1974
538k
                        t->bx += uvtx->w << ss_hor;
1975
538k
                    }
1976
399k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
399k
                    t->bx -= x << ss_hor;
1978
399k
                    t->by += uvtx->h << ss_ver;
1979
399k
                }
1980
349k
                t->by -= y << ss_ver;
1981
349k
            }
1982
228k
        }
1983
224k
    }
1984
214k
    return 0;
1985
416k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
244k
{
1560
244k
    Dav1dTileState *const ts = t->ts;
1561
244k
    const Dav1dFrameContext *const f = t->f;
1562
244k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
244k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
244k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
244k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
244k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
244k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
244k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
244k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
244k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
192k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
178k
                           (bh4 > ss_ver || t->by & 1);
1573
244k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
244k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
244k
    int res;
1576
1577
    // prediction
1578
244k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
244k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
244k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
244k
    const ptrdiff_t uvdstoff =
1582
244k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
244k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
85.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
85.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
85.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
85.7k
        if (res) return res;
1589
126k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
84.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
84.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
84.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
84.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
84.5k
            if (res) return res;
1595
84.5k
        }
1596
159k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
135k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
135k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
135k
        if (imin(bw4, bh4) > 1 &&
1601
86.3k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
79.4k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
9.08k
        {
1604
9.08k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
9.08k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
9.08k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
9.08k
            if (res) return res;
1608
126k
        } else {
1609
126k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
126k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
126k
            if (res) return res;
1612
126k
            if (b->motion_mode == MM_OBMC) {
1613
21.5k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
21.5k
                if (res) return res;
1615
21.5k
            }
1616
126k
        }
1617
135k
        if (b->interintra_type) {
1618
5.31k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
5.31k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
4.51k
                                   SMOOTH_PRED : b->interintra_mode;
1621
5.31k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
5.31k
            int angle = 0;
1623
5.31k
            const pixel *top_sb_edge = NULL;
1624
5.31k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.10k
                top_sb_edge = f->ipred_edge[0];
1626
2.10k
                const int sby = t->by >> f->sb_shift;
1627
2.10k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.10k
            }
1629
5.31k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
5.31k
                                                  t->by, t->by > ts->tiling.row_start,
1631
5.31k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
5.31k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
5.31k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
5.31k
                                                  HIGHBD_CALL_SUFFIX);
1635
5.31k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
5.31k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
5.31k
                                     HIGHBD_CALL_SUFFIX);
1638
5.31k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
5.31k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
5.31k
        }
1641
1642
135k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
107k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
107k
        refmvs_block *const *r;
1647
107k
        if (is_sub8x8) {
1648
10.9k
            assert(ss_hor == 1);
1649
10.9k
            r = &t->rt.r[(t->by & 31) + 5];
1650
10.9k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
10.9k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
10.9k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.09k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
10.9k
        }
1655
1656
        // chroma prediction
1657
107k
        if (is_sub8x8) {
1658
10.7k
            assert(ss_hor == 1);
1659
10.7k
            ptrdiff_t h_off = 0, v_off = 0;
1660
10.7k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
6.15k
                for (int pl = 0; pl < 2; pl++) {
1662
4.10k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
4.10k
                             NULL, f->cur.stride[1],
1664
4.10k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
4.10k
                             r[-1][t->bx - 1].mv.mv[0],
1666
4.10k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
4.10k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
4.10k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
4.10k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
4.10k
                    if (res) return res;
1671
4.10k
                }
1672
2.05k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.05k
                h_off = 2;
1674
2.05k
            }
1675
10.7k
            if (bw4 == 1) {
1676
6.18k
                const enum Filter2d left_filter_2d =
1677
6.18k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
18.5k
                for (int pl = 0; pl < 2; pl++) {
1679
12.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
12.3k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
12.3k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
12.3k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
12.3k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
12.3k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
12.3k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
12.3k
                    if (res) return res;
1687
12.3k
                }
1688
6.18k
                h_off = 2;
1689
6.18k
            }
1690
10.7k
            if (bh4 == ss_ver) {
1691
6.65k
                const enum Filter2d top_filter_2d =
1692
6.65k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
19.9k
                for (int pl = 0; pl < 2; pl++) {
1694
13.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
13.3k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
13.3k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
13.3k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
13.3k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
13.3k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
13.3k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
13.3k
                    if (res) return res;
1702
13.3k
                }
1703
6.65k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
6.65k
            }
1705
32.3k
            for (int pl = 0; pl < 2; pl++) {
1706
21.5k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
21.5k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
21.5k
                         refp, b->ref[0], filter_2d);
1709
21.5k
                if (res) return res;
1710
21.5k
            }
1711
96.2k
        } else {
1712
96.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
52.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
49.2k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
5.49k
            {
1716
16.4k
                for (int pl = 0; pl < 2; pl++) {
1717
10.9k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
10.9k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
10.9k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
10.9k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
10.9k
                    if (res) return res;
1722
10.9k
                }
1723
90.7k
            } else {
1724
272k
                for (int pl = 0; pl < 2; pl++) {
1725
181k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
181k
                             NULL, f->cur.stride[1],
1727
181k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
181k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
181k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
181k
                    if (res) return res;
1731
181k
                    if (b->motion_mode == MM_OBMC) {
1732
39.8k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
39.8k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
39.8k
                        if (res) return res;
1735
39.8k
                    }
1736
181k
                }
1737
90.7k
            }
1738
96.2k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
4.75k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
14.2k
                for (int pl = 0; pl < 2; pl++) {
1745
9.51k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
9.51k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
9.51k
                    enum IntraPredMode m =
1748
9.51k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
8.08k
                        SMOOTH_PRED : b->interintra_mode;
1750
9.51k
                    int angle = 0;
1751
9.51k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
9.51k
                    const pixel *top_sb_edge = NULL;
1753
9.51k
                    if (!(t->by & (f->sb_step - 1))) {
1754
3.60k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.60k
                        const int sby = t->by >> f->sb_shift;
1756
3.60k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.60k
                    }
1758
9.51k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
9.51k
                                                          (t->bx >> ss_hor) >
1760
9.51k
                                                              (ts->tiling.col_start >> ss_hor),
1761
9.51k
                                                          t->by >> ss_ver,
1762
9.51k
                                                          (t->by >> ss_ver) >
1763
9.51k
                                                              (ts->tiling.row_start >> ss_ver),
1764
9.51k
                                                          ts->tiling.col_end >> ss_hor,
1765
9.51k
                                                          ts->tiling.row_end >> ss_ver,
1766
9.51k
                                                          0, uvdst, f->cur.stride[1],
1767
9.51k
                                                          top_sb_edge, m,
1768
9.51k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
9.51k
                                                          HIGHBD_CALL_SUFFIX);
1770
9.51k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
9.51k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
9.51k
                                             HIGHBD_CALL_SUFFIX);
1773
9.51k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
9.51k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
9.51k
                }
1776
4.75k
            }
1777
96.2k
        }
1778
1779
135k
    skip_inter_chroma_pred: {}
1780
135k
        t->tl_4x4_filter = filter_2d;
1781
135k
    } else {
1782
24.0k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
24.0k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
24.0k
        int jnt_weight;
1786
24.0k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
24.0k
        const uint8_t *mask;
1788
1789
72.1k
        for (int i = 0; i < 2; i++) {
1790
48.1k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
48.1k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.85k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.85k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.85k
                if (res) return res;
1796
45.2k
            } else {
1797
45.2k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
45.2k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
45.2k
                if (res) return res;
1800
45.2k
            }
1801
48.1k
        }
1802
24.0k
        switch (b->comp_type) {
1803
16.1k
        case COMP_INTER_AVG:
1804
16.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
16.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
16.1k
            break;
1807
2.84k
        case COMP_INTER_WEIGHTED_AVG:
1808
2.84k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
2.84k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
2.84k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
2.84k
            break;
1812
3.49k
        case COMP_INTER_SEG:
1813
3.49k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
3.49k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
3.49k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
3.49k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
3.49k
            mask = seg_mask;
1818
3.49k
            break;
1819
1.58k
        case COMP_INTER_WEDGE:
1820
1.58k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.58k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.58k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.58k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.58k
            if (has_chroma)
1825
1.35k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.58k
            break;
1827
24.0k
        }
1828
1829
        // chroma
1830
56.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
112k
            for (int i = 0; i < 2; i++) {
1832
74.9k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
74.9k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
12.3k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.39k
                {
1836
3.39k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.39k
                                      b_dim, 1 + pl,
1838
3.39k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.39k
                    if (res) return res;
1840
71.5k
                } else {
1841
71.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
71.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
71.5k
                    if (res) return res;
1844
71.5k
                }
1845
74.9k
            }
1846
37.4k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
37.4k
            switch (b->comp_type) {
1848
24.5k
            case COMP_INTER_AVG:
1849
24.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
24.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
24.5k
                            HIGHBD_CALL_SUFFIX);
1852
24.5k
                break;
1853
4.71k
            case COMP_INTER_WEIGHTED_AVG:
1854
4.71k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
4.71k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
4.71k
                              HIGHBD_CALL_SUFFIX);
1857
4.71k
                break;
1858
2.70k
            case COMP_INTER_WEDGE:
1859
8.19k
            case COMP_INTER_SEG:
1860
8.19k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
8.19k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
8.19k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
8.19k
                             HIGHBD_CALL_SUFFIX);
1864
8.19k
                break;
1865
37.4k
            }
1866
37.4k
        }
1867
24.0k
    }
1868
1869
244k
    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
244k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
244k
    if (b->skip) {
1882
        // reset coef contexts
1883
134k
        BlockContext *const a = t->a;
1884
134k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
134k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
134k
        if (has_chroma) {
1887
82.5k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
82.5k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
82.5k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
82.5k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
82.5k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
82.5k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
82.5k
        }
1894
134k
        return 0;
1895
134k
    }
1896
1897
110k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
110k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
110k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
224k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
232k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
117k
            int y_off = !!init_y, y;
1905
117k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
252k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
134k
                 y += ytx->h, y_off++)
1908
134k
            {
1909
134k
                int x, x_off = !!init_x;
1910
324k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
190k
                     x += ytx->w, x_off++)
1912
190k
                {
1913
190k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
190k
                                   x_off, y_off, &dst[x * 4]);
1915
190k
                    t->bx += ytx->w;
1916
190k
                }
1917
134k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
134k
                t->bx -= x;
1919
134k
                t->by += ytx->h;
1920
134k
            }
1921
117k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
117k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
274k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
183k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
183k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
183k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
400k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
217k
                {
1931
217k
                    int x;
1932
217k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
528k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
310k
                    {
1935
310k
                        coef *cf;
1936
310k
                        int eob;
1937
310k
                        enum TxfmType txtp;
1938
310k
                        if (t->frame_thread.pass) {
1939
310k
                            const int p = t->frame_thread.pass & 1;
1940
310k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
310k
                            cf = ts->frame_thread[p].cf;
1942
310k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
310k
                            eob  = cbi >> 5;
1944
310k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
310k
                        if (eob >= 0) {
1964
110k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
110k
                            dsp->itx.itxfm_add[b->uvtx]
1967
110k
                                              [txtp](&uvdst[4 * x],
1968
110k
                                                     f->cur.stride[1],
1969
110k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
110k
                            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
110k
                        }
1974
310k
                        t->bx += uvtx->w << ss_hor;
1975
310k
                    }
1976
217k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
217k
                    t->bx -= x << ss_hor;
1978
217k
                    t->by += uvtx->h << ss_ver;
1979
217k
                }
1980
183k
                t->by -= y << ss_ver;
1981
183k
            }
1982
117k
        }
1983
114k
    }
1984
110k
    return 0;
1985
244k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
171k
{
1560
171k
    Dav1dTileState *const ts = t->ts;
1561
171k
    const Dav1dFrameContext *const f = t->f;
1562
171k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
171k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
171k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
171k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
171k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
171k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
171k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
171k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
171k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
144k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
137k
                           (bh4 > ss_ver || t->by & 1);
1573
171k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
171k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
171k
    int res;
1576
1577
    // prediction
1578
171k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
171k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
171k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
171k
    const ptrdiff_t uvdstoff =
1582
171k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
171k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
48.3k
        assert(!f->frame_hdr->super_res.enabled);
1586
48.3k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
48.3k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
48.3k
        if (res) return res;
1589
118k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
79.0k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
79.0k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
79.0k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
79.0k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
79.0k
            if (res) return res;
1595
79.0k
        }
1596
123k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
99.4k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
99.4k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
99.4k
        if (imin(bw4, bh4) > 1 &&
1601
53.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
51.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.02k
        {
1604
4.02k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.02k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.02k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.02k
            if (res) return res;
1608
95.4k
        } else {
1609
95.4k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
95.4k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
95.4k
            if (res) return res;
1612
95.4k
            if (b->motion_mode == MM_OBMC) {
1613
13.7k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
13.7k
                if (res) return res;
1615
13.7k
            }
1616
95.4k
        }
1617
99.4k
        if (b->interintra_type) {
1618
4.57k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
4.57k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.75k
                                   SMOOTH_PRED : b->interintra_mode;
1621
4.57k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
4.57k
            int angle = 0;
1623
4.57k
            const pixel *top_sb_edge = NULL;
1624
4.57k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.10k
                top_sb_edge = f->ipred_edge[0];
1626
2.10k
                const int sby = t->by >> f->sb_shift;
1627
2.10k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.10k
            }
1629
4.57k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
4.57k
                                                  t->by, t->by > ts->tiling.row_start,
1631
4.57k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
4.57k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
4.57k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
4.57k
                                                  HIGHBD_CALL_SUFFIX);
1635
4.57k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
4.57k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
4.57k
                                     HIGHBD_CALL_SUFFIX);
1638
4.57k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
4.57k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
4.57k
        }
1641
1642
99.4k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
68.5k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
68.5k
        refmvs_block *const *r;
1647
68.5k
        if (is_sub8x8) {
1648
10.8k
            assert(ss_hor == 1);
1649
10.8k
            r = &t->rt.r[(t->by & 31) + 5];
1650
10.8k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
10.8k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
10.8k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.59k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
10.8k
        }
1655
1656
        // chroma prediction
1657
68.5k
        if (is_sub8x8) {
1658
10.7k
            assert(ss_hor == 1);
1659
10.7k
            ptrdiff_t h_off = 0, v_off = 0;
1660
10.7k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.63k
                for (int pl = 0; pl < 2; pl++) {
1662
3.09k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.09k
                             NULL, f->cur.stride[1],
1664
3.09k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.09k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.09k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.09k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.09k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.09k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.09k
                    if (res) return res;
1671
3.09k
                }
1672
1.54k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.54k
                h_off = 2;
1674
1.54k
            }
1675
10.7k
            if (bw4 == 1) {
1676
4.61k
                const enum Filter2d left_filter_2d =
1677
4.61k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
13.8k
                for (int pl = 0; pl < 2; pl++) {
1679
9.22k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
9.22k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
9.22k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
9.22k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
9.22k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
9.22k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
9.22k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
9.22k
                    if (res) return res;
1687
9.22k
                }
1688
4.61k
                h_off = 2;
1689
4.61k
            }
1690
10.7k
            if (bh4 == ss_ver) {
1691
7.64k
                const enum Filter2d top_filter_2d =
1692
7.64k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
22.9k
                for (int pl = 0; pl < 2; pl++) {
1694
15.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
15.2k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
15.2k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
15.2k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
15.2k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
15.2k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
15.2k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
15.2k
                    if (res) return res;
1702
15.2k
                }
1703
7.64k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
7.64k
            }
1705
32.1k
            for (int pl = 0; pl < 2; pl++) {
1706
21.4k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
21.4k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
21.4k
                         refp, b->ref[0], filter_2d);
1709
21.4k
                if (res) return res;
1710
21.4k
            }
1711
57.7k
        } else {
1712
57.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
26.2k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
24.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.62k
            {
1716
7.86k
                for (int pl = 0; pl < 2; pl++) {
1717
5.24k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.24k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.24k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.24k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.24k
                    if (res) return res;
1722
5.24k
                }
1723
55.1k
            } else {
1724
165k
                for (int pl = 0; pl < 2; pl++) {
1725
110k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
110k
                             NULL, f->cur.stride[1],
1727
110k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
110k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
110k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
110k
                    if (res) return res;
1731
110k
                    if (b->motion_mode == MM_OBMC) {
1732
22.8k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
22.8k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
22.8k
                        if (res) return res;
1735
22.8k
                    }
1736
110k
                }
1737
55.1k
            }
1738
57.7k
            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.50k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
10.5k
                for (int pl = 0; pl < 2; pl++) {
1745
7.01k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
7.01k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
7.01k
                    enum IntraPredMode m =
1748
7.01k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.62k
                        SMOOTH_PRED : b->interintra_mode;
1750
7.01k
                    int angle = 0;
1751
7.01k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
7.01k
                    const pixel *top_sb_edge = NULL;
1753
7.01k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.67k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.67k
                        const int sby = t->by >> f->sb_shift;
1756
2.67k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.67k
                    }
1758
7.01k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
7.01k
                                                          (t->bx >> ss_hor) >
1760
7.01k
                                                              (ts->tiling.col_start >> ss_hor),
1761
7.01k
                                                          t->by >> ss_ver,
1762
7.01k
                                                          (t->by >> ss_ver) >
1763
7.01k
                                                              (ts->tiling.row_start >> ss_ver),
1764
7.01k
                                                          ts->tiling.col_end >> ss_hor,
1765
7.01k
                                                          ts->tiling.row_end >> ss_ver,
1766
7.01k
                                                          0, uvdst, f->cur.stride[1],
1767
7.01k
                                                          top_sb_edge, m,
1768
7.01k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
7.01k
                                                          HIGHBD_CALL_SUFFIX);
1770
7.01k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
7.01k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
7.01k
                                             HIGHBD_CALL_SUFFIX);
1773
7.01k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
7.01k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
7.01k
                }
1776
3.50k
            }
1777
57.7k
        }
1778
1779
99.4k
    skip_inter_chroma_pred: {}
1780
99.4k
        t->tl_4x4_filter = filter_2d;
1781
99.4k
    } else {
1782
24.0k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
24.0k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
24.0k
        int jnt_weight;
1786
24.0k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
24.0k
        const uint8_t *mask;
1788
1789
72.1k
        for (int i = 0; i < 2; i++) {
1790
48.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
48.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.71k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.71k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.71k
                if (res) return res;
1796
46.3k
            } else {
1797
46.3k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
46.3k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
46.3k
                if (res) return res;
1800
46.3k
            }
1801
48.0k
        }
1802
24.0k
        switch (b->comp_type) {
1803
14.9k
        case COMP_INTER_AVG:
1804
14.9k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
14.9k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
14.9k
            break;
1807
3.75k
        case COMP_INTER_WEIGHTED_AVG:
1808
3.75k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
3.75k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
3.75k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
3.75k
            break;
1812
3.48k
        case COMP_INTER_SEG:
1813
3.48k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
3.48k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
3.48k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
3.48k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
3.48k
            mask = seg_mask;
1818
3.48k
            break;
1819
1.89k
        case COMP_INTER_WEDGE:
1820
1.89k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.89k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.89k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.89k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.89k
            if (has_chroma)
1825
1.64k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.89k
            break;
1827
24.0k
        }
1828
1829
        // chroma
1830
57.9k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
115k
            for (int i = 0; i < 2; i++) {
1832
77.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
77.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
14.0k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.03k
                {
1836
2.03k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.03k
                                      b_dim, 1 + pl,
1838
2.03k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.03k
                    if (res) return res;
1840
75.2k
                } else {
1841
75.2k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
75.2k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
75.2k
                    if (res) return res;
1844
75.2k
                }
1845
77.2k
            }
1846
38.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
38.6k
            switch (b->comp_type) {
1848
23.8k
            case COMP_INTER_AVG:
1849
23.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
23.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
23.8k
                            HIGHBD_CALL_SUFFIX);
1852
23.8k
                break;
1853
5.90k
            case COMP_INTER_WEIGHTED_AVG:
1854
5.90k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
5.90k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
5.90k
                              HIGHBD_CALL_SUFFIX);
1857
5.90k
                break;
1858
3.28k
            case COMP_INTER_WEDGE:
1859
8.85k
            case COMP_INTER_SEG:
1860
8.85k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
8.85k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
8.85k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
8.85k
                             HIGHBD_CALL_SUFFIX);
1864
8.85k
                break;
1865
38.6k
            }
1866
38.6k
        }
1867
24.0k
    }
1868
1869
171k
    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
171k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
171k
    if (b->skip) {
1882
        // reset coef contexts
1883
67.3k
        BlockContext *const a = t->a;
1884
67.3k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
67.3k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
67.3k
        if (has_chroma) {
1887
49.1k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
49.1k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
49.1k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
49.1k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
49.1k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
49.1k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
49.1k
        }
1894
67.3k
        return 0;
1895
67.3k
    }
1896
1897
104k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
104k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
104k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
213k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
220k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
110k
            int y_off = !!init_y, y;
1905
110k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
228k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
117k
                 y += ytx->h, y_off++)
1908
117k
            {
1909
117k
                int x, x_off = !!init_x;
1910
261k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
143k
                     x += ytx->w, x_off++)
1912
143k
                {
1913
143k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
143k
                                   x_off, y_off, &dst[x * 4]);
1915
143k
                    t->bx += ytx->w;
1916
143k
                }
1917
117k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
117k
                t->bx -= x;
1919
117k
                t->by += ytx->h;
1920
117k
            }
1921
110k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
110k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
249k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
166k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
166k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
166k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
348k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
182k
                {
1931
182k
                    int x;
1932
182k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
409k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
227k
                    {
1935
227k
                        coef *cf;
1936
227k
                        int eob;
1937
227k
                        enum TxfmType txtp;
1938
227k
                        if (t->frame_thread.pass) {
1939
227k
                            const int p = t->frame_thread.pass & 1;
1940
227k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
227k
                            cf = ts->frame_thread[p].cf;
1942
227k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
227k
                            eob  = cbi >> 5;
1944
227k
                            txtp = cbi & 0x1f;
1945
227k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
227k
                        if (eob >= 0) {
1964
62.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
62.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
62.2k
                                              [txtp](&uvdst[4 * x],
1968
62.2k
                                                     f->cur.stride[1],
1969
62.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
62.2k
                            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
62.2k
                        }
1974
227k
                        t->bx += uvtx->w << ss_hor;
1975
227k
                    }
1976
182k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
182k
                    t->bx -= x << ss_hor;
1978
182k
                    t->by += uvtx->h << ss_ver;
1979
182k
                }
1980
166k
                t->by -= y << ss_ver;
1981
166k
            }
1982
110k
        }
1983
109k
    }
1984
104k
    return 0;
1985
171k
}
1986
1987
205k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
205k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
205k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
205k
    const int y = sby * f->sb_step * 4;
1994
205k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
205k
    pixel *const p[3] = {
1996
205k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
205k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
205k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
205k
    };
2000
205k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
205k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
205k
                                        f->lf.start_of_tile_row[sby]);
2003
205k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
107k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
107k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
107k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
107k
    const int y = sby * f->sb_step * 4;
1994
107k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
107k
    pixel *const p[3] = {
1996
107k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
107k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
107k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
107k
    };
2000
107k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
107k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
107k
                                        f->lf.start_of_tile_row[sby]);
2003
107k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
97.7k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
97.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
97.7k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
97.7k
    const int y = sby * f->sb_step * 4;
1994
97.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
97.7k
    pixel *const p[3] = {
1996
97.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
97.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
97.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
97.7k
    };
2000
97.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
97.7k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
97.7k
                                        f->lf.start_of_tile_row[sby]);
2003
97.7k
}
2004
2005
257k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
257k
    const int y = sby * f->sb_step * 4;
2007
257k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
257k
    pixel *const p[3] = {
2009
257k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
257k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
257k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
257k
    };
2013
257k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
257k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
257k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
205k
    {
2017
205k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
205k
    }
2019
257k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
215k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
215k
    }
2023
257k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
129k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
129k
    const int y = sby * f->sb_step * 4;
2007
129k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
129k
    pixel *const p[3] = {
2009
129k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
129k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
129k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
129k
    };
2013
129k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
129k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
129k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
107k
    {
2017
107k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
107k
    }
2019
129k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
107k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
107k
    }
2023
129k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
127k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
127k
    const int y = sby * f->sb_step * 4;
2007
127k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
127k
    pixel *const p[3] = {
2009
127k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
127k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
127k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
127k
    };
2013
127k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
127k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
127k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
97.6k
    {
2017
97.6k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
97.6k
    }
2019
127k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
108k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
108k
    }
2023
127k
}
2024
2025
160k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
160k
    const Dav1dFrameContext *const f = tc->f;
2027
160k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
160k
    const int sbsz = f->sb_step;
2029
160k
    const int y = sby * sbsz * 4;
2030
160k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
160k
    pixel *const p[3] = {
2032
160k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
160k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
160k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
160k
    };
2036
160k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
160k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
160k
    const int start = sby * sbsz;
2039
160k
    if (sby) {
2040
85.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
85.7k
        pixel *p_up[3] = {
2042
85.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
85.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
85.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
85.7k
        };
2046
85.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
85.7k
    }
2048
160k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
160k
    const int end = imin(start + n_blks, f->bh);
2050
160k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
160k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
81.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
81.4k
    const Dav1dFrameContext *const f = tc->f;
2027
81.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
81.4k
    const int sbsz = f->sb_step;
2029
81.4k
    const int y = sby * sbsz * 4;
2030
81.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
81.4k
    pixel *const p[3] = {
2032
81.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
81.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
81.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
81.4k
    };
2036
81.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
81.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
81.4k
    const int start = sby * sbsz;
2039
81.4k
    if (sby) {
2040
42.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
42.4k
        pixel *p_up[3] = {
2042
42.4k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
42.4k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
42.4k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
42.4k
        };
2046
42.4k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
42.4k
    }
2048
81.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
81.4k
    const int end = imin(start + n_blks, f->bh);
2050
81.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
81.4k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
78.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
78.7k
    const Dav1dFrameContext *const f = tc->f;
2027
78.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
78.7k
    const int sbsz = f->sb_step;
2029
78.7k
    const int y = sby * sbsz * 4;
2030
78.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
78.7k
    pixel *const p[3] = {
2032
78.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
78.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
78.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
78.7k
    };
2036
78.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
78.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
78.7k
    const int start = sby * sbsz;
2039
78.7k
    if (sby) {
2040
43.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
43.3k
        pixel *p_up[3] = {
2042
43.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
43.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
43.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
43.3k
        };
2046
43.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
43.3k
    }
2048
78.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
78.7k
    const int end = imin(start + n_blks, f->bh);
2050
78.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
78.7k
}
2052
2053
56.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
56.0k
    const int sbsz = f->sb_step;
2055
56.0k
    const int y = sby * sbsz * 4;
2056
56.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
56.0k
    const pixel *const p[3] = {
2058
56.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
56.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
56.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
56.0k
    };
2062
56.0k
    pixel *const sr_p[3] = {
2063
56.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
56.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
56.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
56.0k
    };
2067
56.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
196k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
139k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
139k
        const int h_start = 8 * !!sby >> ss_ver;
2071
139k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
139k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
139k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
139k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
139k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
139k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
139k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
139k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
139k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
139k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
139k
                          imin(img_h, h_end) + h_start, src_w,
2083
139k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
139k
                          HIGHBD_CALL_SUFFIX);
2085
139k
    }
2086
56.0k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
26.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
26.0k
    const int sbsz = f->sb_step;
2055
26.0k
    const int y = sby * sbsz * 4;
2056
26.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
26.0k
    const pixel *const p[3] = {
2058
26.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
26.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
26.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
26.0k
    };
2062
26.0k
    pixel *const sr_p[3] = {
2063
26.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
26.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
26.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
26.0k
    };
2067
26.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
94.4k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
68.3k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
68.3k
        const int h_start = 8 * !!sby >> ss_ver;
2071
68.3k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
68.3k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
68.3k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
68.3k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
68.3k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
68.3k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
68.3k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
68.3k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
68.3k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
68.3k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
68.3k
                          imin(img_h, h_end) + h_start, src_w,
2083
68.3k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
68.3k
                          HIGHBD_CALL_SUFFIX);
2085
68.3k
    }
2086
26.0k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
29.9k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
29.9k
    const int sbsz = f->sb_step;
2055
29.9k
    const int y = sby * sbsz * 4;
2056
29.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
29.9k
    const pixel *const p[3] = {
2058
29.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
29.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
29.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
29.9k
    };
2062
29.9k
    pixel *const sr_p[3] = {
2063
29.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
29.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
29.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
29.9k
    };
2067
29.9k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
101k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
71.5k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
71.5k
        const int h_start = 8 * !!sby >> ss_ver;
2071
71.5k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
71.5k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
71.5k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
71.5k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
71.5k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
71.5k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
71.5k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
71.5k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
71.5k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
71.5k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
71.5k
                          imin(img_h, h_end) + h_start, src_w,
2083
71.5k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
71.5k
                          HIGHBD_CALL_SUFFIX);
2085
71.5k
    }
2086
29.9k
}
2087
2088
135k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
135k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
135k
    const int y = sby * f->sb_step * 4;
2091
135k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
135k
    pixel *const sr_p[3] = {
2093
135k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
135k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
135k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
135k
    };
2097
135k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
135k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
66.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
66.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
66.8k
    const int y = sby * f->sb_step * 4;
2091
66.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
66.8k
    pixel *const sr_p[3] = {
2093
66.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
66.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
66.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
66.8k
    };
2097
66.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
66.8k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
68.1k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
68.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
68.1k
    const int y = sby * f->sb_step * 4;
2091
68.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
68.1k
    pixel *const sr_p[3] = {
2093
68.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
68.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
68.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
68.1k
    };
2097
68.1k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
68.1k
}
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
313k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
313k
    const Dav1dFrameContext *const f = t->f;
2113
313k
    Dav1dTileState *const ts = t->ts;
2114
313k
    const int sby = t->by >> f->sb_shift;
2115
313k
    const int sby_off = f->sb128w * 128 * sby;
2116
313k
    const int x_off = ts->tiling.col_start;
2117
2118
313k
    const pixel *const y =
2119
313k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
313k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
313k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
313k
               4 * (ts->tiling.col_end - x_off));
2123
2124
313k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
241k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
241k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
241k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
241k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
723k
        for (int pl = 1; pl <= 2; pl++)
2131
482k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
249k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
249k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
241k
    }
2135
313k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
160k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
160k
    const Dav1dFrameContext *const f = t->f;
2113
160k
    Dav1dTileState *const ts = t->ts;
2114
160k
    const int sby = t->by >> f->sb_shift;
2115
160k
    const int sby_off = f->sb128w * 128 * sby;
2116
160k
    const int x_off = ts->tiling.col_start;
2117
2118
160k
    const pixel *const y =
2119
160k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
160k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
160k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
160k
               4 * (ts->tiling.col_end - x_off));
2123
2124
160k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
124k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
124k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
124k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
124k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
373k
        for (int pl = 1; pl <= 2; pl++)
2131
249k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
249k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
249k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
124k
    }
2135
160k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
152k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
152k
    const Dav1dFrameContext *const f = t->f;
2113
152k
    Dav1dTileState *const ts = t->ts;
2114
152k
    const int sby = t->by >> f->sb_shift;
2115
152k
    const int sby_off = f->sb128w * 128 * sby;
2116
152k
    const int x_off = ts->tiling.col_start;
2117
2118
152k
    const pixel *const y =
2119
152k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
152k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
152k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
152k
               4 * (ts->tiling.col_end - x_off));
2123
2124
152k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
116k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
116k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
116k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
116k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
349k
        for (int pl = 1; pl <= 2; pl++)
2131
232k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
116k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
116k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
116k
    }
2135
152k
}
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
39.6k
{
2142
39.6k
    const Dav1dFrameContext *const f = t->f;
2143
39.6k
    pixel *const pal = t->frame_thread.pass ?
2144
39.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
39.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
39.6k
        bytefn(t->scratch.pal)[0];
2147
190k
    for (int x = 0; x < bw4; x++)
2148
151k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
162k
    for (int y = 0; y < bh4; y++)
2150
123k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
39.6k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
19.9k
{
2142
19.9k
    const Dav1dFrameContext *const f = t->f;
2143
19.9k
    pixel *const pal = t->frame_thread.pass ?
2144
19.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
19.9k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
19.9k
        bytefn(t->scratch.pal)[0];
2147
95.4k
    for (int x = 0; x < bw4; x++)
2148
75.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
79.8k
    for (int y = 0; y < bh4; y++)
2150
59.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
19.9k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
19.6k
{
2142
19.6k
    const Dav1dFrameContext *const f = t->f;
2143
19.6k
    pixel *const pal = t->frame_thread.pass ?
2144
19.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
19.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
19.6k
        bytefn(t->scratch.pal)[0];
2147
95.4k
    for (int x = 0; x < bw4; x++)
2148
75.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
83.0k
    for (int y = 0; y < bh4; y++)
2150
63.4k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
19.6k
}
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
14.8k
{
2158
14.8k
    const Dav1dFrameContext *const f = t->f;
2159
14.8k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
14.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
14.8k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
14.8k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
44.6k
    for (int pl = 1; pl <= 2; pl++) {
2165
170k
        for (int x = 0; x < bw4; x++)
2166
140k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
146k
        for (int y = 0; y < bh4; y++)
2168
116k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
29.7k
    }
2170
14.8k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
7.24k
{
2158
7.24k
    const Dav1dFrameContext *const f = t->f;
2159
7.24k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.24k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.24k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.24k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
21.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
82.6k
        for (int x = 0; x < bw4; x++)
2166
68.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
73.4k
        for (int y = 0; y < bh4; y++)
2168
58.9k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
14.4k
    }
2170
7.24k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
7.65k
{
2158
7.65k
    const Dav1dFrameContext *const f = t->f;
2159
7.65k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.65k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.65k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.65k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
22.9k
    for (int pl = 1; pl <= 2; pl++) {
2165
88.0k
        for (int x = 0; x < bw4; x++)
2166
72.7k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
72.6k
        for (int y = 0; y < bh4; y++)
2168
57.3k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
15.3k
    }
2170
7.65k
}
2171
2172
void bytefn(dav1d_read_pal_plane)(Dav1dTaskContext *const t, Av1Block *const b,
2173
                                  const int pl, const int sz_ctx,
2174
                                  const int bx4, const int by4)
2175
54.5k
{
2176
54.5k
    Dav1dTileState *const ts = t->ts;
2177
54.5k
    const Dav1dFrameContext *const f = t->f;
2178
54.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
54.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
54.5k
    pixel cache[16], used_cache[8];
2181
54.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
54.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
54.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
54.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
54.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
90.7k
    while (l_cache && a_cache) {
2190
36.2k
        if (*l < *a) {
2191
13.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
13.2k
                cache[n_cache++] = *l;
2193
13.2k
            l++;
2194
13.2k
            l_cache--;
2195
22.9k
        } else {
2196
22.9k
            if (*a == *l) {
2197
9.15k
                l++;
2198
9.15k
                l_cache--;
2199
9.15k
            }
2200
22.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
22.2k
                cache[n_cache++] = *a;
2202
22.9k
            a++;
2203
22.9k
            a_cache--;
2204
22.9k
        }
2205
36.2k
    }
2206
54.5k
    if (l_cache) {
2207
64.7k
        do {
2208
64.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
52.6k
                cache[n_cache++] = *l;
2210
64.7k
            l++;
2211
64.7k
        } while (--l_cache > 0);
2212
38.8k
    } else if (a_cache) {
2213
46.1k
        do {
2214
46.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
36.7k
                cache[n_cache++] = *a;
2216
46.1k
            a++;
2217
46.1k
        } while (--a_cache > 0);
2218
11.3k
    }
2219
2220
    // find reused cache entries
2221
54.5k
    int i = 0;
2222
165k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
110k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
55.2k
            used_cache[i++] = cache[n];
2225
54.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
54.5k
    pixel *const pal = t->frame_thread.pass ?
2229
54.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
54.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
54.5k
        bytefn(t->scratch.pal)[pl];
2232
54.5k
    if (i < pal_sz) {
2233
47.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
47.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
47.5k
        if (i < pal_sz) {
2237
42.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
42.8k
            const int max = (1 << bpc) - 1;
2239
2240
100k
            do {
2241
100k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
100k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
100k
                if (prev + !pl >= max) {
2244
56.6k
                    for (; i < pal_sz; i++)
2245
37.0k
                        pal[i] = max;
2246
19.6k
                    break;
2247
19.6k
                }
2248
80.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
80.8k
            } while (i < pal_sz);
2250
42.8k
        }
2251
2252
        // merge cache+new entries
2253
47.5k
        int n = 0, m = n_used_cache;
2254
269k
        for (i = 0; i < pal_sz; i++) {
2255
221k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
36.6k
                pal[i] = used_cache[n++];
2257
185k
            } else {
2258
185k
                assert(m < pal_sz);
2259
185k
                pal[i] = pal[m++];
2260
185k
            }
2261
221k
        }
2262
47.5k
    } else {
2263
6.94k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
6.94k
    }
2265
2266
54.5k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
54.5k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
27.1k
{
2176
27.1k
    Dav1dTileState *const ts = t->ts;
2177
27.1k
    const Dav1dFrameContext *const f = t->f;
2178
27.1k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
27.1k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
27.1k
    pixel cache[16], used_cache[8];
2181
27.1k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
27.1k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
27.1k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
27.1k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
27.1k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
48.0k
    while (l_cache && a_cache) {
2190
20.8k
        if (*l < *a) {
2191
7.70k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
7.65k
                cache[n_cache++] = *l;
2193
7.70k
            l++;
2194
7.70k
            l_cache--;
2195
13.1k
        } else {
2196
13.1k
            if (*a == *l) {
2197
5.23k
                l++;
2198
5.23k
                l_cache--;
2199
5.23k
            }
2200
13.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
12.7k
                cache[n_cache++] = *a;
2202
13.1k
            a++;
2203
13.1k
            a_cache--;
2204
13.1k
        }
2205
20.8k
    }
2206
27.1k
    if (l_cache) {
2207
33.5k
        do {
2208
33.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
27.1k
                cache[n_cache++] = *l;
2210
33.5k
            l++;
2211
33.5k
        } while (--l_cache > 0);
2212
19.0k
    } else if (a_cache) {
2213
23.5k
        do {
2214
23.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
18.4k
                cache[n_cache++] = *a;
2216
23.5k
            a++;
2217
23.5k
        } while (--a_cache > 0);
2218
5.84k
    }
2219
2220
    // find reused cache entries
2221
27.1k
    int i = 0;
2222
85.5k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
58.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
29.1k
            used_cache[i++] = cache[n];
2225
27.1k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
27.1k
    pixel *const pal = t->frame_thread.pass ?
2229
27.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
27.1k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
27.1k
        bytefn(t->scratch.pal)[pl];
2232
27.1k
    if (i < pal_sz) {
2233
23.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
23.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
23.5k
        if (i < pal_sz) {
2237
21.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
21.0k
            const int max = (1 << bpc) - 1;
2239
2240
48.8k
            do {
2241
48.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
48.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
48.8k
                if (prev + !pl >= max) {
2244
28.9k
                    for (; i < pal_sz; i++)
2245
19.0k
                        pal[i] = max;
2246
9.86k
                    break;
2247
9.86k
                }
2248
38.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
38.9k
            } while (i < pal_sz);
2250
21.0k
        }
2251
2252
        // merge cache+new entries
2253
23.5k
        int n = 0, m = n_used_cache;
2254
134k
        for (i = 0; i < pal_sz; i++) {
2255
110k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
19.2k
                pal[i] = used_cache[n++];
2257
91.5k
            } else {
2258
91.5k
                assert(m < pal_sz);
2259
91.5k
                pal[i] = pal[m++];
2260
91.5k
            }
2261
110k
        }
2262
23.5k
    } else {
2263
3.59k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.59k
    }
2265
2266
27.1k
    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
27.1k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
27.3k
{
2176
27.3k
    Dav1dTileState *const ts = t->ts;
2177
27.3k
    const Dav1dFrameContext *const f = t->f;
2178
27.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
27.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
27.3k
    pixel cache[16], used_cache[8];
2181
27.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
27.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
27.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
27.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
27.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
42.6k
    while (l_cache && a_cache) {
2190
15.3k
        if (*l < *a) {
2191
5.58k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
5.54k
                cache[n_cache++] = *l;
2193
5.58k
            l++;
2194
5.58k
            l_cache--;
2195
9.75k
        } else {
2196
9.75k
            if (*a == *l) {
2197
3.91k
                l++;
2198
3.91k
                l_cache--;
2199
3.91k
            }
2200
9.75k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
9.51k
                cache[n_cache++] = *a;
2202
9.75k
            a++;
2203
9.75k
            a_cache--;
2204
9.75k
        }
2205
15.3k
    }
2206
27.3k
    if (l_cache) {
2207
31.2k
        do {
2208
31.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
25.5k
                cache[n_cache++] = *l;
2210
31.2k
            l++;
2211
31.2k
        } while (--l_cache > 0);
2212
19.8k
    } else if (a_cache) {
2213
22.6k
        do {
2214
22.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
18.3k
                cache[n_cache++] = *a;
2216
22.6k
            a++;
2217
22.6k
        } while (--a_cache > 0);
2218
5.50k
    }
2219
2220
    // find reused cache entries
2221
27.3k
    int i = 0;
2222
79.7k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
52.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
26.1k
            used_cache[i++] = cache[n];
2225
27.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
27.3k
    pixel *const pal = t->frame_thread.pass ?
2229
27.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
27.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
27.3k
        bytefn(t->scratch.pal)[pl];
2232
27.3k
    if (i < pal_sz) {
2233
23.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
23.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
23.9k
        if (i < pal_sz) {
2237
21.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
21.7k
            const int max = (1 << bpc) - 1;
2239
2240
51.5k
            do {
2241
51.5k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
51.5k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
51.5k
                if (prev + !pl >= max) {
2244
27.6k
                    for (; i < pal_sz; i++)
2245
17.9k
                        pal[i] = max;
2246
9.73k
                    break;
2247
9.73k
                }
2248
41.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
41.8k
            } while (i < pal_sz);
2250
21.7k
        }
2251
2252
        // merge cache+new entries
2253
23.9k
        int n = 0, m = n_used_cache;
2254
134k
        for (i = 0; i < pal_sz; i++) {
2255
110k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
17.3k
                pal[i] = used_cache[n++];
2257
93.5k
            } else {
2258
93.5k
                assert(m < pal_sz);
2259
93.5k
                pal[i] = pal[m++];
2260
93.5k
            }
2261
110k
        }
2262
23.9k
    } else {
2263
3.35k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.35k
    }
2265
2266
27.3k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
27.3k
}
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
14.8k
{
2281
14.8k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
14.8k
    Dav1dTileState *const ts = t->ts;
2285
14.8k
    const Dav1dFrameContext *const f = t->f;
2286
14.8k
    pixel *const pal = t->frame_thread.pass ?
2287
14.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
14.8k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
14.8k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
14.8k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
7.75k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
7.75k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
7.75k
        const int max = (1 << bpc) - 1;
2295
32.6k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
24.8k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
24.8k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
24.8k
            prev = pal[i] = (prev + delta) & max;
2299
24.8k
        }
2300
7.75k
    } else {
2301
37.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
29.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
7.13k
    }
2304
14.8k
    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
14.8k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
7.24k
{
2281
7.24k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.24k
    Dav1dTileState *const ts = t->ts;
2285
7.24k
    const Dav1dFrameContext *const f = t->f;
2286
7.24k
    pixel *const pal = t->frame_thread.pass ?
2287
7.24k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.24k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
7.24k
        bytefn(t->scratch.pal)[2];
2290
7.24k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.24k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.66k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.66k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.66k
        const int max = (1 << bpc) - 1;
2295
15.9k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
12.2k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
12.2k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
12.2k
            prev = pal[i] = (prev + delta) & max;
2299
12.2k
        }
2300
3.66k
    } else {
2301
18.6k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
15.0k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.57k
    }
2304
7.24k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
7.24k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
7.65k
{
2281
7.65k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.65k
    Dav1dTileState *const ts = t->ts;
2285
7.65k
    const Dav1dFrameContext *const f = t->f;
2286
7.65k
    pixel *const pal = t->frame_thread.pass ?
2287
7.65k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.65k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
7.65k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.65k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.08k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.08k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.08k
        const int max = (1 << bpc) - 1;
2295
16.6k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
12.6k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
12.6k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
12.6k
            prev = pal[i] = (prev + delta) & max;
2299
12.6k
        }
2300
4.08k
    } else {
2301
18.4k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
14.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.56k
    }
2304
7.65k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
7.65k
}