Coverage Report

Created: 2026-09-01 06:57

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.58M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.58M
    int len = 0;
51
1.58M
    unsigned val = 1;
52
53
2.92M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
2.92M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.58M
    return val - 1;
57
1.58M
}
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
12.5M
{
66
12.5M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
12.5M
    if (chroma) {
69
6.41M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
6.41M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
6.41M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
4.08M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
6.41M
        unsigned ca, cl;
74
75
6.41M
#define MERGE_CTX(dir, type, no_val) \
76
12.8M
        c##dir = *(const type *) dir != no_val; \
77
12.8M
        break
78
79
6.41M
        switch (t_dim->lw) {
80
        /* For some reason the MSVC CRT _wassert() function is not flagged as
81
         * __declspec(noreturn), so when using those headers the compiler will
82
         * expect execution to continue after an assertion has been triggered
83
         * and will therefore complain about the use of uninitialized variables
84
         * when compiled in debug mode if we put the default case at the end. */
85
0
        default: assert(0); /* fall-through */
86
2.60M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
1.30M
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
980k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
1.53M
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
6.41M
        }
91
6.41M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
2.89M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
1.29M
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
762k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
1.47M
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
6.41M
        }
98
6.41M
#undef MERGE_CTX
99
100
6.41M
        return 7 + not_one_blk * 3 + ca + cl;
101
6.41M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
2.58M
        return 0;
103
3.51M
    } else {
104
3.51M
        unsigned la, ll;
105
106
3.51M
#define MERGE_CTX(dir, type, tx) \
107
7.07M
        if (tx == TX_64X64) { \
108
534k
            uint64_t tmp = *(const uint64_t *) dir; \
109
534k
            tmp |= *(const uint64_t *) &dir[8]; \
110
534k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
534k
        } else \
112
7.07M
            l##dir = *(const type *) dir; \
113
7.07M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
7.07M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
7.07M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
7.07M
        break
117
118
3.51M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
1.97M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
708k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
537k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
51.6k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
267k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
3.51M
        }
126
3.53M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
1.99M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
689k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
535k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
52.3k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
267k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
3.53M
        }
134
3.53M
#undef MERGE_CTX
135
136
3.53M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
3.53M
    }
138
12.5M
}
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
5.32M
{
144
5.32M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
5.32M
    int s;
146
147
5.32M
#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
5.32M
    __asm__("" : "+r"(mask), "+r"(mul));
151
5.32M
#endif
152
153
5.32M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
1.99M
    case TX_4X4: {
156
1.99M
        int t = *(const uint8_t *) a >> 6;
157
1.99M
        t    += *(const uint8_t *) l >> 6;
158
1.99M
        s = t - 1 - 1;
159
1.99M
        break;
160
0
    }
161
624k
    case TX_8X8: {
162
624k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
624k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
624k
        t *= 0x04040404U;
165
624k
        s = (int) (t >> 24) - 2 - 2;
166
624k
        break;
167
0
    }
168
450k
    case TX_16X16: {
169
450k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
450k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
450k
        t *= (uint32_t) mul;
172
450k
        s = (int) (t >> 24) - 4 - 4;
173
450k
        break;
174
0
    }
175
389k
    case TX_32X32: {
176
389k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
389k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
389k
        t *= mul;
179
389k
        s = (int) (t >> 56) - 8 - 8;
180
389k
        break;
181
0
    }
182
204k
    case TX_64X64: {
183
204k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
204k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
204k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
204k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
204k
        t *= mul;
188
204k
        s = (int) (t >> 56) - 16 - 16;
189
204k
        break;
190
0
    }
191
187k
    case RTX_4X8: {
192
187k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
187k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
187k
        t *= 0x04040404U;
195
187k
        s = (int) (t >> 24) - 1 - 2;
196
187k
        break;
197
0
    }
198
276k
    case RTX_8X4: {
199
276k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
276k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
276k
        t *= 0x04040404U;
202
276k
        s = (int) (t >> 24) - 2 - 1;
203
276k
        break;
204
0
    }
205
162k
    case RTX_8X16: {
206
162k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
162k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
162k
        t = (t >> 6) * (uint32_t) mul;
209
162k
        s = (int) (t >> 24) - 2 - 4;
210
162k
        break;
211
0
    }
212
295k
    case RTX_16X8: {
213
295k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
295k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
295k
        t = (t >> 6) * (uint32_t) mul;
216
295k
        s = (int) (t >> 24) - 4 - 2;
217
295k
        break;
218
0
    }
219
82.5k
    case RTX_16X32: {
220
82.5k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
82.5k
        t         += *(const uint64_t *) l & mask;
222
82.5k
        t = (t >> 6) * mul;
223
82.5k
        s = (int) (t >> 56) - 4 - 8;
224
82.5k
        break;
225
0
    }
226
137k
    case RTX_32X16: {
227
137k
        uint64_t t = *(const uint64_t *) a & mask;
228
137k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
137k
        t = (t >> 6) * mul;
230
137k
        s = (int) (t >> 56) - 8 - 4;
231
137k
        break;
232
0
    }
233
49.5k
    case RTX_32X64: {
234
49.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
49.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
49.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
49.5k
        t *= mul;
238
49.5k
        s = (int) (t >> 56) - 8 - 16;
239
49.5k
        break;
240
0
    }
241
45.4k
    case RTX_64X32: {
242
45.4k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
45.4k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
45.4k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
45.4k
        t *= mul;
246
45.4k
        s = (int) (t >> 56) - 16 - 8;
247
45.4k
        break;
248
0
    }
249
87.0k
    case RTX_4X16: {
250
87.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
87.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
87.0k
        t = (t >> 6) * (uint32_t) mul;
253
87.0k
        s = (int) (t >> 24) - 1 - 4;
254
87.0k
        break;
255
0
    }
256
165k
    case RTX_16X4: {
257
165k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
165k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
165k
        t = (t >> 6) * (uint32_t) mul;
260
165k
        s = (int) (t >> 24) - 4 - 1;
261
165k
        break;
262
0
    }
263
59.9k
    case RTX_8X32: {
264
59.9k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
59.9k
        t         += *(const uint64_t *) l & mask;
266
59.9k
        t = (t >> 6) * mul;
267
59.9k
        s = (int) (t >> 56) - 2 - 8;
268
59.9k
        break;
269
0
    }
270
74.9k
    case RTX_32X8: {
271
74.9k
        uint64_t t = *(const uint64_t *) a & mask;
272
74.9k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
74.9k
        t = (t >> 6) * mul;
274
74.9k
        s = (int) (t >> 56) - 8 - 2;
275
74.9k
        break;
276
0
    }
277
19.7k
    case RTX_16X64: {
278
19.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
19.7k
        t         += *(const uint64_t *) &l[0] & mask;
280
19.7k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
19.7k
        t *= mul;
282
19.7k
        s = (int) (t >> 56) - 4 - 16;
283
19.7k
        break;
284
0
    }
285
13.1k
    case RTX_64X16: {
286
13.1k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
13.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
13.1k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
13.1k
        t *= mul;
290
13.1k
        s = (int) (t >> 56) - 16 - 4;
291
13.1k
        break;
292
0
    }
293
5.32M
    }
294
295
5.32M
    return (s != 0) + (s > 0);
296
5.32M
}
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
104M
{
305
104M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
104M
    unsigned offset;
307
104M
    if (tx_class == TX_CLASS_2D) {
308
95.4M
        mag += levels[1 * stride + 1];
309
95.4M
        *hi_mag = mag;
310
95.4M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
95.4M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
95.4M
    } else {
313
8.64M
        mag += levels[0 * stride + 2];
314
8.64M
        *hi_mag = mag;
315
8.64M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
8.64M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
8.64M
    }
318
104M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
104M
}
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
12.5M
{
328
12.5M
    Dav1dTileState *const ts = t->ts;
329
12.5M
    const int chroma = !!plane;
330
12.5M
    const Dav1dFrameContext *const f = t->f;
331
12.5M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
12.5M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
12.5M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
12.5M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
12.5M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
12.5M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
12.5M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
12.5M
    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
12.5M
    if (all_skip) {
346
6.09M
        *res_ctx = 0x40;
347
6.09M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
6.09M
        return -1;
349
6.09M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
6.42M
    if (lossless) {
353
1.73M
        assert(t_dim->max == TX_4X4);
354
1.73M
        *txtp = WHT_WHT;
355
4.68M
    } else if (t_dim->max + intra >= TX_64X64) {
356
970k
        *txtp = DCT_DCT;
357
3.71M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
868k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
868k
                        get_uv_inter_txtp(t_dim, *txtp);
361
2.85M
    } 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
27.2k
        *txtp = DCT_DCT;
366
2.82M
    } else {
367
2.82M
        unsigned idx;
368
2.82M
        if (intra) {
369
1.68M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
1.43M
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.68M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
735k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
735k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
735k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
953k
            } else {
376
953k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
953k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
953k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
953k
            }
380
1.68M
            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.68M
        } else {
384
1.13M
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
294k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
294k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
294k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
839k
            } else if (t_dim->min == TX_16X16) {
389
102k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
102k
                          ts->cdf.m.txtp_inter2, 11);
391
102k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
737k
            } else {
393
737k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
737k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
737k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
737k
            }
397
1.13M
            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
1.13M
        }
401
2.82M
    }
402
403
    // find end-of-block (eob)
404
6.42M
    int eob;
405
6.42M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
6.42M
    const int tx2dszctx = slw + slh;
407
6.42M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
6.42M
    const int is_1d = tx_class != TX_CLASS_2D;
409
6.42M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
6.44M
    case sz: { \
412
6.44M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
6.44M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
6.44M
        break; \
415
6.44M
    }
416
2.29M
    case_sz(0,   16,  8, [is_1d]);
417
616k
    case_sz(1,   32,  8, [is_1d]);
418
1.14M
    case_sz(2,   64,  8, [is_1d]);
419
615k
    case_sz(3,  128,  8, [is_1d]);
420
730k
    case_sz(4,  256, 16, [is_1d]);
421
291k
    case_sz(5,  512, 16,        );
422
748k
    case_sz(6, 1024, 16,        );
423
6.42M
#undef case_sz
424
6.42M
    }
425
6.44M
    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
6.44M
    if (eob > 1) {
429
4.06M
        const int eob_bin = eob - 2;
430
4.06M
        uint16_t *const eob_hi_bit_cdf =
431
4.06M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
4.06M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
4.06M
        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
4.06M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
4.06M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
4.06M
    }
440
6.44M
    assert(eob >= 0);
441
442
    // base tokens
443
6.44M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
6.44M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
6.44M
    unsigned rc, dc_tok;
446
447
6.44M
    if (eob) {
448
4.31M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
4.31M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
4.31M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
4.31M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
4.31M
        int tok = eob_tok + 1;
455
4.31M
        int level_tok = tok * 0x41;
456
4.31M
        unsigned mag;
457
458
4.31M
#define DECODE_COEFS_CLASS(tx_class) \
459
4.31M
        unsigned x, y; \
460
4.31M
        uint8_t *level; \
461
4.31M
        if (tx_class == TX_CLASS_2D) \
462
4.31M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
4.31M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
462k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
462k
        else /* tx_class == TX_CLASS_V */ \
467
462k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
4.31M
        if (dbg) \
469
4.31M
            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
4.31M
        if (eob_tok == 2) { \
472
97.9k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
97.9k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
97.9k
            level_tok = tok + (3 << 6); \
475
97.9k
            if (dbg) \
476
97.9k
                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
97.9k
        } \
480
4.31M
        cf[rc] = tok << 11; \
481
4.31M
        if (tx_class == TX_CLASS_2D) \
482
4.31M
            level = levels + rc; \
483
4.31M
        else \
484
4.31M
            level = levels + x * stride + y; \
485
4.31M
        *level = (uint8_t) level_tok; \
486
107M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
103M
            unsigned rc_i; \
488
103M
            if (tx_class == TX_CLASS_2D) \
489
103M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
103M
            else if (tx_class == TX_CLASS_H) \
491
8.28M
                x = i & mask, y = i >> shift, rc_i = i; \
492
8.28M
            else /* tx_class == TX_CLASS_V */ \
493
8.28M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
103M
            assert(x < 32 && y < 32); \
495
103M
            if (tx_class == TX_CLASS_2D) \
496
103M
                level = levels + rc_i; \
497
103M
            else \
498
103M
                level = levels + x * stride + y; \
499
103M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
103M
            if (tx_class == TX_CLASS_2D) \
501
103M
                y |= x; \
502
103M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
103M
            if (dbg) \
504
103M
                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
103M
            if (tok == 3) { \
507
7.64M
                mag &= 63; \
508
7.64M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
7.64M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
7.64M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
7.64M
                if (dbg) \
512
7.64M
                    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
7.64M
                *level = (uint8_t) (tok + (3 << 6)); \
516
7.64M
                cf[rc_i] = (tok << 11) | rc; \
517
7.64M
                rc = rc_i; \
518
95.9M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
95.9M
                tok *= 0x17ff41; \
521
95.9M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
95.9M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
95.9M
                if (tok) rc = rc_i; \
525
95.9M
                cf[rc_i] = tok; \
526
95.9M
            } \
527
103M
        } \
528
        /* dc */ \
529
4.31M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
4.31M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
4.31M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
4.31M
        if (dbg) \
533
4.31M
            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
4.31M
        if (dc_tok == 3) { \
536
1.51M
            if (tx_class == TX_CLASS_2D) \
537
1.51M
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
1.47M
                      levels[1 * stride + 1]; \
539
1.51M
            mag &= 63; \
540
1.51M
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
1.51M
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
1.51M
            if (dbg) \
543
1.51M
                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.51M
        } \
546
4.31M
        break
547
548
4.31M
        const uint16_t *scan;
549
4.31M
        switch (tx_class) {
550
3.85M
        case TX_CLASS_2D: {
551
3.85M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
3.85M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
3.85M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
3.85M
            scan = dav1d_scans[tx];
555
3.85M
            const ptrdiff_t stride = 4 << slh;
556
3.85M
            const unsigned shift = slh + 2, shift2 = 0;
557
3.85M
            const unsigned mask = (4 << slh) - 1;
558
3.85M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
3.85M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
3.85M
        }
561
292k
        case TX_CLASS_H: {
562
292k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
292k
            const ptrdiff_t stride = 16;
564
292k
            const unsigned shift = slh + 2, shift2 = 0;
565
292k
            const unsigned mask = (4 << slh) - 1;
566
292k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
292k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
292k
        }
569
169k
        case TX_CLASS_V: {
570
169k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
169k
            const ptrdiff_t stride = 16;
572
169k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
169k
            const unsigned mask = (4 << slw) - 1;
574
169k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
169k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
169k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
4.31M
        }
580
4.31M
    } else { // dc-only
581
2.12M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
2.12M
        dc_tok = 1 + tok_br;
583
2.12M
        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.12M
        if (tok_br == 2) {
587
89.0k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
89.0k
            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
89.0k
        }
592
2.12M
        rc = 0;
593
2.12M
    }
594
595
    // residual and sign
596
6.43M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
6.43M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
6.43M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
6.43M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
6.43M
    unsigned cul_level, dc_sign_level;
