Coverage Report

Created: 2026-10-17 06:56

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