601
602
6.43M
    if (!dc_tok) {
603
1.12M
        cul_level = 0;
604
1.12M
        dc_sign_level = 1 << 6;
605
1.12M
        if (qm_tbl) goto ac_qm;
606
782k
        goto ac_noqm;
607
1.12M
    }
608
609
5.31M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
5.31M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
5.31M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
5.31M
    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
5.31M
    int dc_dq = dq_tbl[0];
617
5.31M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
5.31M
    if (qm_tbl) {
620
1.81M
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
1.81M
        if (dc_tok == 15) {
623
45.9k
            dc_tok = read_golomb(&ts->msac) + 15;
624
45.9k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
45.9k
            dc_tok &= 0xfffff;
629
45.9k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
1.77M
        } else {
631
1.77M
            dc_dq *= dc_tok;
632
1.77M
            assert(dc_dq <= 0xffffff);
633
1.77M
        }
634
1.81M
        cul_level = dc_tok;
635
1.81M
        dc_dq >>= dq_shift;
636
1.81M
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
1.81M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
2.64M
        if (rc) ac_qm: {
640
2.64M
            const unsigned ac_dq = dq_tbl[1];
641
17.1M
            do {
642
17.1M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
17.1M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
17.1M
                const unsigned rc_tok = cf[rc];
646
17.1M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
17.1M
                int dq_sat;
648
649
17.1M
                if (rc_tok >= (15 << 11)) {
650
1.05M
                    tok = read_golomb(&ts->msac) + 15;
651
1.05M
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
1.05M
                    tok &= 0xfffff;
656
1.05M
                    dq = (dq * tok) & 0xffffff;
657
16.0M
                } else {
658
16.0M
                    tok = rc_tok >> 11;
659
16.0M
                    dq *= tok;
660
16.0M
                    assert(dq <= 0xffffff);
661
16.0M
                }
662
17.1M
                cul_level += tok;
663
17.1M
                dq >>= dq_shift;
664
17.1M
                dq_sat = umin(dq, cf_max + sign);
665
17.1M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
17.1M
                rc = rc_tok & 0x3ff;
668
17.1M
            } while (rc);
669
2.64M
        }
670
3.49M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
3.49M
        if (dc_tok == 15) {
673
104k
            dc_tok = read_golomb(&ts->msac) + 15;
674
104k
            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
104k
            dc_tok &= 0xfffff;
679
104k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
104k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
3.39M
        } else {
682
3.39M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
3.39M
            assert(dc_dq <= cf_max);
684
3.39M
        }
685
3.49M
        cul_level = dc_tok;
686
3.49M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
4.85M
        if (rc) ac_noqm: {
689
4.85M
            const unsigned ac_dq = dq_tbl[1];
690
21.6M
            do {
691
21.6M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
21.6M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
21.6M
                const unsigned rc_tok = cf[rc];
695
21.6M
                unsigned tok;
696
21.6M
                int dq;
697
698
                // residual
699
21.6M
                if (rc_tok >= (15 << 11)) {
700
373k
                    tok = read_golomb(&ts->msac) + 15;
701
373k
                    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
373k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
373k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
373k
                    dq = umin(dq, cf_max + sign);
711
21.3M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
21.3M
                    tok = rc_tok >> 11;
714
21.3M
                    dq = ((ac_dq * tok) >> dq_shift);
715
21.3M
                    assert(dq <= cf_max);
716
21.3M
                }
717
21.6M
                cul_level += tok;
718
21.6M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
21.6M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
21.6M
            } while (rc);
722
4.85M
        }
723
3.49M
    }
724
725
    // context
726
6.43M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
6.43M
    return eob;
729
5.31M
}
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
3.19M
{
737
3.19M
    const Dav1dFrameContext *const f = t->f;
738
3.19M
    Dav1dTileState *const ts = t->ts;
739
3.19M
    const Dav1dDSPContext *const dsp = f->dsp;
740
3.19M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
3.19M
    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
3.19M
    if (depth < 2 && tx_split[depth] &&
746
308k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
244k
    {
748
244k
        const enum RectTxfmSize sub = t_dim->sub;
749
244k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
244k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
244k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
244k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
244k
        t->bx += txsw;
755
244k
        if (txw >= txh && t->bx < f->bw)
756
178k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
178k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
244k
        t->bx -= txsw;
759
244k
        t->by += txsh;
760
244k
        if (txh >= txw && t->by < f->bh) {
761
171k
            if (dst)
762
62.9k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
171k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
171k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
171k
            t->bx += txsw;
766
171k
            if (txw >= txh && t->bx < f->bw)
767
106k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
106k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
171k
            t->bx -= txsw;
770
171k
        }
771
244k
        t->by -= txsh;
772
2.94M
    } else {
773
2.94M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
2.94M
        enum TxfmType txtp;
775
2.94M
        uint8_t cf_ctx;
776
2.94M
        int eob;
777
2.94M
        coef *cf;
778
779
2.94M
        if (t->frame_thread.pass) {
780
2.94M
            const int p = t->frame_thread.pass & 1;
781
2.94M
            assert(ts->frame_thread[p].cf);
782
2.94M
            cf = ts->frame_thread[p].cf;
783
2.94M
            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
2.94M
        if (t->frame_thread.pass != 2) {
788
1.90M
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
1.90M
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
1.90M
            if (DEBUG_BLOCK_INFO)
791
0
                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
792
0
                       ytx, txtp, eob, ts->msac.rng);
793
1.90M
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
1.90M
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
1.90M
#define set_ctx(rep_macro) \
796
7.81M
            for (int y = 0; y < txh; y++) { \
797
5.91M
                rep_macro(txtp_map, 0, txtp); \
798
5.91M
                txtp_map += 32; \
799
5.91M
            }
800
1.90M
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
1.90M
            case_set_upto16(t_dim->lw);
802
1.90M
#undef set_ctx
803
1.90M
            if (t->frame_thread.pass == 1)
804
1.90M
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
1.90M
        } else {
806
1.04M
            const int cbi = *ts->frame_thread[0].cbi++;
807
1.04M
            eob  = cbi >> 5;
808
1.04M
            txtp = cbi & 0x1f;
809
1.04M
        }
810
2.94M
        if (!(t->frame_thread.pass & 1)) {
811
1.04M
            assert(dst);
812
1.04M
            if (eob >= 0) {
813
804k
                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
804k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
804k
                                              HIGHBD_CALL_SUFFIX);
817
804k
                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
804k
            }
820
1.04M
        }
821
2.94M
    }
822
3.19M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
6.96M
{
827
6.96M
    const Dav1dFrameContext *const f = t->f;
828
6.96M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
6.96M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
6.96M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
6.96M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
6.96M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
6.96M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
6.96M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
6.96M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
5.65M
                           (bw4 > ss_hor || t->bx & 1) &&
837
5.27M
                           (bh4 > ss_ver || t->by & 1);
838
839
6.96M
    if (b->skip) {
840
3.87M
        BlockContext *const a = t->a;
841
3.87M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
3.87M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
3.87M
        if (has_chroma) {
844
2.79M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
2.79M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
2.79M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
2.79M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
2.79M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
2.79M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
2.79M
        }
851
3.87M
        return;
852
3.87M
    }
853
854
3.08M
    Dav1dTileState *const ts = t->ts;
855
3.08M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
3.08M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
3.08M
    assert(t->frame_thread.pass == 1);
858
3.08M
    assert(!b->skip);
859
3.08M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
3.08M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
3.08M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
6.26M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
3.17M
        const int sub_h4 = imin(h4, 16 + init_y);
865
6.46M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
3.29M
            const int sub_w4 = imin(w4, init_x + 16);
867
3.29M
            int y_off = !!init_y, y, x;
868
7.04M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
3.75M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
3.75M
            {
871
3.75M
                int x_off = !!init_x;
872
9.57M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
5.82M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
5.82M
                {
875
5.82M
                    if (!b->intra) {
876
1.60M
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
1.60M
                                       x_off, y_off, NULL);
878
4.22M
                    } else {
879
4.22M
                        uint8_t cf_ctx = 0x40;
880
4.22M
                        enum TxfmType txtp;
881
4.22M
                        const int eob =
882
4.22M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
4.22M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
4.22M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
4.22M
                        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.22M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
4.22M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
4.22M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
4.22M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
4.22M
                    }
893
5.82M
                }
894
3.75M
                t->bx -= x;
895
3.75M
            }
896
3.29M
            t->by -= y;
897
898
3.29M
            if (!has_chroma) continue;
899
900
2.28M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
2.28M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
6.86M
            for (int pl = 0; pl < 2; pl++) {
903
9.55M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
4.98M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
4.98M
                {
906
11.4M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
6.41M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
6.41M
                    {
909
6.41M
                        uint8_t cf_ctx = 0x40;
910
6.41M
                        enum TxfmType txtp;
911
6.41M
                        if (!b->intra)
912
2.24M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
2.24M
                                                        bx4 + (x << ss_hor)];
914
6.41M
                        const int eob =
915
6.41M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
6.41M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
6.41M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
6.41M
                                         &txtp, &cf_ctx);
919
6.41M
                        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
6.41M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
6.41M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
6.41M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
6.41M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
6.41M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
6.41M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
6.41M
                    }
930
4.98M
                    t->bx -= x << ss_hor;
931
4.98M
                }
932
4.57M
                t->by -= y << ss_ver;
933
4.57M
            }
934
2.28M
        }
935
3.17M
    }
936
3.08M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
3.41M
{
827
3.41M
    const Dav1dFrameContext *const f = t->f;
828
3.41M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.41M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.41M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.41M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.41M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.41M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.41M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.41M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
3.01M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.79M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.41M
    if (b->skip) {
840
1.98M
        BlockContext *const a = t->a;
841
1.98M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.98M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.98M
        if (has_chroma) {
844
1.44M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.44M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.44M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.44M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.44M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.44M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.44M
        }
851
1.98M
        return;
852
1.98M
    }
853
854
1.43M
    Dav1dTileState *const ts = t->ts;
855
1.43M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.43M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.43M
    assert(t->frame_thread.pass == 1);
858
1.43M
    assert(!b->skip);
859
1.43M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.43M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.43M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.91M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.47M
        const int sub_h4 = imin(h4, 16 + init_y);
865
3.00M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.53M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.53M
            int y_off = !!init_y, y, x;
868
3.22M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.69M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.69M
            {
871
1.69M
                int x_off = !!init_x;
872
4.09M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.40M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.40M
                {
875
2.40M
                    if (!b->intra) {
876
706k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
706k
                                       x_off, y_off, NULL);
878
1.69M
                    } else {
879
1.69M
                        uint8_t cf_ctx = 0x40;
880
1.69M
                        enum TxfmType txtp;
881
1.69M
                        const int eob =
882
1.69M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.69M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.69M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.69M
                        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.69M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.69M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.69M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.69M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.69M
                    }
893
2.40M
                }
894
1.69M
                t->bx -= x;
895
1.69M
            }
896
1.53M
            t->by -= y;
897
898
1.53M
            if (!has_chroma) continue;
899
900
1.23M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.23M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.71M
            for (int pl = 0; pl < 2; pl++) {
903
5.11M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.63M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.63M
                {
906
5.74M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.11M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.11M
                    {
909
3.11M
                        uint8_t cf_ctx = 0x40;
910
3.11M
                        enum TxfmType txtp;
911
3.11M
                        if (!b->intra)
912
1.09M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.09M
                                                        bx4 + (x << ss_hor)];
914
3.11M
                        const int eob =
915
3.11M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.11M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.11M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.11M
                                         &txtp, &cf_ctx);
919
3.11M
                        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
3.11M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.11M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.11M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.11M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.11M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.11M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.11M
                    }
930
2.63M
                    t->bx -= x << ss_hor;
931
2.63M
                }
932
2.47M
                t->by -= y << ss_ver;
933
2.47M
            }
934
1.23M
        }
935
1.47M
    }
936
1.43M
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
3.54M
{
827
3.54M
    const Dav1dFrameContext *const f = t->f;
828
3.54M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.54M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.54M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.54M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.54M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.54M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.54M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.54M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.63M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.48M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.54M
    if (b->skip) {
840
1.89M
        BlockContext *const a = t->a;
841
1.89M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.89M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.89M
        if (has_chroma) {
844
1.35M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.35M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.35M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.35M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.35M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.35M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.35M
        }
851
1.89M
        return;
852
1.89M
    }
853
854
1.65M
    Dav1dTileState *const ts = t->ts;
855
1.65M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.65M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.65M
    assert(t->frame_thread.pass == 1);
858
1.65M
    assert(!b->skip);
859
1.65M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.65M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.65M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
3.34M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.69M
        const int sub_h4 = imin(h4, 16 + init_y);
865
3.45M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.76M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.76M
            int y_off = !!init_y, y, x;
868
3.81M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
2.05M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
2.05M
            {
871
2.05M
                int x_off = !!init_x;
872
5.48M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
3.42M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
3.42M
                {
875
3.42M
                    if (!b->intra) {
876
900k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
900k
                                       x_off, y_off, NULL);
878
2.52M
                    } else {
879
2.52M
                        uint8_t cf_ctx = 0x40;
880
2.52M
                        enum TxfmType txtp;
881
2.52M
                        const int eob =
882
2.52M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.52M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.52M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.52M
                        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.52M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.52M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.52M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.52M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.52M
                    }
893
3.42M
                }
894
2.05M
                t->bx -= x;
895
2.05M
            }
896
1.76M
            t->by -= y;
897
898
1.76M
            if (!has_chroma) continue;
899
900
1.04M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.04M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.14M
            for (int pl = 0; pl < 2; pl++) {
903
4.44M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.35M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.35M
                {
906
5.66M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.30M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.30M
                    {
909
3.30M
                        uint8_t cf_ctx = 0x40;
910
3.30M
                        enum TxfmType txtp;
911
3.30M
                        if (!b->intra)
912
1.15M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.15M
                                                        bx4 + (x << ss_hor)];
914
3.30M
                        const int eob =
915
3.30M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.30M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.30M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.30M
                                         &txtp, &cf_ctx);
919
3.30M
                        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
3.30M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.30M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.30M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.30M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.30M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.30M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.30M
                    }
930
2.35M
                    t->bx -= x << ss_hor;
931
2.35M
                }
932
2.09M
                t->by -= y << ss_ver;
933
2.09M
            }
934
1.04M
        }
935
1.69M
    }
936
1.65M
}
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
3.79M
{
945
3.79M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
3.79M
    const Dav1dFrameContext *const f = t->f;
947
3.79M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
3.79M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
3.79M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
3.79M
    const int mvx = mv.x, mvy = mv.y;
951
3.79M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
3.79M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
3.79M
    const pixel *ref;
954
955
3.79M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
1.97M
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
1.97M
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
1.97M
        int w, h;
959
960
1.97M
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
1.20M
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
1.20M
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
1.20M
        } else {
964
765k
            w = f->bw * 4 >> ss_hor;
965
765k
            h = f->bh * 4 >> ss_ver;
966
765k
        }
967
1.97M
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
1.57M
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
988k
            dy + bh4 * v_mul + !!my * 4 > h)
970
1.07M
        {
971
1.07M
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
1.07M
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
1.07M
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
1.07M
                                emu_edge_buf, 192 * sizeof(pixel),
975
1.07M
                                refp->p.data[pl], ref_stride);
976
1.07M
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
1.07M
            ref_stride = 192 * sizeof(pixel);
978
1.07M
        } else {
979
902k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
902k
        }
981
982
1.97M
        if (dst8 != NULL) {
983
1.68M
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
1.68M
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
1.68M
                                     HIGHBD_CALL_SUFFIX);
986
1.68M
        } else {
987
284k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
284k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
284k
                                      HIGHBD_CALL_SUFFIX);
990
284k
        }
991
1.97M
    } else {
992
1.81M
        assert(refp != &f->sr_cur);
993
994
1.81M
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
1.81M
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
3.63M
#define scale_mv(res, val, scale) do { \
997
3.63M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
3.63M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
3.63M
        } while (0)
1000
1.81M
        int pos_y, pos_x;
1001
1.81M
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
1.81M
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
1.81M
#undef scale_mv
1004
1.81M
        const int left = pos_x >> 10;
1005
1.81M
        const int top = pos_y >> 10;
1006
1.81M
        const int right =
1007
1.81M
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
1.81M
        const int bottom =
1009
1.81M
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
1.81M
        if (DEBUG_BLOCK_INFO)
1012
0
            printf("Off %dx%d [%d,%d,%d], size %dx%d [%d,%d]\n",
1013
0
                   left, top, orig_pos_x, f->svc[refidx][0].scale, refidx,
1014
0
                   right-left, bottom-top,
1015
0
                   f->svc[refidx][0].step, f->svc[refidx][1].step);
1016
1017
1.81M
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
1.81M
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
1.81M
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
900k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
900k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
900k
                                w, h, left - 3, top - 3,
1023
900k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
900k
                                refp->p.data[pl], ref_stride);
1025
900k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
900k
            ref_stride = 320 * sizeof(pixel);
1027
900k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
918k
        } else {
1029
918k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
918k
        }
1031
1032
1.81M
        if (dst8 != NULL) {
1033
1.44M
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
1.44M
                                            bw4 * h_mul, bh4 * v_mul,
1035
1.44M
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
1.44M
                                            f->svc[refidx][0].step,
1037
1.44M
                                            f->svc[refidx][1].step
1038
1.44M
                                            HIGHBD_CALL_SUFFIX);
1039
1.44M
        } else {
1040
377k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
377k
                                             bw4 * h_mul, bh4 * v_mul,
1042
377k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
377k
                                             f->svc[refidx][0].step,
1044
377k
                                             f->svc[refidx][1].step
1045
377k
                                             HIGHBD_CALL_SUFFIX);
1046
377k
        }
1047
1.81M
    }
1048
1049
3.79M
    return 0;
1050
3.79M
}
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
356k
{
1057
356k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
356k
    const Dav1dFrameContext *const f = t->f;
1059
356k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
356k
    pixel *const lap = bitfn(t->scratch.lap);
1061
356k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
356k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
356k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
356k
    int res;
1065
1066
356k
    if (t->by > t->ts->tiling.row_start &&
1067
308k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
255k
    {
1069
535k
        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
279k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
279k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
279k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
279k
            if (a_r->ref.ref[0] > 0) {
1076
274k
                const int ow4 = imin(step4, b_dim[0]);
1077
274k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
274k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
274k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
274k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
274k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
274k
                if (res) return res;
1083
274k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
274k
                                   h_mul * ow4, v_mul * oh4);
1085
274k
                i++;
1086
274k
            }
1087
279k
            x += step4;
1088
279k
        }
1089
255k
    }
1090
1091
356k
    if (t->bx > t->ts->tiling.col_start)
1092
543k
        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
284k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
284k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
284k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
284k
            if (l_r->ref.ref[0] > 0) {
1099
279k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
279k
                const int oh4 = imin(step4, b_dim[1]);
1101
279k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
279k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
279k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
279k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
279k
                if (res) return res;
1106
279k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
279k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
279k
                i++;
1109
279k
            }
1110
284k
            y += step4;
1111
284k
        }
1112
356k
    return 0;
1113
356k
}
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
62.7k
{
1121
62.7k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
62.7k
    const Dav1dFrameContext *const f = t->f;
1123
62.7k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
62.7k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
62.7k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
62.7k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
62.7k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
62.7k
    const int32_t *const mat = wmp->matrix;
1129
62.7k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
62.7k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
253k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
191k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
191k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
191k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
769k
        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
578k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
578k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
578k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
578k
            const int dx = (int) (mvx >> 16) - 4;
1144
578k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
578k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
578k
            const int dy = (int) (mvy >> 16) - 4;
1147
578k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
578k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
578k
            const pixel *ref_ptr;
1151
578k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
578k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
500k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
500k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
500k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
500k
                                    refp->p.data[pl], ref_stride);
1158
500k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
500k
                ref_stride = 32 * sizeof(pixel);
1160
500k
            } else {
1161
78.1k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
78.1k
            }
1163
578k
            if (dst16 != NULL)
1164
161k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
161k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
416k
            else
1167
416k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
416k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
578k
        }
1170
191k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
54.8k
        else      dst16 += 8 * dstride;
1172
191k
    }
1173
62.7k
    return 0;
1174
62.7k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
2.82M
{
1180
2.82M
    Dav1dTileState *const ts = t->ts;
1181
2.82M
    const Dav1dFrameContext *const f = t->f;
1182
2.82M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
2.82M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
2.82M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
2.82M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
2.82M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
2.82M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
2.82M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
2.82M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
2.82M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
2.82M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
2.28M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
2.14M
                           (bh4 > ss_ver || t->by & 1);
1194
2.82M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
2.82M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
2.82M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
2.82M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
2.82M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
5.73M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
2.90M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
2.90M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
5.91M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
3.01M
            if (b->pal_sz[0]) {
1208
22.9k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
22.9k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
22.9k
                const uint8_t *pal_idx;
1211
22.9k
                if (t->frame_thread.pass) {
1212
22.9k
                    const int p = t->frame_thread.pass & 1;
1213
22.9k
                    assert(ts->frame_thread[p].pal_idx);
1214
22.9k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
22.9k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
22.9k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
22.9k
                const pixel *const pal = t->frame_thread.pass ?
1220
22.9k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
22.9k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
22.9k
                    bytefn(t->scratch.pal)[0];
1223
22.9k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
22.9k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
22.9k
                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
22.9k
            }
1229
1230
3.01M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
3.01M
                                     sm_flag(&t->l, by4) |
1232
3.01M
                                     intra_edge_filter_flag);
1233
3.01M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
2.90M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
3.01M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
2.90M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
3.01M
            int y, x;
1238
3.01M
            const int sub_w4 = imin(w4, init_x + 16);
1239
6.71M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
3.70M
                 y += t_dim->h, t->by += t_dim->h)
1241
3.70M
            {
1242
3.70M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
3.70M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
3.70M
                                    t->bx + init_x);
1245
9.78M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
6.08M
                     x += t_dim->w, t->bx += t_dim->w)
1247
6.08M
                {
1248
6.08M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
6.05M
                    int angle = b->y_angle;
1251
6.05M
                    const enum EdgeFlags edge_flags =
1252
6.05M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
4.39M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
6.05M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
4.02M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
6.05M
                    const pixel *top_sb_edge = NULL;
1257
6.05M
                    if (!(t->by & (f->sb_step - 1))) {
1258
1.18M
                        top_sb_edge = f->ipred_edge[0];
1259
1.18M
                        const int sby = t->by >> f->sb_shift;
1260
1.18M
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
1.18M
                    }
1262
6.05M
                    const enum IntraPredMode m =
1263
6.05M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
6.05M
                                                          t->bx > ts->tiling.col_start,
1265
6.05M
                                                          t->by,
1266
6.05M
                                                          t->by > ts->tiling.row_start,
1267
6.05M
                                                          ts->tiling.col_end,
1268
6.05M
                                                          ts->tiling.row_end,
1269
6.05M
                                                          edge_flags, dst,
1270
6.05M
                                                          f->cur.stride[0], top_sb_edge,
1271
6.05M
                                                          b->y_mode, &angle,
1272
6.05M
                                                          t_dim->w, t_dim->h,
1273
6.05M
                                                          f->seq_hdr->intra_edge_filter,
1274
6.05M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
6.05M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
6.05M
                                             t_dim->w * 4, t_dim->h * 4,
1277
6.05M
                                             angle | intra_flags,
1278
6.05M
                                             4 * f->bw - 4 * t->bx,
1279
6.05M
                                             4 * f->bh - 4 * t->by
1280
6.05M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
6.05M
                    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.08M
                skip_y_pred: {}
1293
6.08M
                    if (!b->skip) {
1294
2.17M
                        coef *cf;
1295
2.17M
                        int eob;
1296
2.17M
                        enum TxfmType txtp;
1297
2.17M
                        if (t->frame_thread.pass) {
1298
2.17M
                            const int p = t->frame_thread.pass & 1;
1299
2.17M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
2.17M
                            cf = ts->frame_thread[p].cf;
1301
2.17M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
2.17M
                            eob  = cbi >> 5;
1303
2.17M
                            txtp = cbi & 0x1f;
1304
2.17M
                        } 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
2.17M
                        if (eob >= 0) {
1317
1.60M
                            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.60M
                            dsp->itx.itxfm_add[b->tx]
1321
1.60M
                                              [txtp](dst,
1322
1.60M
                                                     f->cur.stride[0],
1323
1.60M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.60M
                            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.60M
                        }
1328
3.90M
                    } 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.08M
                    dst += 4 * t_dim->w;
1333
6.08M
                }
1334
3.70M
                t->bx -= x;
1335
3.70M
            }
1336
3.01M
            t->by -= y;
1337
1338
3.01M
            if (!has_chroma) continue;
1339
1340
2.11M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
2.11M
            if (b->uv_mode == CFL_PRED) {
1343
403k
                assert(!init_x && !init_y);
1344
1345
403k
                int16_t *const ac = t->scratch.ac;
1346
403k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
403k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
403k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
403k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
403k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
403k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
403k
                const int furthest_r =
1354
403k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
403k
                const int furthest_b =
1356
403k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
403k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
403k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
403k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
403k
                                                         cbw4 * 4, cbh4 * 4);
1361
1.21M
                for (int pl = 0; pl < 2; pl++) {
1362
806k
                    if (!b->cfl_alpha[pl]) continue;
1363
644k
                    int angle = 0;
1364
644k
                    const pixel *top_sb_edge = NULL;
1365
644k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
174k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
174k
                        const int sby = t->by >> f->sb_shift;
1368
174k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
174k
                    }
1370
644k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
644k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
644k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
644k
                    const enum IntraPredMode m =
1374
644k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
644k
                                                          ypos, ypos > ystart,
1376
644k
                                                          ts->tiling.col_end >> ss_hor,
1377
644k
                                                          ts->tiling.row_end >> ss_ver,
1378
644k
                                                          0, uv_dst[pl], stride,
1379
644k
                                                          top_sb_edge, DC_PRED, &angle,
1380
644k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
644k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
644k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
644k
                                           uv_t_dim->w * 4,
1384
644k
                                           uv_t_dim->h * 4,
1385
644k
                                           ac, b->cfl_alpha[pl]
1386
644k
                                           HIGHBD_CALL_SUFFIX);
1387
644k
                }
1388
403k
                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.71M
            } else if (b->pal_sz[1]) {
1394
6.04k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
6.04k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
6.04k
                const pixel (*pal)[8];
1397
6.04k
                const uint8_t *pal_idx;
1398
6.04k
                if (t->frame_thread.pass) {
1399
6.04k
                    const int p = t->frame_thread.pass & 1;
1400
6.04k
                    assert(ts->frame_thread[p].pal_idx);
1401
6.04k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
6.04k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
6.04k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
6.04k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
6.04k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
6.04k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
6.04k
                                       f->cur.stride[1], pal[1],
1412
6.04k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
6.04k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
6.04k
                                       f->cur.stride[1], pal[2],
1415
6.04k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
6.04k
                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
6.04k
            }
1425
1426
2.11M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
2.11M
                                 sm_uv_flag(&t->l, cby4);
1428
2.11M
            const int uv_sb_has_tr =
1429
2.11M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
2.03M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
2.11M
            const int uv_sb_has_bl =
1432
2.11M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
2.03M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
2.11M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
6.35M
            for (int pl = 0; pl < 2; pl++) {
1436
8.90M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
4.67M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
4.67M
                {
1439
4.67M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
4.67M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
4.67M
                                        ((t->bx + init_x) >> ss_hor));
1442
10.8M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
6.12M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
6.12M
                    {
1445
6.12M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
5.48M
                            b->pal_sz[1])
1447
658k
                        {
1448
658k
                            goto skip_uv_pred;
1449
658k
                        }
1450
1451
5.46M
                        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
5.46M
                        const enum EdgeFlags edge_flags =
1456
5.46M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
2.66M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
3.96M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
5.46M
                            ((x > (init_x >> ss_hor) ||
1460
4.01M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
3.43M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
5.46M
                        const pixel *top_sb_edge = NULL;
1463
5.46M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
1.47M
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
1.47M
                            const int sby = t->by >> f->sb_shift;
1466
1.47M
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
1.47M
                        }
1468
5.46M
                        const enum IntraPredMode uv_mode =
1469
5.46M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
5.46M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
5.46M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
5.46M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
5.46M
                        const enum IntraPredMode m =
1474
5.46M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
5.46M
                                                              ypos, ypos > ystart,
1476
5.46M
                                                              ts->tiling.col_end >> ss_hor,
1477
5.46M
                                                              ts->tiling.row_end >> ss_ver,
1478
5.46M
                                                              edge_flags, dst, stride,
1479
5.46M
                                                              top_sb_edge, uv_mode,
1480
5.46M
                                                              &angle, uv_t_dim->w,
1481
5.46M
                                                              uv_t_dim->h,
1482
5.46M
                                                              f->seq_hdr->intra_edge_filter,
1483
5.46M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
5.46M
                        angle |= intra_edge_filter_flag;
1485
5.46M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
5.46M
                                                 uv_t_dim->w * 4,
1487
5.46M
                                                 uv_t_dim->h * 4,
1488
5.46M
                                                 angle | sm_uv_fl,
1489
5.46M
                                                 (4 * f->bw + ss_hor -
1490
5.46M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
5.46M
                                                 (4 * f->bh + ss_ver -
1492
5.46M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
5.46M
                                                 HIGHBD_CALL_SUFFIX);
1494
5.46M
                        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
6.12M
                    skip_uv_pred: {}
1505
6.12M
                        if (!b->skip) {
1506
2.05M
                            enum TxfmType txtp;
1507
2.05M
                            int eob;
1508
2.05M
                            coef *cf;
1509
2.05M
                            if (t->frame_thread.pass) {
1510
2.05M
                                const int p = t->frame_thread.pass & 1;
1511
2.05M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
2.05M
                                cf = ts->frame_thread[p].cf;
1513
2.05M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
2.05M
                                eob  = cbi >> 5;
1515
2.05M
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
2.05M
                            if (eob >= 0) {
1533
656k
                                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
656k
                                dsp->itx.itxfm_add[b->uvtx]
1537
656k
                                                  [txtp](dst, stride,
1538
656k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
656k
                                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
656k
                            }
1543
4.07M
                        } 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
6.12M
                        dst += uv_t_dim->w * 4;
1548
6.12M
                    }
1549
4.67M
                    t->bx -= x << ss_hor;
1550
4.67M
                }
1551
4.23M
                t->by -= y << ss_ver;
1552
4.23M
            }
1553
2.11M
        }
1554
2.90M
    }
1555
2.82M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
1.32M
{
1180
1.32M
    Dav1dTileState *const ts = t->ts;
1181
1.32M
    const Dav1dFrameContext *const f = t->f;
1182
1.32M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.32M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.32M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.32M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.32M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.32M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.32M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.32M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.32M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.32M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.15M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.07M
                           (bh4 > ss_ver || t->by & 1);
1194
1.32M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.32M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.32M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.32M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.32M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.68M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.35M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.35M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.76M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.40M
            if (b->pal_sz[0]) {
1208
8.86k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
8.86k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
8.86k
                const uint8_t *pal_idx;
1211
8.86k
                if (t->frame_thread.pass) {
1212
8.86k
                    const int p = t->frame_thread.pass & 1;
1213
8.86k
                    assert(ts->frame_thread[p].pal_idx);
1214
8.86k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
8.86k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
8.86k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
8.86k
                const pixel *const pal = t->frame_thread.pass ?
1220
8.86k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
8.86k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
8.86k
                    bytefn(t->scratch.pal)[0];
1223
8.86k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
8.86k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
8.86k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
8.86k
            }
1229
1230
1.40M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.40M
                                     sm_flag(&t->l, by4) |
1232
1.40M
                                     intra_edge_filter_flag);
1233
1.40M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.35M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.40M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.35M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.40M
            int y, x;
1238
1.40M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.09M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.69M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.69M
            {
1242
1.69M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.69M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.69M
                                    t->bx + init_x);
1245
4.16M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.47M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.47M
                {
1248
2.47M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.46M
                    int angle = b->y_angle;
1251
2.46M
                    const enum EdgeFlags edge_flags =
1252
2.46M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.75M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.46M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.57M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.46M
                    const pixel *top_sb_edge = NULL;
1257
2.46M
                    if (!(t->by & (f->sb_step - 1))) {
1258
565k
                        top_sb_edge = f->ipred_edge[0];
1259
565k
                        const int sby = t->by >> f->sb_shift;
1260
565k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
565k
                    }
1262
2.46M
                    const enum IntraPredMode m =
1263
2.46M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.46M
                                                          t->bx > ts->tiling.col_start,
1265
2.46M
                                                          t->by,
1266
2.46M
                                                          t->by > ts->tiling.row_start,
1267
2.46M
                                                          ts->tiling.col_end,
1268
2.46M
                                                          ts->tiling.row_end,
1269
2.46M
                                                          edge_flags, dst,
1270
2.46M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.46M
                                                          b->y_mode, &angle,
1272
2.46M
                                                          t_dim->w, t_dim->h,
1273
2.46M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.46M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.46M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.46M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.46M
                                             angle | intra_flags,
1278
2.46M
                                             4 * f->bw - 4 * t->bx,
1279
2.46M
                                             4 * f->bh - 4 * t->by
1280
2.46M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.46M
                    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.47M
                skip_y_pred: {}
1293
2.47M
                    if (!b->skip) {
1294
776k
                        coef *cf;
1295
776k
                        int eob;
1296
776k
                        enum TxfmType txtp;
1297
776k
                        if (t->frame_thread.pass) {
1298
776k
                            const int p = t->frame_thread.pass & 1;
1299
776k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
776k
                            cf = ts->frame_thread[p].cf;
1301
776k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
776k
                            eob  = cbi >> 5;
1303
776k
                            txtp = cbi & 0x1f;
1304
776k
                        } 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
776k
                        if (eob >= 0) {
1317
567k
                            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
567k
                            dsp->itx.itxfm_add[b->tx]
1321
567k
                                              [txtp](dst,
1322
567k
                                                     f->cur.stride[0],
1323
567k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
567k
                            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
567k
                        }
1328
1.70M
                    } 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.47M
                    dst += 4 * t_dim->w;
1333
2.47M
                }
1334
1.69M
                t->bx -= x;
1335
1.69M
            }
1336
1.40M
            t->by -= y;
1337
1338
1.40M
            if (!has_chroma) continue;
1339
1340
1.06M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.06M
            if (b->uv_mode == CFL_PRED) {
1343
197k
                assert(!init_x && !init_y);
1344
1345
197k
                int16_t *const ac = t->scratch.ac;
1346
197k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
197k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
197k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
197k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
197k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
197k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
197k
                const int furthest_r =
1354
197k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
197k
                const int furthest_b =
1356
197k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
197k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
197k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
197k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
197k
                                                         cbw4 * 4, cbh4 * 4);
1361
593k
                for (int pl = 0; pl < 2; pl++) {
1362
395k
                    if (!b->cfl_alpha[pl]) continue;
1363
316k
                    int angle = 0;
1364
316k
                    const pixel *top_sb_edge = NULL;
1365
316k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
80.9k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
80.9k
                        const int sby = t->by >> f->sb_shift;
1368
80.9k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
80.9k
                    }
1370
316k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
316k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
316k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
316k
                    const enum IntraPredMode m =
1374
316k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
316k
                                                          ypos, ypos > ystart,
1376
316k
                                                          ts->tiling.col_end >> ss_hor,
1377
316k
                                                          ts->tiling.row_end >> ss_ver,
1378
316k
                                                          0, uv_dst[pl], stride,
1379
316k
                                                          top_sb_edge, DC_PRED, &angle,
1380
316k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
316k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
316k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
316k
                                           uv_t_dim->w * 4,
1384
316k
                                           uv_t_dim->h * 4,
1385
316k
                                           ac, b->cfl_alpha[pl]
1386
316k
                                           HIGHBD_CALL_SUFFIX);
1387
316k
                }
1388
197k
                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
868k
            } else if (b->pal_sz[1]) {
1394
2.91k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.91k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.91k
                const pixel (*pal)[8];
1397
2.91k
                const uint8_t *pal_idx;
1398
2.91k
                if (t->frame_thread.pass) {
1399
2.91k
                    const int p = t->frame_thread.pass & 1;
1400
2.91k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.91k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.91k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.91k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.91k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.91k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.91k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.91k
                                       f->cur.stride[1], pal[1],
1412
2.91k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.91k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.91k
                                       f->cur.stride[1], pal[2],
1415
2.91k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.91k
                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.91k
            }
1425
1426
1.06M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.06M
                                 sm_uv_flag(&t->l, cby4);
1428
1.06M
            const int uv_sb_has_tr =
1429
1.06M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.01M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.06M
            const int uv_sb_has_bl =
1432
1.06M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.01M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.06M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.19M
            for (int pl = 0; pl < 2; pl++) {
1436
4.44M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.31M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.31M
                {
1439
2.31M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.31M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.31M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.09M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.78M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.78M
                    {
1445
2.78M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.46M
                            b->pal_sz[1])
1447
323k
                        {
1448
323k
                            goto skip_uv_pred;
1449
323k
                        }
1450
1451
2.45M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.45M
                        const enum EdgeFlags edge_flags =
1456
2.45M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.07M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.74M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.45M
                            ((x > (init_x >> ss_hor) ||
1460
1.98M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.49M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.45M
                        const pixel *top_sb_edge = NULL;
1463
2.45M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
715k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
715k
                            const int sby = t->by >> f->sb_shift;
1466
715k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
715k
                        }
1468
2.45M
                        const enum IntraPredMode uv_mode =
1469
2.45M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.45M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.45M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.45M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.45M
                        const enum IntraPredMode m =
1474
2.45M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.45M
                                                              ypos, ypos > ystart,
1476
2.45M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.45M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.45M
                                                              edge_flags, dst, stride,
1479
2.45M
                                                              top_sb_edge, uv_mode,
1480
2.45M
                                                              &angle, uv_t_dim->w,
1481
2.45M
                                                              uv_t_dim->h,
1482
2.45M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.45M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.45M
                        angle |= intra_edge_filter_flag;
1485
2.45M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.45M
                                                 uv_t_dim->w * 4,
1487
2.45M
                                                 uv_t_dim->h * 4,
1488
2.45M
                                                 angle | sm_uv_fl,
1489
2.45M
                                                 (4 * f->bw + ss_hor -
1490
2.45M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.45M
                                                 (4 * f->bh + ss_ver -
1492
2.45M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.45M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.45M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.78M
                    skip_uv_pred: {}
1505
2.78M
                        if (!b->skip) {
1506
969k
                            enum TxfmType txtp;
1507
969k
                            int eob;
1508
969k
                            coef *cf;
1509
969k
                            if (t->frame_thread.pass) {
1510
969k
                                const int p = t->frame_thread.pass & 1;
1511
969k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
969k
                                cf = ts->frame_thread[p].cf;
1513
969k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
969k
                                eob  = cbi >> 5;
1515
969k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
969k
                            if (eob >= 0) {
1533
291k
                                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
291k
                                dsp->itx.itxfm_add[b->uvtx]
1537
291k
                                                  [txtp](dst, stride,
1538
291k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
291k
                                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
291k
                            }
1543
1.81M
                        } 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.78M
                        dst += uv_t_dim->w * 4;
1548
2.78M
                    }
1549
2.31M
                    t->bx -= x << ss_hor;
1550
2.31M
                }
1551
2.13M
                t->by -= y << ss_ver;
1552
2.13M
            }
1553
1.06M
        }
1554
1.35M
    }
1555
1.32M
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
1.50M
{
1180
1.50M
    Dav1dTileState *const ts = t->ts;
1181
1.50M
    const Dav1dFrameContext *const f = t->f;
1182
1.50M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.50M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.50M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.50M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.50M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.50M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.50M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.50M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.50M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.50M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.13M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.06M
                           (bh4 > ss_ver || t->by & 1);
1194
1.50M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.50M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.50M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.50M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.50M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
3.04M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.54M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.54M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.14M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.60M
            if (b->pal_sz[0]) {
1208
14.0k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
14.0k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
14.0k
                const uint8_t *pal_idx;
1211
14.0k
                if (t->frame_thread.pass) {
1212
14.0k
                    const int p = t->frame_thread.pass & 1;
1213
14.0k
                    assert(ts->frame_thread[p].pal_idx);
1214
14.0k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
14.0k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
14.0k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
14.0k
                const pixel *const pal = t->frame_thread.pass ?
1220
14.0k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
14.0k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
14.0k
                    bytefn(t->scratch.pal)[0];
1223
14.0k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
14.0k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
14.0k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
14.0k
            }
1229
1230
1.60M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.60M
                                     sm_flag(&t->l, by4) |
1232
1.60M
                                     intra_edge_filter_flag);
1233
1.60M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.54M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.60M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.54M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.60M
            int y, x;
1238
1.60M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.61M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
2.01M
                 y += t_dim->h, t->by += t_dim->h)
1241
2.01M
            {
1242
2.01M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
2.01M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
2.01M
                                    t->bx + init_x);
1245
5.61M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.60M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.60M
                {
1248
3.60M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.58M
                    int angle = b->y_angle;
1251
3.58M
                    const enum EdgeFlags edge_flags =
1252
3.58M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.64M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.58M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.45M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.58M
                    const pixel *top_sb_edge = NULL;
1257
3.58M
                    if (!(t->by & (f->sb_step - 1))) {
1258
621k
                        top_sb_edge = f->ipred_edge[0];
1259
621k
                        const int sby = t->by >> f->sb_shift;
1260
621k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
621k
                    }
1262
3.58M
                    const enum IntraPredMode m =
1263
3.58M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.58M
                                                          t->bx > ts->tiling.col_start,
1265
3.58M
                                                          t->by,
1266
3.58M
                                                          t->by > ts->tiling.row_start,
1267
3.58M
                                                          ts->tiling.col_end,
1268
3.58M
                                                          ts->tiling.row_end,
1269
3.58M
                                                          edge_flags, dst,
1270
3.58M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.58M
                                                          b->y_mode, &angle,
1272
3.58M
                                                          t_dim->w, t_dim->h,
1273
3.58M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.58M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.58M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.58M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.58M
                                             angle | intra_flags,
1278
3.58M
                                             4 * f->bw - 4 * t->bx,
1279
3.58M
                                             4 * f->bh - 4 * t->by
1280
3.58M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.58M
                    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
3.60M
                skip_y_pred: {}
1293
3.60M
                    if (!b->skip) {
1294
1.39M
                        coef *cf;
1295
1.39M
                        int eob;
1296
1.39M
                        enum TxfmType txtp;
1297
1.39M
                        if (t->frame_thread.pass) {
1298
1.39M
                            const int p = t->frame_thread.pass & 1;
1299
1.39M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.39M
                            cf = ts->frame_thread[p].cf;
1301
1.39M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.39M
                            eob  = cbi >> 5;
1303
1.39M
                            txtp = cbi & 0x1f;
1304
1.39M
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
1.39M
                        if (eob >= 0) {
1317
1.04M
                            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.04M
                            dsp->itx.itxfm_add[b->tx]
1321
1.04M
                                              [txtp](dst,
1322
1.04M
                                                     f->cur.stride[0],
1323
1.04M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.04M
                            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.04M
                        }
1328
2.20M
                    } 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
3.60M
                    dst += 4 * t_dim->w;
1333
3.60M
                }
1334
2.01M
                t->bx -= x;
1335
2.01M
            }
1336
1.60M
            t->by -= y;
1337
1338
1.60M
            if (!has_chroma) continue;
1339
1340
1.05M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.05M
            if (b->uv_mode == CFL_PRED) {
1343
205k
                assert(!init_x && !init_y);
1344
1345
205k
                int16_t *const ac = t->scratch.ac;
1346
205k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
205k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
205k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
205k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
205k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
205k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
205k
                const int furthest_r =
1354
205k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
205k
                const int furthest_b =
1356
205k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
205k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
205k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
205k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
205k
                                                         cbw4 * 4, cbh4 * 4);
1361
616k
                for (int pl = 0; pl < 2; pl++) {
1362
411k
                    if (!b->cfl_alpha[pl]) continue;
1363
327k
                    int angle = 0;
1364
327k
                    const pixel *top_sb_edge = NULL;
1365
327k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
93.2k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
93.2k
                        const int sby = t->by >> f->sb_shift;
1368
93.2k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
93.2k
                    }
1370
327k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
327k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
327k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
327k
                    const enum IntraPredMode m =
1374
327k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
327k
                                                          ypos, ypos > ystart,
1376
327k
                                                          ts->tiling.col_end >> ss_hor,
1377
327k
                                                          ts->tiling.row_end >> ss_ver,
1378
327k
                                                          0, uv_dst[pl], stride,
1379
327k
                                                          top_sb_edge, DC_PRED, &angle,
1380
327k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
327k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
327k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
327k
                                           uv_t_dim->w * 4,
1384
327k
                                           uv_t_dim->h * 4,
1385
327k
                                           ac, b->cfl_alpha[pl]
1386
327k
                                           HIGHBD_CALL_SUFFIX);
1387
327k
                }
1388
205k
                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
845k
            } else if (b->pal_sz[1]) {
1394
3.13k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.13k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.13k
                const pixel (*pal)[8];
1397
3.13k
                const uint8_t *pal_idx;
1398
3.13k
                if (t->frame_thread.pass) {
1399
3.13k
                    const int p = t->frame_thread.pass & 1;
1400
3.13k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.13k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.13k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.13k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.13k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.13k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.13k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.13k
                                       f->cur.stride[1], pal[1],
1412
3.13k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.13k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.13k
                                       f->cur.stride[1], pal[2],
1415
3.13k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.13k
                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.13k
            }
1425
1426
1.05M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.05M
                                 sm_uv_flag(&t->l, cby4);
1428
1.05M
            const int uv_sb_has_tr =
1429
1.05M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.01M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.05M
            const int uv_sb_has_bl =
1432
1.05M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.01M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.05M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.15M
            for (int pl = 0; pl < 2; pl++) {
1436
4.46M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.36M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.36M
                {
1439
2.36M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.36M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.36M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.70M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
3.34M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
3.34M
                    {
1445
3.34M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
3.01M
                            b->pal_sz[1])
1447
334k
                        {
1448
334k
                            goto skip_uv_pred;
1449
334k
                        }
1450
1451
3.01M
                        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
3.01M
                        const enum EdgeFlags edge_flags =
1456
3.01M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.58M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
2.21M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
3.01M
                            ((x > (init_x >> ss_hor) ||
1460
2.02M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.94M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
3.01M
                        const pixel *top_sb_edge = NULL;
1463
3.01M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
758k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
758k
                            const int sby = t->by >> f->sb_shift;
1466
758k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
758k
                        }
1468
3.01M
                        const enum IntraPredMode uv_mode =
1469
3.01M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
3.01M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
3.01M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
3.01M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
3.01M
                        const enum IntraPredMode m =
1474
3.01M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
3.01M
                                                              ypos, ypos > ystart,
1476
3.01M
                                                              ts->tiling.col_end >> ss_hor,
1477
3.01M
                                                              ts->tiling.row_end >> ss_ver,
1478
3.01M
                                                              edge_flags, dst, stride,
1479
3.01M
                                                              top_sb_edge, uv_mode,
1480
3.01M
                                                              &angle, uv_t_dim->w,
1481
3.01M
                                                              uv_t_dim->h,
1482
3.01M
                                                              f->seq_hdr->intra_edge_filter,
1483
3.01M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
3.01M
                        angle |= intra_edge_filter_flag;
1485
3.01M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
3.01M
                                                 uv_t_dim->w * 4,
1487
3.01M
                                                 uv_t_dim->h * 4,
1488
3.01M
                                                 angle | sm_uv_fl,
1489
3.01M
                                                 (4 * f->bw + ss_hor -
1490
3.01M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
3.01M
                                                 (4 * f->bh + ss_ver -
1492
3.01M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
3.01M
                                                 HIGHBD_CALL_SUFFIX);
1494
3.01M
                        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
3.34M
                    skip_uv_pred: {}
1505
3.34M
                        if (!b->skip) {
1506
1.08M
                            enum TxfmType txtp;
1507
1.08M
                            int eob;
1508
1.08M
                            coef *cf;
1509
1.08M
                            if (t->frame_thread.pass) {
1510
1.08M
                                const int p = t->frame_thread.pass & 1;
1511
1.08M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.08M
                                cf = ts->frame_thread[p].cf;
1513
1.08M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.08M
                                eob  = cbi >> 5;
1515
1.08M
                                txtp = cbi & 0x1f;
1516
1.08M
                            } 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.08M
                            if (eob >= 0) {
1533
364k
                                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
364k
                                dsp->itx.itxfm_add[b->uvtx]
1537
364k
                                                  [txtp](dst, stride,
1538
364k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
364k
                                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
364k
                            }
1543
2.26M
                        } 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
3.34M
                        dst += uv_t_dim->w * 4;
1548
3.34M
                    }
1549
2.36M
                    t->bx -= x << ss_hor;
1550
2.36M
                }
1551
2.10M
                t->by -= y << ss_ver;
1552
2.10M
            }
1553
1.05M
        }
1554
1.54M
    }
1555
1.50M
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
1.25M
{
1560
1.25M
    Dav1dTileState *const ts = t->ts;
1561
1.25M
    const Dav1dFrameContext *const f = t->f;
1562
1.25M
    const Dav1dDSPContext *const dsp = f->dsp;
1563
1.25M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
1.25M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
1.25M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
1.25M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
1.25M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
1.25M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
1.25M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
1.25M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
886k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
837k
                           (bh4 > ss_ver || t->by & 1);
1573
1.25M
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
1.25M
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
1.25M
    int res;
1576
1577
    // prediction
1578
1.25M
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
1.25M
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
1.25M
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
1.25M
    const ptrdiff_t uvdstoff =
1582
1.25M
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
1.25M
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
382k
        assert(!f->frame_hdr->super_res.enabled);
1586
382k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
382k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
382k
        if (res) return res;
1589
574k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
383k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
383k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
383k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
383k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
383k
            if (res) return res;
1595
383k
        }
1596
873k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
743k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
743k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
743k
        if (imin(bw4, bh4) > 1 &&
1601
458k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
444k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
18.9k
        {
1604
18.9k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
18.9k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
18.9k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
18.9k
            if (res) return res;
1608
724k
        } else {
1609
724k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
724k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
724k
            if (res) return res;
1612
724k
            if (b->motion_mode == MM_OBMC) {
1613
137k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
137k
                if (res) return res;
1615
137k
            }
1616
724k
        }
1617
743k
        if (b->interintra_type) {
1618
29.7k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
29.7k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
24.5k
                                   SMOOTH_PRED : b->interintra_mode;
1621
29.7k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
29.7k
            int angle = 0;
1623
29.7k
            const pixel *top_sb_edge = NULL;
1624
29.7k
            if (!(t->by & (f->sb_step - 1))) {
1625
8.95k
                top_sb_edge = f->ipred_edge[0];
1626
8.95k
                const int sby = t->by >> f->sb_shift;
1627
8.95k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
8.95k
            }
1629
29.7k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
29.7k
                                                  t->by, t->by > ts->tiling.row_start,
1631
29.7k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
29.7k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
29.7k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
29.7k
                                                  HIGHBD_CALL_SUFFIX);
1635
29.7k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
29.7k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
29.7k
                                     HIGHBD_CALL_SUFFIX);
1638
29.7k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
29.7k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
29.7k
        }
1641
1642
743k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
493k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
493k
        refmvs_block *const *r;
1647
493k
        if (is_sub8x8) {
1648
49.2k
            assert(ss_hor == 1);
1649
49.2k
            r = &t->rt.r[(t->by & 31) + 5];
1650
49.2k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
49.2k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
49.2k
            if (bw4 == 1 && bh4 == ss_ver)
1653
8.58k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
49.2k
        }
1655
1656
        // chroma prediction
1657
493k
        if (is_sub8x8) {
1658
47.1k
            assert(ss_hor == 1);
1659
47.1k
            ptrdiff_t h_off = 0, v_off = 0;
1660
47.1k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
23.0k
                for (int pl = 0; pl < 2; pl++) {
1662
15.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
15.3k
                             NULL, f->cur.stride[1],
1664
15.3k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
15.3k
                             r[-1][t->bx - 1].mv.mv[0],
1666
15.3k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
15.3k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
15.3k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
15.3k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
15.3k
                    if (res) return res;
1671
15.3k
                }
1672
7.67k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
7.67k
                h_off = 2;
1674
7.67k
            }
1675
47.1k
            if (bw4 == 1) {
1676
25.0k
                const enum Filter2d left_filter_2d =
1677
25.0k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
75.2k
                for (int pl = 0; pl < 2; pl++) {
1679
50.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
50.1k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
50.1k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
50.1k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
50.1k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
50.1k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
50.1k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
50.1k
                    if (res) return res;
1687
50.1k
                }
1688
25.0k
                h_off = 2;
1689
25.0k
            }
1690
47.1k
            if (bh4 == ss_ver) {
1691
29.7k
                const enum Filter2d top_filter_2d =
1692
29.7k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
89.2k
                for (int pl = 0; pl < 2; pl++) {
1694
59.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
59.4k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
59.4k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
59.4k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
59.4k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
59.4k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
59.4k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
59.4k
                    if (res) return res;
1702
59.4k
                }
1703
29.7k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
29.7k
            }
1705
141k
            for (int pl = 0; pl < 2; pl++) {
1706
94.3k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
94.3k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
94.3k
                         refp, b->ref[0], filter_2d);
1709
94.3k
                if (res) return res;
1710
94.3k
            }
1711
446k
        } else {
1712
446k
            if (imin(cbw4, cbh4) > 1 &&
1713
242k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
233k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
12.6k
            {
1716
37.8k
                for (int pl = 0; pl < 2; pl++) {
1717
25.2k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
25.2k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
25.2k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
25.2k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
25.2k
                    if (res) return res;
1722
25.2k
                }
1723
433k
            } else {
1724
1.30M
                for (int pl = 0; pl < 2; pl++) {
1725
866k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
866k
                             NULL, f->cur.stride[1],
1727
866k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
866k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
866k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
866k
                    if (res) return res;
1731
866k
                    if (b->motion_mode == MM_OBMC) {
1732
218k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
218k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
218k
                        if (res) return res;
1735
218k
                    }
1736
866k
                }
1737
433k
            }
1738
446k
            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
26.6k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
79.8k
                for (int pl = 0; pl < 2; pl++) {
1745
53.2k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
53.2k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
53.2k
                    enum IntraPredMode m =
1748
53.2k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
44.0k
                        SMOOTH_PRED : b->interintra_mode;
1750
53.2k
                    int angle = 0;
1751
53.2k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
53.2k
                    const pixel *top_sb_edge = NULL;
1753
53.2k
                    if (!(t->by & (f->sb_step - 1))) {
1754
14.6k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
14.6k
                        const int sby = t->by >> f->sb_shift;
1756
14.6k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
14.6k
                    }
1758
53.2k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
53.2k
                                                          (t->bx >> ss_hor) >
1760
53.2k
                                                              (ts->tiling.col_start >> ss_hor),
1761
53.2k
                                                          t->by >> ss_ver,
1762
53.2k
                                                          (t->by >> ss_ver) >
1763
53.2k
                                                              (ts->tiling.row_start >> ss_ver),
1764
53.2k
                                                          ts->tiling.col_end >> ss_hor,
1765
53.2k
                                                          ts->tiling.row_end >> ss_ver,
1766
53.2k
                                                          0, uvdst, f->cur.stride[1],
1767
53.2k
                                                          top_sb_edge, m,
1768
53.2k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
53.2k
                                                          HIGHBD_CALL_SUFFIX);
1770
53.2k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
53.2k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
53.2k
                                             HIGHBD_CALL_SUFFIX);
1773
53.2k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
53.2k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
53.2k
                }
1776
26.6k
            }
1777
446k
        }
1778
1779
743k
    skip_inter_chroma_pred: {}
1780
743k
        t->tl_4x4_filter = filter_2d;
1781
743k
    } else {
1782
130k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
130k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
130k
        int jnt_weight;
1786
130k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
130k
        const uint8_t *mask;
1788
1789
390k
        for (int i = 0; i < 2; i++) {
1790
260k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
260k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
9.29k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
9.29k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
9.29k
                if (res) return res;
1796
250k
            } else {
1797
250k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
250k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
250k
                if (res) return res;
1800
250k
            }
1801
260k
        }
1802
130k
        switch (b->comp_type) {
1803
97.6k
        case COMP_INTER_AVG:
1804
97.6k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
97.6k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
97.6k
            break;
1807
13.1k
        case COMP_INTER_WEIGHTED_AVG:
1808
13.1k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
13.1k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
13.1k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
13.1k
            break;
1812
13.5k
        case COMP_INTER_SEG:
1813
13.5k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
13.5k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
13.5k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
13.5k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
13.5k
            mask = seg_mask;
1818
13.5k
            break;
1819
5.84k
        case COMP_INTER_WEDGE:
1820
5.84k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
5.84k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
5.84k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
5.84k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
5.84k
            if (has_chroma)
1825
4.55k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
5.84k
            break;
1827
130k
        }
1828
1829
        // chroma
1830
315k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
630k
            for (int i = 0; i < 2; i++) {
1832
420k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
420k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
62.4k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
9.31k
                {
1836
9.31k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
9.31k
                                      b_dim, 1 + pl,
1838
9.31k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
9.31k
                    if (res) return res;
1840
411k
                } else {
1841
411k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
411k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
411k
                    if (res) return res;
1844
411k
                }
1845
420k
            }
1846
210k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
210k
            switch (b->comp_type) {
1848
160k
            case COMP_INTER_AVG:
1849
160k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
160k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
160k
                            HIGHBD_CALL_SUFFIX);
1852
160k
                break;
1853
18.1k
            case COMP_INTER_WEIGHTED_AVG:
1854
18.1k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
18.1k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
18.1k
                              HIGHBD_CALL_SUFFIX);
1857
18.1k
                break;
1858
9.10k
            case COMP_INTER_WEDGE:
1859
31.8k
            case COMP_INTER_SEG:
1860
31.8k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
31.8k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
31.8k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
31.8k
                             HIGHBD_CALL_SUFFIX);
1864
31.8k
                break;
1865
210k
            }
1866
210k
        }
1867
130k
    }
1868
1869
1.25M
    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
1.25M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
1.25M
    if (b->skip) {
1882
        // reset coef contexts
1883
494k
        BlockContext *const a = t->a;
1884
494k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
494k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
494k
        if (has_chroma) {
1887
312k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
312k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
312k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
312k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
312k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
312k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
312k
        }
1894
494k
        return 0;
1895
494k
    }
1896
1897
762k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
762k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
762k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
1.54M
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
1.58M
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
802k
            int y_off = !!init_y, y;
1905
802k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
1.62M
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
817k
                 y += ytx->h, y_off++)
1908
817k
            {
1909
817k
                int x, x_off = !!init_x;
1910
1.70M
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
883k
                     x += ytx->w, x_off++)
1912
883k
                {
1913
883k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
883k
                                   x_off, y_off, &dst[x * 4]);
1915
883k
                    t->bx += ytx->w;
1916
883k
                }
1917
817k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
817k
                t->bx -= x;
1919
817k
                t->by += ytx->h;
1920
817k
            }
1921
802k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
802k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
1.50M
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
1.00M
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
1.00M
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
1.00M
                for (y = init_y >> ss_ver, t->by += init_y;
1929
2.07M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
1.06M
                {
1931
1.06M
                    int x;
1932
1.06M
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
2.28M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
1.21M
                    {
1935
1.21M
                        coef *cf;
1936
1.21M
                        int eob;
1937
1.21M
                        enum TxfmType txtp;
1938
1.21M
                        if (t->frame_thread.pass) {
1939
1.21M
                            const int p = t->frame_thread.pass & 1;
1940
1.21M
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
1.21M
                            cf = ts->frame_thread[p].cf;
1942
1.21M
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
1.21M
                            eob  = cbi >> 5;
1944
1.21M
                            txtp = cbi & 0x1f;
1945
1.21M
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
1.21M
                        if (eob >= 0) {
1964
318k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
318k
                            dsp->itx.itxfm_add[b->uvtx]
1967
318k
                                              [txtp](&uvdst[4 * x],
1968
318k
                                                     f->cur.stride[1],
1969
318k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
318k
                            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
318k
                        }
1974
1.21M
                        t->bx += uvtx->w << ss_hor;
1975
1.21M
                    }
1976
1.06M
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
1.06M
                    t->bx -= x << ss_hor;
1978
1.06M
                    t->by += uvtx->h << ss_ver;
1979
1.06M
                }
1980
1.00M
                t->by -= y << ss_ver;
1981
1.00M
            }
1982
802k
        }
1983
781k
    }
1984
762k
    return 0;
1985
1.25M
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
624k
{
1560
624k
    Dav1dTileState *const ts = t->ts;
1561
624k
    const Dav1dFrameContext *const f = t->f;
1562
624k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
624k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
624k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
624k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
624k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
624k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
624k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
624k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
624k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
562k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
525k
                           (bh4 > ss_ver || t->by & 1);
1573
624k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
624k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
624k
    int res;
1576
1577
    // prediction
1578
624k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
624k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
624k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
624k
    const ptrdiff_t uvdstoff =
1582
624k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
624k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
195k
        assert(!f->frame_hdr->super_res.enabled);
1586
195k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
195k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
195k
        if (res) return res;
1589
457k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
305k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
305k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
305k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
305k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
305k
            if (res) return res;
1595
305k
        }
1596
428k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
362k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
362k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
362k
        if (imin(bw4, bh4) > 1 &&
1601
224k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
214k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
12.4k
        {
1604
12.4k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
12.4k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
12.4k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
12.4k
            if (res) return res;
1608
349k
        } else {
1609
349k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
349k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
349k
            if (res) return res;
1612
349k
            if (b->motion_mode == MM_OBMC) {
1613
70.2k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
70.2k
                if (res) return res;
1615
70.2k
            }
1616
349k
        }
1617
362k
        if (b->interintra_type) {
1618
13.0k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
13.0k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
10.7k
                                   SMOOTH_PRED : b->interintra_mode;
1621
13.0k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
13.0k
            int angle = 0;
1623
13.0k
            const pixel *top_sb_edge = NULL;
1624
13.0k
            if (!(t->by & (f->sb_step - 1))) {
1625
3.95k
                top_sb_edge = f->ipred_edge[0];
1626
3.95k
                const int sby = t->by >> f->sb_shift;
1627
3.95k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
3.95k
            }
1629
13.0k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
13.0k
                                                  t->by, t->by > ts->tiling.row_start,
1631
13.0k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
13.0k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
13.0k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
13.0k
                                                  HIGHBD_CALL_SUFFIX);
1635
13.0k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
13.0k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
13.0k
                                     HIGHBD_CALL_SUFFIX);
1638
13.0k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
13.0k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
13.0k
        }
1641
1642
362k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
281k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
281k
        refmvs_block *const *r;
1647
281k
        if (is_sub8x8) {
1648
29.5k
            assert(ss_hor == 1);
1649
29.5k
            r = &t->rt.r[(t->by & 31) + 5];
1650
29.5k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
29.5k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
29.5k
            if (bw4 == 1 && bh4 == ss_ver)
1653
5.67k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
29.5k
        }
1655
1656
        // chroma prediction
1657
281k
        if (is_sub8x8) {
1658
28.3k
            assert(ss_hor == 1);
1659
28.3k
            ptrdiff_t h_off = 0, v_off = 0;
1660
28.3k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
15.2k
                for (int pl = 0; pl < 2; pl++) {
1662
10.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
10.1k
                             NULL, f->cur.stride[1],
1664
10.1k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
10.1k
                             r[-1][t->bx - 1].mv.mv[0],
1666
10.1k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
10.1k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
10.1k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
10.1k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
10.1k
                    if (res) return res;
1671
10.1k
                }
1672
5.07k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
5.07k
                h_off = 2;
1674
5.07k
            }
1675
28.3k
            if (bw4 == 1) {
1676
16.7k
                const enum Filter2d left_filter_2d =
1677
16.7k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
50.1k
                for (int pl = 0; pl < 2; pl++) {
1679
33.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
33.4k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
33.4k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
33.4k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
33.4k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
33.4k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
33.4k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
33.4k
                    if (res) return res;
1687
33.4k
                }
1688
16.7k
                h_off = 2;
1689
16.7k
            }
1690
28.3k
            if (bh4 == ss_ver) {
1691
16.6k
                const enum Filter2d top_filter_2d =
1692
16.6k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
50.0k
                for (int pl = 0; pl < 2; pl++) {
1694
33.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
33.3k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
33.3k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
33.3k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
33.3k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
33.3k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
33.3k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
33.3k
                    if (res) return res;
1702
33.3k
                }
1703
16.6k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
16.6k
            }
1705
84.9k
            for (int pl = 0; pl < 2; pl++) {
1706
56.6k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
56.6k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
56.6k
                         refp, b->ref[0], filter_2d);
1709
56.6k
                if (res) return res;
1710
56.6k
            }
1711
252k
        } else {
1712
252k
            if (imin(cbw4, cbh4) > 1 &&
1713
133k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
126k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
8.47k
            {
1716
25.4k
                for (int pl = 0; pl < 2; pl++) {
1717
16.9k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
16.9k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
16.9k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
16.9k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
16.9k
                    if (res) return res;
1722
16.9k
                }
1723
244k
            } else {
1724
732k
                for (int pl = 0; pl < 2; pl++) {
1725
488k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
488k
                             NULL, f->cur.stride[1],
1727
488k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
488k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
488k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
488k
                    if (res) return res;
1731
488k
                    if (b->motion_mode == MM_OBMC) {
1732
128k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
128k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
128k
                        if (res) return res;
1735
128k
                    }
1736
488k
                }
1737
244k
            }
1738
252k
            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
12.3k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
37.1k
                for (int pl = 0; pl < 2; pl++) {
1745
24.7k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
24.7k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
24.7k
                    enum IntraPredMode m =
1748
24.7k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
20.3k
                        SMOOTH_PRED : b->interintra_mode;
1750
24.7k
                    int angle = 0;
1751
24.7k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
24.7k
                    const pixel *top_sb_edge = NULL;
1753
24.7k
                    if (!(t->by & (f->sb_step - 1))) {
1754
7.15k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
7.15k
                        const int sby = t->by >> f->sb_shift;
1756
7.15k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
7.15k
                    }
1758
24.7k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
24.7k
                                                          (t->bx >> ss_hor) >
1760
24.7k
                                                              (ts->tiling.col_start >> ss_hor),
1761
24.7k
                                                          t->by >> ss_ver,
1762
24.7k
                                                          (t->by >> ss_ver) >
1763
24.7k
                                                              (ts->tiling.row_start >> ss_ver),
1764
24.7k
                                                          ts->tiling.col_end >> ss_hor,
1765
24.7k
                                                          ts->tiling.row_end >> ss_ver,
1766
24.7k
                                                          0, uvdst, f->cur.stride[1],
1767
24.7k
                                                          top_sb_edge, m,
1768
24.7k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
24.7k
                                                          HIGHBD_CALL_SUFFIX);
1770
24.7k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
24.7k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
24.7k
                                             HIGHBD_CALL_SUFFIX);
1773
24.7k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
24.7k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
24.7k
                }
1776
12.3k
            }
1777
252k
        }
1778
1779
362k
    skip_inter_chroma_pred: {}
1780
362k
        t->tl_4x4_filter = filter_2d;
1781
362k
    } else {
1782
66.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
66.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
66.5k
        int jnt_weight;
1786
66.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
66.5k
        const uint8_t *mask;
1788
1789
199k
        for (int i = 0; i < 2; i++) {
1790
133k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
133k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.30k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.30k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.30k
                if (res) return res;
1796
128k
            } else {
1797
128k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
128k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
128k
                if (res) return res;
1800
128k
            }
1801
133k
        }
1802
66.5k
        switch (b->comp_type) {
1803
50.4k
        case COMP_INTER_AVG:
1804
50.4k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
50.4k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
50.4k
            break;
1807
4.68k
        case COMP_INTER_WEIGHTED_AVG:
1808
4.68k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
4.68k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
4.68k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
4.68k
            break;
1812
8.00k
        case COMP_INTER_SEG:
1813
8.00k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
8.00k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
8.00k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
8.00k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
8.00k
            mask = seg_mask;
1818
8.00k
            break;
1819
3.38k
        case COMP_INTER_WEDGE:
1820
3.38k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.38k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.38k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.38k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.38k
            if (has_chroma)
1825
2.88k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.38k
            break;
1827
66.5k
        }
1828
1829
        // chroma
1830
175k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
351k
            for (int i = 0; i < 2; i++) {
1832
234k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
234k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
31.9k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.50k
                {
1836
3.50k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.50k
                                      b_dim, 1 + pl,
1838
3.50k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.50k
                    if (res) return res;
1840
230k
                } else {
1841
230k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
230k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
230k
                    if (res) return res;
1844
230k
                }
1845
234k
            }
1846
117k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
117k
            switch (b->comp_type) {
1848
89.5k
            case COMP_INTER_AVG:
1849
89.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
89.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
89.5k
                            HIGHBD_CALL_SUFFIX);
1852
89.5k
                break;
1853
7.61k
            case COMP_INTER_WEIGHTED_AVG:
1854
7.61k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
7.61k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
7.61k
                              HIGHBD_CALL_SUFFIX);
1857
7.61k
                break;
1858
5.76k
            case COMP_INTER_WEDGE:
1859
19.8k
            case COMP_INTER_SEG:
1860
19.8k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
19.8k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
19.8k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
19.8k
                             HIGHBD_CALL_SUFFIX);
1864
19.8k
                break;
1865
117k
            }
1866
117k
        }
1867
66.5k
    }
1868
1869
624k
    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
624k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
624k
    if (b->skip) {
1882
        // reset coef contexts
1883
262k
        BlockContext *const a = t->a;
1884
262k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
262k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
262k
        if (has_chroma) {
1887
198k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
198k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
198k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
198k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
198k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
198k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
198k
        }
1894
262k
        return 0;
1895
262k
    }
1896
1897
361k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
361k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
361k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
733k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
753k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
382k
            int y_off = !!init_y, y;
1905
382k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
768k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
386k
                 y += ytx->h, y_off++)
1908
386k
            {
1909
386k
                int x, x_off = !!init_x;
1910
787k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
401k
                     x += ytx->w, x_off++)
1912
401k
                {
1913
401k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
401k
                                   x_off, y_off, &dst[x * 4]);
1915
401k
                    t->bx += ytx->w;
1916
401k
                }
1917
386k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
386k
                t->bx -= x;
1919
386k
                t->by += ytx->h;
1920
386k
            }
1921
382k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
382k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
936k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
624k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
624k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
624k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.27M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
648k
                {
1931
648k
                    int x;
1932
648k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.33M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
689k
                    {
1935
689k
                        coef *cf;
1936
689k
                        int eob;
1937
689k
                        enum TxfmType txtp;
1938
689k
                        if (t->frame_thread.pass) {
1939
689k
                            const int p = t->frame_thread.pass & 1;
1940
689k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
689k
                            cf = ts->frame_thread[p].cf;
1942
689k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
689k
                            eob  = cbi >> 5;
1944
689k
                            txtp = cbi & 0x1f;
1945
689k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
689k
                        if (eob >= 0) {
1964
166k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
166k
                            dsp->itx.itxfm_add[b->uvtx]
1967
166k
                                              [txtp](&uvdst[4 * x],
1968
166k
                                                     f->cur.stride[1],
1969
166k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
166k
                            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
166k
                        }
1974
689k
                        t->bx += uvtx->w << ss_hor;
1975
689k
                    }
1976
648k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
648k
                    t->bx -= x << ss_hor;
1978
648k
                    t->by += uvtx->h << ss_ver;
1979
648k
                }
1980
624k
                t->by -= y << ss_ver;
1981
624k
            }
1982
382k
        }
1983
371k
    }
1984
361k
    return 0;
1985
624k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
631k
{
1560
631k
    Dav1dTileState *const ts = t->ts;
1561
631k
    const Dav1dFrameContext *const f = t->f;
1562
631k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
631k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
631k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
631k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
631k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
631k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
631k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
631k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
631k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
324k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
312k
                           (bh4 > ss_ver || t->by & 1);
1573
631k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
631k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
631k
    int res;
1576
1577
    // prediction
1578
631k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
631k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
631k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
631k
    const ptrdiff_t uvdstoff =
1582
631k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
631k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
186k
        assert(!f->frame_hdr->super_res.enabled);
1586
186k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
186k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
186k
        if (res) return res;
1589
186k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
77.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
77.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
77.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
77.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
77.7k
            if (res) return res;
1595
77.7k
        }
1596
444k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
381k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
381k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
381k
        if (imin(bw4, bh4) > 1 &&
1601
233k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
230k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
6.41k
        {
1604
6.41k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
6.41k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
6.41k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
6.41k
            if (res) return res;
1608
375k
        } else {
1609
375k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
375k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
375k
            if (res) return res;
1612
375k
            if (b->motion_mode == MM_OBMC) {
1613
67.6k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
67.6k
                if (res) return res;
1615
67.6k
            }
1616
375k
        }
1617
381k
        if (b->interintra_type) {
1618
16.7k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
16.7k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
13.7k
                                   SMOOTH_PRED : b->interintra_mode;
1621
16.7k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
16.7k
            int angle = 0;
1623
16.7k
            const pixel *top_sb_edge = NULL;
1624
16.7k
            if (!(t->by & (f->sb_step - 1))) {
1625
5.00k
                top_sb_edge = f->ipred_edge[0];
1626
5.00k
                const int sby = t->by >> f->sb_shift;
1627
5.00k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
5.00k
            }
1629
16.7k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
16.7k
                                                  t->by, t->by > ts->tiling.row_start,
1631
16.7k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
16.7k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
16.7k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
16.7k
                                                  HIGHBD_CALL_SUFFIX);
1635
16.7k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
16.7k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
16.7k
                                     HIGHBD_CALL_SUFFIX);
1638
16.7k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
16.7k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
16.7k
        }
1641
1642
381k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
212k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
212k
        refmvs_block *const *r;
1647
212k
        if (is_sub8x8) {
1648
19.7k
            assert(ss_hor == 1);
1649
19.7k
            r = &t->rt.r[(t->by & 31) + 5];
1650
19.7k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
19.7k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
19.7k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.91k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
19.7k
        }
1655
1656
        // chroma prediction
1657
212k
        if (is_sub8x8) {
1658
18.8k
            assert(ss_hor == 1);
1659
18.8k
            ptrdiff_t h_off = 0, v_off = 0;
1660
18.8k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
7.80k
                for (int pl = 0; pl < 2; pl++) {
1662
5.20k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
5.20k
                             NULL, f->cur.stride[1],
1664
5.20k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
5.20k
                             r[-1][t->bx - 1].mv.mv[0],
1666
5.20k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
5.20k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
5.20k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
5.20k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
5.20k
                    if (res) return res;
1671
5.20k
                }
1672
2.60k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.60k
                h_off = 2;
1674
2.60k
            }
1675
18.8k
            if (bw4 == 1) {
1676
8.37k
                const enum Filter2d left_filter_2d =
1677
8.37k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
25.1k
                for (int pl = 0; pl < 2; pl++) {
1679
16.7k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
16.7k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
16.7k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
16.7k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
16.7k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
16.7k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
16.7k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
16.7k
                    if (res) return res;
1687
16.7k
                }
1688
8.37k
                h_off = 2;
1689
8.37k
            }
1690
18.8k
            if (bh4 == ss_ver) {
1691
13.0k
                const enum Filter2d top_filter_2d =
1692
13.0k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
39.2k
                for (int pl = 0; pl < 2; pl++) {
1694
26.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
26.1k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
26.1k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
26.1k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
26.1k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
26.1k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
26.1k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
26.1k
                    if (res) return res;
1702
26.1k
                }
1703
13.0k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
13.0k
            }
1705
56.5k
            for (int pl = 0; pl < 2; pl++) {
1706
37.6k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
37.6k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
37.6k
                         refp, b->ref[0], filter_2d);
1709
37.6k
                if (res) return res;
1710
37.6k
            }
1711
193k
        } else {
1712
193k
            if (imin(cbw4, cbh4) > 1 &&
1713
109k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
107k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
4.13k
            {
1716
12.4k
                for (int pl = 0; pl < 2; pl++) {
1717
8.27k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
8.27k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
8.27k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
8.27k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
8.27k
                    if (res) return res;
1722
8.27k
                }
1723
189k
            } else {
1724
567k
                for (int pl = 0; pl < 2; pl++) {
1725
378k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
378k
                             NULL, f->cur.stride[1],
1727
378k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
378k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
378k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
378k
                    if (res) return res;
1731
378k
                    if (b->motion_mode == MM_OBMC) {
1732
89.5k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
89.5k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
89.5k
                        if (res) return res;
1735
89.5k
                    }
1736
378k
                }
1737
189k
            }
1738
193k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
14.2k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
42.7k
                for (int pl = 0; pl < 2; pl++) {
1745
28.4k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
28.4k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
28.4k
                    enum IntraPredMode m =
1748
28.4k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
23.6k
                        SMOOTH_PRED : b->interintra_mode;
1750
28.4k
                    int angle = 0;
1751
28.4k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
28.4k
                    const pixel *top_sb_edge = NULL;
1753
28.4k
                    if (!(t->by & (f->sb_step - 1))) {
1754
7.46k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
7.46k
                        const int sby = t->by >> f->sb_shift;
1756
7.46k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
7.46k
                    }
1758
28.4k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
28.4k
                                                          (t->bx >> ss_hor) >
1760
28.4k
                                                              (ts->tiling.col_start >> ss_hor),
1761
28.4k
                                                          t->by >> ss_ver,
1762
28.4k
                                                          (t->by >> ss_ver) >
1763
28.4k
                                                              (ts->tiling.row_start >> ss_ver),
1764
28.4k
                                                          ts->tiling.col_end >> ss_hor,
1765
28.4k
                                                          ts->tiling.row_end >> ss_ver,
1766
28.4k
                                                          0, uvdst, f->cur.stride[1],
1767
28.4k
                                                          top_sb_edge, m,
1768
28.4k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
28.4k
                                                          HIGHBD_CALL_SUFFIX);
1770
28.4k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
28.4k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
28.4k
                                             HIGHBD_CALL_SUFFIX);
1773
28.4k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
28.4k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
28.4k
                }
1776
14.2k
            }
1777
193k
        }
1778
1779
381k
    skip_inter_chroma_pred: {}
1780
381k
        t->tl_4x4_filter = filter_2d;
1781
381k
    } else {
1782
63.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
63.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
63.5k
        int jnt_weight;
1786
63.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
63.5k
        const uint8_t *mask;
1788
1789
190k
        for (int i = 0; i < 2; i++) {
1790
127k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
127k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.99k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.99k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.99k
                if (res) return res;
1796
122k
            } else {
1797
122k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
122k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
122k
                if (res) return res;
1800
122k
            }
1801
127k
        }
1802
63.5k
        switch (b->comp_type) {
1803
47.1k
        case COMP_INTER_AVG:
1804
47.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
47.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
47.1k
            break;
1807
8.47k
        case COMP_INTER_WEIGHTED_AVG:
1808
8.47k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
8.47k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
8.47k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
8.47k
            break;
1812
5.49k
        case COMP_INTER_SEG:
1813
5.49k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
5.49k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
5.49k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
5.49k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
5.49k
            mask = seg_mask;
1818
5.49k
            break;
1819
2.46k
        case COMP_INTER_WEDGE:
1820
2.46k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.46k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.46k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.46k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.46k
            if (has_chroma)
1825
1.66k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.46k
            break;
1827
63.5k
        }
1828
1829
        // chroma
1830
139k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
279k
            for (int i = 0; i < 2; i++) {
1832
186k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
186k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
30.4k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
5.81k
                {
1836
5.81k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
5.81k
                                      b_dim, 1 + pl,
1838
5.81k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
5.81k
                    if (res) return res;
1840
180k
                } else {
1841
180k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
180k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
180k
                    if (res) return res;
1844
180k
                }
1845
186k
            }
1846
93.2k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
93.2k
            switch (b->comp_type) {
1848
70.8k
            case COMP_INTER_AVG:
1849
70.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
70.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
70.8k
                            HIGHBD_CALL_SUFFIX);
1852
70.8k
                break;
1853
10.5k
            case COMP_INTER_WEIGHTED_AVG:
1854
10.5k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
10.5k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
10.5k
                              HIGHBD_CALL_SUFFIX);
1857
10.5k
                break;
1858
3.33k
            case COMP_INTER_WEDGE:
1859
11.9k
            case COMP_INTER_SEG:
1860
11.9k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
11.9k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
11.9k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
11.9k
                             HIGHBD_CALL_SUFFIX);
1864
11.9k
                break;
1865
93.2k
            }
1866
93.2k
        }
1867
63.5k
    }
1868
1869
631k
    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
631k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
631k
    if (b->skip) {
1882
        // reset coef contexts
1883
231k
        BlockContext *const a = t->a;
1884
231k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
231k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
231k
        if (has_chroma) {
1887
114k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
114k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
114k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
114k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
114k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
114k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
114k
        }
1894
231k
        return 0;
1895
231k
    }
1896
1897
400k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
400k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
400k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
811k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
830k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
419k
            int y_off = !!init_y, y;
1905
419k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
851k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
431k
                 y += ytx->h, y_off++)
1908
431k
            {
1909
431k
                int x, x_off = !!init_x;
1910
913k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
481k
                     x += ytx->w, x_off++)
1912
481k
                {
1913
481k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
481k
                                   x_off, y_off, &dst[x * 4]);
1915
481k
                    t->bx += ytx->w;
1916
481k
                }
1917
431k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
431k
                t->bx -= x;
1919
431k
                t->by += ytx->h;
1920
431k
            }
1921
419k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
419k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
572k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
381k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
381k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
381k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
799k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
418k
                {
1931
418k
                    int x;
1932
418k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
944k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
526k
                    {
1935
526k
                        coef *cf;
1936
526k
                        int eob;
1937
526k
                        enum TxfmType txtp;
1938
526k
                        if (t->frame_thread.pass) {
1939
526k
                            const int p = t->frame_thread.pass & 1;
1940
526k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
526k
                            cf = ts->frame_thread[p].cf;
1942
526k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
526k
                            eob  = cbi >> 5;
1944
526k
                            txtp = cbi & 0x1f;
1945
526k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
526k
                        if (eob >= 0) {
1964
151k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
151k
                            dsp->itx.itxfm_add[b->uvtx]
1967
151k
                                              [txtp](&uvdst[4 * x],
1968
151k
                                                     f->cur.stride[1],
1969
151k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
151k
                            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
151k
                        }
1974
526k
                        t->bx += uvtx->w << ss_hor;
1975
526k
                    }
1976
418k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
418k
                    t->bx -= x << ss_hor;
1978
418k
                    t->by += uvtx->h << ss_ver;
1979
418k
                }
1980
381k
                t->by -= y << ss_ver;
1981
381k
            }
1982
419k
        }
1983
410k
    }
1984
400k
    return 0;
1985
631k
}
1986
1987
357k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
357k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
357k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
357k
    const int y = sby * f->sb_step * 4;
1994
357k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
357k
    pixel *const p[3] = {
1996
357k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
357k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
357k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
357k
    };
2000
357k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
357k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
357k
                                        f->lf.start_of_tile_row[sby]);
2003
357k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
171k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
171k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
171k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
171k
    const int y = sby * f->sb_step * 4;
1994
171k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
171k
    pixel *const p[3] = {
1996
171k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
171k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
171k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
171k
    };
2000
171k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
171k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
171k
                                        f->lf.start_of_tile_row[sby]);
2003
171k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
186k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
186k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
186k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
186k
    const int y = sby * f->sb_step * 4;
1994
186k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
186k
    pixel *const p[3] = {
1996
186k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
186k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
186k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
186k
    };
2000
186k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
186k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
186k
                                        f->lf.start_of_tile_row[sby]);
2003
186k
}
2004
2005
417k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
417k
    const int y = sby * f->sb_step * 4;
2007
417k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
417k
    pixel *const p[3] = {
2009
417k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
417k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
417k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
417k
    };
2013
417k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
417k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
417k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
357k
    {
2017
357k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
357k
    }
2019
417k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
343k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
343k
    }
2023
417k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
209k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
209k
    const int y = sby * f->sb_step * 4;
2007
209k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
209k
    pixel *const p[3] = {
2009
209k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
209k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
209k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
209k
    };
2013
209k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
209k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
209k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
171k
    {
2017
171k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
171k
    }
2019
209k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
166k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
166k
    }
2023
209k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
208k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
208k
    const int y = sby * f->sb_step * 4;
2007
208k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
208k
    pixel *const p[3] = {
2009
208k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
208k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
208k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
208k
    };
2013
208k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
208k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
208k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
186k
    {
2017
186k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
186k
    }
2019
208k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
176k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
176k
    }
2023
208k
}
2024
2025
241k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
241k
    const Dav1dFrameContext *const f = tc->f;
2027
241k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
241k
    const int sbsz = f->sb_step;
2029
241k
    const int y = sby * sbsz * 4;
2030
241k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
241k
    pixel *const p[3] = {
2032
241k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
241k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
241k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
241k
    };
2036
241k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
241k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
241k
    const int start = sby * sbsz;
2039
241k
    if (sby) {
2040
125k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
125k
        pixel *p_up[3] = {
2042
125k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
125k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
125k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
125k
        };
2046
125k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
125k
    }
2048
241k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
241k
    const int end = imin(start + n_blks, f->bh);
2050
241k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
241k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
129k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
129k
    const Dav1dFrameContext *const f = tc->f;
2027
129k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
129k
    const int sbsz = f->sb_step;
2029
129k
    const int y = sby * sbsz * 4;
2030
129k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
129k
    pixel *const p[3] = {
2032
129k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
129k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
129k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
129k
    };
2036
129k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
129k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
129k
    const int start = sby * sbsz;
2039
129k
    if (sby) {
2040
79.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
79.7k
        pixel *p_up[3] = {
2042
79.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
79.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
79.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
79.7k
        };
2046
79.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
79.7k
    }
2048
129k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
129k
    const int end = imin(start + n_blks, f->bh);
2050
129k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
129k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
111k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
111k
    const Dav1dFrameContext *const f = tc->f;
2027
111k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
111k
    const int sbsz = f->sb_step;
2029
111k
    const int y = sby * sbsz * 4;
2030
111k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
111k
    pixel *const p[3] = {
2032
111k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
111k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
111k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
111k
    };
2036
111k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
111k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
111k
    const int start = sby * sbsz;
2039
111k
    if (sby) {
2040
46.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
46.1k
        pixel *p_up[3] = {
2042
46.1k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
46.1k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
46.1k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
46.1k
        };
2046
46.1k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
46.1k
    }
2048
111k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
111k
    const int end = imin(start + n_blks, f->bh);
2050
111k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
111k
}
2052
2053
65.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
65.6k
    const int sbsz = f->sb_step;
2055
65.6k
    const int y = sby * sbsz * 4;
2056
65.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
65.6k
    const pixel *const p[3] = {
2058
65.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
65.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
65.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
65.6k
    };
2062
65.6k
    pixel *const sr_p[3] = {
2063
65.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
65.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
65.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
65.6k
    };
2067
65.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
244k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
178k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
178k
        const int h_start = 8 * !!sby >> ss_ver;
2071
178k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
178k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
178k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
178k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
178k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
178k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
178k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
178k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
178k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
178k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
178k
                          imin(img_h, h_end) + h_start, src_w,
2083
178k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
178k
                          HIGHBD_CALL_SUFFIX);
2085
178k
    }
2086
65.6k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
29.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
29.8k
    const int sbsz = f->sb_step;
2055
29.8k
    const int y = sby * sbsz * 4;
2056
29.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
29.8k
    const pixel *const p[3] = {
2058
29.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
29.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
29.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
29.8k
    };
2062
29.8k
    pixel *const sr_p[3] = {
2063
29.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
29.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
29.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
29.8k
    };
2067
29.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
111k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
81.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
81.9k
        const int h_start = 8 * !!sby >> ss_ver;
2071
81.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
81.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
81.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
81.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
81.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
81.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
81.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
81.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
81.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
81.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
81.9k
                          imin(img_h, h_end) + h_start, src_w,
2083
81.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
81.9k
                          HIGHBD_CALL_SUFFIX);
2085
81.9k
    }
2086
29.8k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
35.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
35.8k
    const int sbsz = f->sb_step;
2055
35.8k
    const int y = sby * sbsz * 4;
2056
35.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
35.8k
    const pixel *const p[3] = {
2058
35.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
35.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
35.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
35.8k
    };
2062
35.8k
    pixel *const sr_p[3] = {
2063
35.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
35.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
35.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
35.8k
    };
2067
35.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
132k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
96.6k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
96.6k
        const int h_start = 8 * !!sby >> ss_ver;
2071
96.6k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
96.6k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
96.6k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
96.6k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
96.6k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
96.6k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
96.6k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
96.6k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
96.6k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
96.6k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
96.6k
                          imin(img_h, h_end) + h_start, src_w,
2083
96.6k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
96.6k
                          HIGHBD_CALL_SUFFIX);
2085
96.6k
    }
2086
35.8k
}
2087
2088
248k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
248k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
248k
    const int y = sby * f->sb_step * 4;
2091
248k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
248k
    pixel *const sr_p[3] = {
2093
248k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
248k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
248k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
248k
    };
2097
248k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
248k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
119k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
119k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
119k
    const int y = sby * f->sb_step * 4;
2091
119k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
119k
    pixel *const sr_p[3] = {
2093
119k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
119k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
119k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
119k
    };
2097
119k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
119k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
129k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
129k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
129k
    const int y = sby * f->sb_step * 4;
2091
129k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
129k
    pixel *const sr_p[3] = {
2093
129k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
129k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
129k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
129k
    };
2097
129k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
129k
}
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
465k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
465k
    const Dav1dFrameContext *const f = t->f;
2113
465k
    Dav1dTileState *const ts = t->ts;
2114
465k
    const int sby = t->by >> f->sb_shift;
2115
465k
    const int sby_off = f->sb128w * 128 * sby;
2116
465k
    const int x_off = ts->tiling.col_start;
2117
2118
465k
    const pixel *const y =
2119
465k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
465k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
465k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
465k
               4 * (ts->tiling.col_end - x_off));
2123
2124
465k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
359k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
359k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
359k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
359k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
1.07M
        for (int pl = 1; pl <= 2; pl++)
2131
719k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
397k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
397k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
359k
    }
2135
465k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
234k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
234k
    const Dav1dFrameContext *const f = t->f;
2113
234k
    Dav1dTileState *const ts = t->ts;
2114
234k
    const int sby = t->by >> f->sb_shift;
2115
234k
    const int sby_off = f->sb128w * 128 * sby;
2116
234k
    const int x_off = ts->tiling.col_start;
2117
2118
234k
    const pixel *const y =
2119
234k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
234k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
234k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
234k
               4 * (ts->tiling.col_end - x_off));
2123
2124
234k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
198k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
198k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
198k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
198k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
595k
        for (int pl = 1; pl <= 2; pl++)
2131
397k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
397k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
397k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
198k
    }
2135
234k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
230k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
230k
    const Dav1dFrameContext *const f = t->f;
2113
230k
    Dav1dTileState *const ts = t->ts;
2114
230k
    const int sby = t->by >> f->sb_shift;
2115
230k
    const int sby_off = f->sb128w * 128 * sby;
2116
230k
    const int x_off = ts->tiling.col_start;
2117
2118
230k
    const pixel *const y =
2119
230k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
230k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
230k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
230k
               4 * (ts->tiling.col_end - x_off));
2123
2124
230k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
161k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
161k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
161k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
161k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
483k
        for (int pl = 1; pl <= 2; pl++)
2131
322k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
161k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
161k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
161k
    }
2135
230k
}
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
57.1k
{
2142
57.1k
    const Dav1dFrameContext *const f = t->f;
2143
57.1k
    pixel *const pal = t->frame_thread.pass ?
2144
57.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
57.1k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
57.1k
        bytefn(t->scratch.pal)[0];
2147
271k
    for (int x = 0; x < bw4; x++)
2148
214k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
237k
    for (int y = 0; y < bh4; y++)
2150
180k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
57.1k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
24.6k
{
2142
24.6k
    const Dav1dFrameContext *const f = t->f;
2143
24.6k
    pixel *const pal = t->frame_thread.pass ?
2144
24.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
24.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
24.6k
        bytefn(t->scratch.pal)[0];
2147
115k
    for (int x = 0; x < bw4; x++)
2148
91.1k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
102k
    for (int y = 0; y < bh4; y++)
2150
77.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
24.6k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
32.5k
{
2142
32.5k
    const Dav1dFrameContext *const f = t->f;
2143
32.5k
    pixel *const pal = t->frame_thread.pass ?
2144
32.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
32.5k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
32.5k
        bytefn(t->scratch.pal)[0];
2147
155k
    for (int x = 0; x < bw4; x++)
2148
123k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
135k
    for (int y = 0; y < bh4; y++)
2150
102k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
32.5k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
17.5k
{
2158
17.5k
    const Dav1dFrameContext *const f = t->f;
2159
17.5k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
17.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
17.5k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
17.5k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
52.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
200k
        for (int x = 0; x < bw4; x++)
2166
165k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
180k
        for (int y = 0; y < bh4; y++)
2168
144k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
35.1k
    }
2170
17.5k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
8.61k
{
2158
8.61k
    const Dav1dFrameContext *const f = t->f;
2159
8.61k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.61k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.61k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.61k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
25.8k
    for (int pl = 1; pl <= 2; pl++) {
2165
99.4k
        for (int x = 0; x < bw4; x++)
2166
82.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
90.8k
        for (int y = 0; y < bh4; y++)
2168
73.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
17.2k
    }
2170
8.61k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
8.95k
{
2158
8.95k
    const Dav1dFrameContext *const f = t->f;
2159
8.95k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.95k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.95k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.95k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
26.8k
    for (int pl = 1; pl <= 2; pl++) {
2165
101k
        for (int x = 0; x < bw4; x++)
2166
83.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
89.1k
        for (int y = 0; y < bh4; y++)
2168
71.2k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
17.9k
    }
2170
8.95k
}
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
74.7k
{
2176
74.7k
    Dav1dTileState *const ts = t->ts;
2177
74.7k
    const Dav1dFrameContext *const f = t->f;
2178
74.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
74.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
74.7k
    pixel cache[16], used_cache[8];
2181
74.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
74.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
74.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
74.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
74.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
123k
    while (l_cache && a_cache) {
2190
48.6k
        if (*l < *a) {
2191
18.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
18.4k
                cache[n_cache++] = *l;
2193
18.6k
            l++;
2194
18.6k
            l_cache--;
2195
30.0k
        } else {
2196
30.0k
            if (*a == *l) {
2197
11.9k
                l++;
2198
11.9k
                l_cache--;
2199
11.9k
            }
2200
30.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
29.0k
                cache[n_cache++] = *a;
2202
30.0k
            a++;
2203
30.0k
            a_cache--;
2204
30.0k
        }
2205
48.6k
    }
2206
74.7k
    if (l_cache) {
2207
88.6k
        do {
2208
88.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
71.6k
                cache[n_cache++] = *l;
2210
88.6k
            l++;
2211
88.6k
        } while (--l_cache > 0);
2212
53.8k
    } else if (a_cache) {
2213
65.7k
        do {
2214
65.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
52.5k
                cache[n_cache++] = *a;
2216
65.7k
            a++;
2217
65.7k
        } while (--a_cache > 0);
2218
15.9k
    }
2219
2220
    // find reused cache entries
2221
74.7k
    int i = 0;
2222
227k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
152k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
75.8k
            used_cache[i++] = cache[n];
2225
74.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
74.7k
    pixel *const pal = t->frame_thread.pass ?
2229
74.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
74.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
74.7k
        bytefn(t->scratch.pal)[pl];
2232
74.7k
    if (i < pal_sz) {
2233
65.3k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
65.3k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
65.3k
        if (i < pal_sz) {
2237
59.2k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
59.2k
            const int max = (1 << bpc) - 1;
2239
2240
139k
            do {
2241
139k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
139k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
139k
                if (prev + !pl >= max) {
2244
80.5k
                    for (; i < pal_sz; i++)
2245
52.5k
                        pal[i] = max;
2246
27.9k
                    break;
2247
27.9k
                }
2248
111k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
111k
            } while (i < pal_sz);
2250
59.2k
        }
2251
2252
        // merge cache+new entries
2253
65.3k
        int n = 0, m = n_used_cache;
2254
372k
        for (i = 0; i < pal_sz; i++) {
2255
307k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
50.2k
                pal[i] = used_cache[n++];
2257
256k
            } else {
2258
256k
                assert(m < pal_sz);
2259
256k
                pal[i] = pal[m++];
2260
256k
            }
2261
307k
        }
2262
65.3k
    } else {
2263
9.44k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
9.44k
    }
2265
2266
74.7k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
74.7k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
33.2k
{
2176
33.2k
    Dav1dTileState *const ts = t->ts;
2177
33.2k
    const Dav1dFrameContext *const f = t->f;
2178
33.2k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
33.2k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
33.2k
    pixel cache[16], used_cache[8];
2181
33.2k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
33.2k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
33.2k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
33.2k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
33.2k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
50.1k
    while (l_cache && a_cache) {
2190
16.8k
        if (*l < *a) {
2191
6.35k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.26k
                cache[n_cache++] = *l;
2193
6.35k
            l++;
2194
6.35k
            l_cache--;
2195
10.5k
        } else {
2196
10.5k
            if (*a == *l) {
2197
4.37k
                l++;
2198
4.37k
                l_cache--;
2199
4.37k
            }
2200
10.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.0k
                cache[n_cache++] = *a;
2202
10.5k
            a++;
2203
10.5k
            a_cache--;
2204
10.5k
        }
2205
16.8k
    }
2206
33.2k
    if (l_cache) {
2207
36.5k
        do {
2208
36.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
29.2k
                cache[n_cache++] = *l;
2210
36.5k
            l++;
2211
36.5k
        } while (--l_cache > 0);
2212
24.6k
    } else if (a_cache) {
2213
26.4k
        do {
2214
26.4k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
20.8k
                cache[n_cache++] = *a;
2216
26.4k
            a++;
2217
26.4k
        } while (--a_cache > 0);
2218
6.34k
    }
2219
2220
    // find reused cache entries
2221
33.2k
    int i = 0;
2222
92.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
59.0k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
29.5k
            used_cache[i++] = cache[n];
2225
33.2k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
33.2k
    pixel *const pal = t->frame_thread.pass ?
2229
33.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
33.2k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
33.2k
        bytefn(t->scratch.pal)[pl];
2232
33.2k
    if (i < pal_sz) {
2233
29.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
29.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
29.5k
        if (i < pal_sz) {
2237
27.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
27.0k
            const int max = (1 << bpc) - 1;
2239
2240
63.6k
            do {
2241
63.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
63.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
63.6k
                if (prev + !pl >= max) {
2244
38.3k
                    for (; i < pal_sz; i++)
2245
25.1k
                        pal[i] = max;
2246
13.1k
                    break;
2247
13.1k
                }
2248
50.4k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
50.4k
            } while (i < pal_sz);
2250
27.0k
        }
2251
2252
        // merge cache+new entries
2253
29.5k
        int n = 0, m = n_used_cache;
2254
167k
        for (i = 0; i < pal_sz; i++) {
2255
138k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
19.8k
                pal[i] = used_cache[n++];
2257
118k
            } else {
2258
118k
                assert(m < pal_sz);
2259
118k
                pal[i] = pal[m++];
2260
118k
            }
2261
138k
        }
2262
29.5k
    } else {
2263
3.68k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.68k
    }
2265
2266
33.2k
    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
33.2k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
41.5k
{
2176
41.5k
    Dav1dTileState *const ts = t->ts;
2177
41.5k
    const Dav1dFrameContext *const f = t->f;
2178
41.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
41.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
41.5k
    pixel cache[16], used_cache[8];
2181
41.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
41.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
41.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
41.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
41.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
73.3k
    while (l_cache && a_cache) {
2190
31.7k
        if (*l < *a) {
2191
12.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
12.1k
                cache[n_cache++] = *l;
2193
12.2k
            l++;
2194
12.2k
            l_cache--;
2195
19.5k
        } else {
2196
19.5k
            if (*a == *l) {
2197
7.61k
                l++;
2198
7.61k
                l_cache--;
2199
7.61k
            }
2200
19.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
18.9k
                cache[n_cache++] = *a;
2202
19.5k
            a++;
2203
19.5k
            a_cache--;
2204
19.5k
        }
2205
31.7k
    }
2206
41.5k
    if (l_cache) {
2207
52.0k
        do {
2208
52.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
42.4k
                cache[n_cache++] = *l;
2210
52.0k
            l++;
2211
52.0k
        } while (--l_cache > 0);
2212
29.1k
    } else if (a_cache) {
2213
39.2k
        do {
2214
39.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
31.6k
                cache[n_cache++] = *a;
2216
39.2k
            a++;
2217
39.2k
        } while (--a_cache > 0);
2218
9.63k
    }
2219
2220
    // find reused cache entries
2221
41.5k
    int i = 0;
2222
134k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
93.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
46.3k
            used_cache[i++] = cache[n];
2225
41.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
41.5k
    pixel *const pal = t->frame_thread.pass ?
2229
41.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
41.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
41.5k
        bytefn(t->scratch.pal)[pl];
2232
41.5k
    if (i < pal_sz) {
2233
35.7k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
35.7k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
35.7k
        if (i < pal_sz) {
2237
32.1k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
32.1k
            const int max = (1 << bpc) - 1;
2239
2240
75.4k
            do {
2241
75.4k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
75.4k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
75.4k
                if (prev + !pl >= max) {
2244
42.1k
                    for (; i < pal_sz; i++)
2245
27.3k
                        pal[i] = max;
2246
14.7k
                    break;
2247
14.7k
                }
2248
60.6k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
60.6k
            } while (i < pal_sz);
2250
32.1k
        }
2251
2252
        // merge cache+new entries
2253
35.7k
        int n = 0, m = n_used_cache;
2254
204k
        for (i = 0; i < pal_sz; i++) {
2255
168k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
30.4k
                pal[i] = used_cache[n++];
2257
138k
            } else {
2258
138k
                assert(m < pal_sz);
2259
138k
                pal[i] = pal[m++];
2260
138k
            }
2261
168k
        }
2262
35.7k
    } else {
2263
5.76k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
5.76k
    }
2265
2266
41.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
41.5k
}
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
17.5k
{
2281
17.5k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
17.5k
    Dav1dTileState *const ts = t->ts;
2285
17.5k
    const Dav1dFrameContext *const f = t->f;
2286
17.5k
    pixel *const pal = t->frame_thread.pass ?
2287
17.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
17.5k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
17.5k
        bytefn(t->scratch.pal)[2];
2290
17.5k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
17.5k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
8.65k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
8.65k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
8.65k
        const int max = (1 << bpc) - 1;
2295
36.4k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
27.7k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
27.7k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
27.7k
            prev = pal[i] = (prev + delta) & max;
2299
27.7k
        }
2300
8.92k
    } else {
2301
45.7k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
36.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
8.92k
    }
2304
17.5k
    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
17.5k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
8.61k
{
2281
8.61k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.61k
    Dav1dTileState *const ts = t->ts;
2285
8.61k
    const Dav1dFrameContext *const f = t->f;
2286
8.61k
    pixel *const pal = t->frame_thread.pass ?
2287
8.61k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.61k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
8.61k
        bytefn(t->scratch.pal)[2];
2290
8.61k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
8.61k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.16k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.16k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.16k
        const int max = (1 << bpc) - 1;
2295
17.6k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
13.4k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
13.4k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
13.4k
            prev = pal[i] = (prev + delta) & max;
2299
13.4k
        }
2300
4.45k
    } else {
2301
22.8k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
18.4k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.45k
    }
2304
8.61k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
8.61k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
8.95k
{
2281
8.95k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.95k
    Dav1dTileState *const ts = t->ts;
2285
8.95k
    const Dav1dFrameContext *const f = t->f;
2286
8.95k
    pixel *const pal = t->frame_thread.pass ?
2287
8.95k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.95k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
8.95k
        bytefn(t->scratch.pal)[2];
2290
8.95k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
8.95k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.48k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.48k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.48k
        const int max = (1 << bpc) - 1;
2295
18.7k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
14.3k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
14.3k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
14.3k
            prev = pal[i] = (prev + delta) & max;
2299
14.3k
        }
2300
4.48k
    } else {
2301
22.8k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
18.4k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.47k
    }
2304
8.95k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
8.95k
}