Coverage Report

Created: 2026-07-30 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
1.61M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.61M
    int len = 0;
51
1.61M
    unsigned val = 1;
52
53
2.93M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
2.93M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.61M
    return val - 1;
57
1.61M
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
12.2M
{
66
12.2M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
12.2M
    if (chroma) {
69
6.57M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
6.57M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
6.57M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
3.93M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
6.57M
        unsigned ca, cl;
74
75
6.57M
#define MERGE_CTX(dir, type, no_val) \
76
13.1M
        c##dir = *(const type *) dir != no_val; \
77
13.1M
        break
78
79
6.57M
        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.74M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
1.24M
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
919k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
1.67M
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
6.57M
        }
91
6.58M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
3.04M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
1.20M
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
735k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
1.61M
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
6.58M
        }
98
6.58M
#undef MERGE_CTX
99
100
6.58M
        return 7 + not_one_blk * 3 + ca + cl;
101
6.58M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
2.24M
        return 0;
103
3.42M
    } else {
104
3.42M
        unsigned la, ll;
105
106
3.42M
#define MERGE_CTX(dir, type, tx) \
107
7.15M
        if (tx == TX_64X64) { \
108
491k
            uint64_t tmp = *(const uint64_t *) dir; \
109
491k
            tmp |= *(const uint64_t *) &dir[8]; \
110
491k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
491k
        } else \
112
7.15M
            l##dir = *(const type *) dir; \
113
7.15M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
7.15M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
7.15M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
7.15M
        break
117
118
3.42M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
2.04M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
703k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
539k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
46.5k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
245k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
3.42M
        }
126
3.57M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
2.06M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
682k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
537k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
46.8k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
245k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
3.57M
        }
134
3.57M
#undef MERGE_CTX
135
136
3.57M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
3.57M
    }
138
12.2M
}
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.19M
{
144
5.19M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
5.19M
    int s;
146
147
5.19M
#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.19M
    __asm__("" : "+r"(mask), "+r"(mul));
151
5.19M
#endif
152
153
5.19M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
2.05M
    case TX_4X4: {
156
2.05M
        int t = *(const uint8_t *) a >> 6;
157
2.05M
        t    += *(const uint8_t *) l >> 6;
158
2.05M
        s = t - 1 - 1;
159
2.05M
        break;
160
0
    }
161
565k
    case TX_8X8: {
162
565k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
565k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
565k
        t *= 0x04040404U;
165
565k
        s = (int) (t >> 24) - 2 - 2;
166
565k
        break;
167
0
    }
168
425k
    case TX_16X16: {
169
425k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
425k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
425k
        t *= (uint32_t) mul;
172
425k
        s = (int) (t >> 24) - 4 - 4;
173
425k
        break;
174
0
    }
175
462k
    case TX_32X32: {
176
462k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
462k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
462k
        t *= mul;
179
462k
        s = (int) (t >> 56) - 8 - 8;
180
462k
        break;
181
0
    }
182
195k
    case TX_64X64: {
183
195k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
195k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
195k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
195k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
195k
        t *= mul;
188
195k
        s = (int) (t >> 56) - 16 - 16;
189
195k
        break;
190
0
    }
191
172k
    case RTX_4X8: {
192
172k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
172k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
172k
        t *= 0x04040404U;
195
172k
        s = (int) (t >> 24) - 1 - 2;
196
172k
        break;
197
0
    }
198
255k
    case RTX_8X4: {
199
255k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
255k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
255k
        t *= 0x04040404U;
202
255k
        s = (int) (t >> 24) - 2 - 1;
203
255k
        break;
204
0
    }
205
143k
    case RTX_8X16: {
206
143k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
143k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
143k
        t = (t >> 6) * (uint32_t) mul;
209
143k
        s = (int) (t >> 24) - 2 - 4;
210
143k
        break;
211
0
    }
212
261k
    case RTX_16X8: {
213
261k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
261k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
261k
        t = (t >> 6) * (uint32_t) mul;
216
261k
        s = (int) (t >> 24) - 4 - 2;
217
261k
        break;
218
0
    }
219
78.7k
    case RTX_16X32: {
220
78.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
78.7k
        t         += *(const uint64_t *) l & mask;
222
78.7k
        t = (t >> 6) * mul;
223
78.7k
        s = (int) (t >> 56) - 4 - 8;
224
78.7k
        break;
225
0
    }
226
123k
    case RTX_32X16: {
227
123k
        uint64_t t = *(const uint64_t *) a & mask;
228
123k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
123k
        t = (t >> 6) * mul;
230
123k
        s = (int) (t >> 56) - 8 - 4;
231
123k
        break;
232
0
    }
233
49.3k
    case RTX_32X64: {
234
49.3k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
49.3k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
49.3k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
49.3k
        t *= mul;
238
49.3k
        s = (int) (t >> 56) - 8 - 16;
239
49.3k
        break;
240
0
    }
241
43.8k
    case RTX_64X32: {
242
43.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
43.8k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
43.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
43.8k
        t *= mul;
246
43.8k
        s = (int) (t >> 56) - 16 - 8;
247
43.8k
        break;
248
0
    }
249
80.6k
    case RTX_4X16: {
250
80.6k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
80.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
80.6k
        t = (t >> 6) * (uint32_t) mul;
253
80.6k
        s = (int) (t >> 24) - 1 - 4;
254
80.6k
        break;
255
0
    }
256
153k
    case RTX_16X4: {
257
153k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
153k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
153k
        t = (t >> 6) * (uint32_t) mul;
260
153k
        s = (int) (t >> 24) - 4 - 1;
261
153k
        break;
262
0
    }
263
50.3k
    case RTX_8X32: {
264
50.3k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
50.3k
        t         += *(const uint64_t *) l & mask;
266
50.3k
        t = (t >> 6) * mul;
267
50.3k
        s = (int) (t >> 56) - 2 - 8;
268
50.3k
        break;
269
0
    }
270
68.3k
    case RTX_32X8: {
271
68.3k
        uint64_t t = *(const uint64_t *) a & mask;
272
68.3k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
68.3k
        t = (t >> 6) * mul;
274
68.3k
        s = (int) (t >> 56) - 8 - 2;
275
68.3k
        break;
276
0
    }
277
14.5k
    case RTX_16X64: {
278
14.5k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
14.5k
        t         += *(const uint64_t *) &l[0] & mask;
280
14.5k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
14.5k
        t *= mul;
282
14.5k
        s = (int) (t >> 56) - 4 - 16;
283
14.5k
        break;
284
0
    }
285
11.1k
    case RTX_64X16: {
286
11.1k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
11.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
11.1k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
11.1k
        t *= mul;
290
11.1k
        s = (int) (t >> 56) - 16 - 4;
291
11.1k
        break;
292
0
    }
293
5.19M
    }
294
295
5.19M
    return (s != 0) + (s > 0);
296
5.19M
}
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
102M
{
305
102M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
102M
    unsigned offset;
307
102M
    if (tx_class == TX_CLASS_2D) {
308
95.4M
        mag += levels[1 * stride + 1];
309
95.4M
        *hi_mag = mag;
310
95.4M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
95.4M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
95.4M
    } else {
313
6.72M
        mag += levels[0 * stride + 2];
314
6.72M
        *hi_mag = mag;
315
6.72M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
6.72M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
6.72M
    }
318
102M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
102M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
12.2M
{
328
12.2M
    Dav1dTileState *const ts = t->ts;
329
12.2M
    const int chroma = !!plane;
330
12.2M
    const Dav1dFrameContext *const f = t->f;
331
12.2M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
12.2M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
12.2M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
12.2M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
12.2M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
12.2M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
12.2M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
12.2M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
12.2M
    if (all_skip) {
346
6.01M
        *res_ctx = 0x40;
347
6.01M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
6.01M
        return -1;
349
6.01M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
6.21M
    if (lossless) {
353
1.88M
        assert(t_dim->max == TX_4X4);
354
1.88M
        *txtp = WHT_WHT;
355
4.33M
    } else if (t_dim->max + intra >= TX_64X64) {
356
1.08M
        *txtp = DCT_DCT;
357
3.24M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
833k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
833k
                        get_uv_inter_txtp(t_dim, *txtp);
361
2.41M
    } 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
31.3k
        *txtp = DCT_DCT;
366
2.38M
    } else {
367
2.38M
        unsigned idx;
368
2.38M
        if (intra) {
369
1.76M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
1.48M
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.76M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
755k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
755k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
755k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
1.00M
            } else {
376
1.00M
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
1.00M
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
1.00M
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
1.00M
            }
380
1.76M
            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.76M
        } else {
384
618k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
196k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
196k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
196k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
421k
            } else if (t_dim->min == TX_16X16) {
389
56.1k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
56.1k
                          ts->cdf.m.txtp_inter2, 11);
391
56.1k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
365k
            } else {
393
365k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
365k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
365k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
365k
            }
397
618k
            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
618k
        }
401
2.38M
    }
402
403
    // find end-of-block (eob)
404
6.21M
    int eob;
405
6.21M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
6.21M
    const int tx2dszctx = slw + slh;
407
6.21M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
6.21M
    const int is_1d = tx_class != TX_CLASS_2D;
409
6.21M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
6.27M
    case sz: { \
412
6.27M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
6.27M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
6.27M
        break; \
415
6.27M
    }
416
2.40M
    case_sz(0,   16,  8, [is_1d]);
417
556k
    case_sz(1,   32,  8, [is_1d]);
418
1.03M
    case_sz(2,   64,  8, [is_1d]);
419
532k
    case_sz(3,  128,  8, [is_1d]);
420
680k
    case_sz(4,  256, 16, [is_1d]);
421
262k
    case_sz(5,  512, 16,        );
422
805k
    case_sz(6, 1024, 16,        );
423
6.21M
#undef case_sz
424
6.21M
    }
425
6.22M
    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.22M
    if (eob > 1) {
429
3.97M
        const int eob_bin = eob - 2;
430
3.97M
        uint16_t *const eob_hi_bit_cdf =
431
3.97M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
3.97M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
3.97M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
3.97M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
3.97M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
3.97M
    }
440
6.22M
    assert(eob >= 0);
441
442
    // base tokens
443
6.22M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
6.22M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
6.22M
    unsigned rc, dc_tok;
446
447
6.22M
    if (eob) {
448
4.16M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
4.16M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
4.16M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
4.16M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
4.16M
        int tok = eob_tok + 1;
455
4.16M
        int level_tok = tok * 0x41;
456
4.16M
        unsigned mag;
457
458
4.16M
#define DECODE_COEFS_CLASS(tx_class) \
459
4.18M
        unsigned x, y; \
460
4.18M
        uint8_t *level; \
461
4.18M
        if (tx_class == TX_CLASS_2D) \
462
4.18M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
4.18M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
337k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
337k
        else /* tx_class == TX_CLASS_V */ \
467
337k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
4.18M
        if (dbg) \
469
4.18M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
4.18M
        if (eob_tok == 2) { \
472
95.3k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
95.3k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
95.3k
            level_tok = tok + (3 << 6); \
475
95.3k
            if (dbg) \
476
95.3k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
95.3k
        } \
480
4.18M
        cf[rc] = tok << 11; \
481
4.18M
        if (tx_class == TX_CLASS_2D) \
482
4.18M
            level = levels + rc; \
483
4.18M
        else \
484
4.18M
            level = levels + x * stride + y; \
485
4.18M
        *level = (uint8_t) level_tok; \
486
106M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
101M
            unsigned rc_i; \
488
101M
            if (tx_class == TX_CLASS_2D) \
489
101M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
101M
            else if (tx_class == TX_CLASS_H) \
491
6.64M
                x = i & mask, y = i >> shift, rc_i = i; \
492
6.64M
            else /* tx_class == TX_CLASS_V */ \
493
6.64M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
101M
            assert(x < 32 && y < 32); \
495
101M
            if (tx_class == TX_CLASS_2D) \
496
101M
                level = levels + rc_i; \
497
101M
            else \
498
101M
                level = levels + x * stride + y; \
499
101M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
101M
            if (tx_class == TX_CLASS_2D) \
501
101M
                y |= x; \
502
101M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
101M
            if (dbg) \
504
101M
                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
101M
            if (tok == 3) { \
507
8.25M
                mag &= 63; \
508
8.25M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
8.25M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
8.25M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
8.25M
                if (dbg) \
512
8.25M
                    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
8.25M
                *level = (uint8_t) (tok + (3 << 6)); \
516
8.25M
                cf[rc_i] = (tok << 11) | rc; \
517
8.25M
                rc = rc_i; \
518
93.7M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
93.7M
                tok *= 0x17ff41; \
521
93.7M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
93.7M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
93.7M
                if (tok) rc = rc_i; \
525
93.7M
                cf[rc_i] = tok; \
526
93.7M
            } \
527
101M
        } \
528
        /* dc */ \
529
4.18M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
4.18M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
4.18M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
4.18M
        if (dbg) \
533
4.18M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
4.18M
        if (dc_tok == 3) { \
536
1.56M
            if (tx_class == TX_CLASS_2D) \
537
1.56M
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
1.52M
                      levels[1 * stride + 1]; \
539
1.56M
            mag &= 63; \
540
1.56M
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
1.56M
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
1.56M
            if (dbg) \
543
1.56M
                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.56M
        } \
546
4.18M
        break
547
548
4.16M
        const uint16_t *scan;
549
4.16M
        switch (tx_class) {
550
3.83M
        case TX_CLASS_2D: {
551
3.83M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
3.83M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
3.83M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
3.83M
            scan = dav1d_scans[tx];
555
3.83M
            const ptrdiff_t stride = 4 << slh;
556
3.83M
            const unsigned shift = slh + 2, shift2 = 0;
557
3.83M
            const unsigned mask = (4 << slh) - 1;
558
3.83M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
3.83M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
3.83M
        }
561
226k
        case TX_CLASS_H: {
562
226k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
226k
            const ptrdiff_t stride = 16;
564
226k
            const unsigned shift = slh + 2, shift2 = 0;
565
226k
            const unsigned mask = (4 << slh) - 1;
566
226k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
226k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
226k
        }
569
128k
        case TX_CLASS_V: {
570
128k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
128k
            const ptrdiff_t stride = 16;
572
128k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
128k
            const unsigned mask = (4 << slw) - 1;
574
128k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
128k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
128k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
4.16M
        }
580
4.16M
    } else { // dc-only
581
2.06M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
2.06M
        dc_tok = 1 + tok_br;
583
2.06M
        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.06M
        if (tok_br == 2) {
587
78.7k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
78.7k
            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
78.7k
        }
592
2.06M
        rc = 0;
593
2.06M
    }
594
595
    // residual and sign
596
6.26M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
6.26M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
6.26M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
6.26M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
6.26M
    unsigned cul_level, dc_sign_level;
601
602
6.26M
    if (!dc_tok) {
603
1.07M
        cul_level = 0;
604
1.07M
        dc_sign_level = 1 << 6;
605
1.07M
        if (qm_tbl) goto ac_qm;
606
772k
        goto ac_noqm;
607
1.07M
    }
608
609
5.19M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
5.19M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
5.19M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
5.19M
    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.19M
    int dc_dq = dq_tbl[0];
617
5.19M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
5.19M
    if (qm_tbl) {
620
1.56M
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
1.56M
        if (dc_tok == 15) {
623
47.0k
            dc_tok = read_golomb(&ts->msac) + 15;
624
47.0k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
47.0k
            dc_tok &= 0xfffff;
629
47.0k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
1.51M
        } else {
631
1.51M
            dc_dq *= dc_tok;
632
1.51M
            assert(dc_dq <= 0xffffff);
633
1.51M
        }
634
1.56M
        cul_level = dc_tok;
635
1.56M
        dc_dq >>= dq_shift;
636
1.56M
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
1.56M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
2.32M
        if (rc) ac_qm: {
640
2.32M
            const unsigned ac_dq = dq_tbl[1];
641
16.7M
            do {
642
16.7M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
16.7M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
16.7M
                const unsigned rc_tok = cf[rc];
646
16.7M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
16.7M
                int dq_sat;
648
649
16.7M
                if (rc_tok >= (15 << 11)) {
650
977k
                    tok = read_golomb(&ts->msac) + 15;
651
977k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
977k
                    tok &= 0xfffff;
656
977k
                    dq = (dq * tok) & 0xffffff;
657
15.7M
                } else {
658
15.7M
                    tok = rc_tok >> 11;
659
15.7M
                    dq *= tok;
660
15.7M
                    assert(dq <= 0xffffff);
661
15.7M
                }
662
16.7M
                cul_level += tok;
663
16.7M
                dq >>= dq_shift;
664
16.7M
                dq_sat = umin(dq, cf_max + sign);
665
16.7M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
16.7M
                rc = rc_tok & 0x3ff;
668
16.7M
            } while (rc);
669
2.32M
        }
670
3.63M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
3.63M
        if (dc_tok == 15) {
673
128k
            dc_tok = read_golomb(&ts->msac) + 15;
674
128k
            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
128k
            dc_tok &= 0xfffff;
679
128k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
128k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
3.50M
        } else {
682
3.50M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
3.50M
            assert(dc_dq <= cf_max);
684
3.50M
        }
685
3.63M
        cul_level = dc_tok;
686
3.63M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
5.05M
        if (rc) ac_noqm: {
689
5.05M
            const unsigned ac_dq = dq_tbl[1];
690
23.9M
            do {
691
23.9M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
23.9M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
23.9M
                const unsigned rc_tok = cf[rc];
695
23.9M
                unsigned tok;
696
23.9M
                int dq;
697
698
                // residual
699
23.9M
                if (rc_tok >= (15 << 11)) {
700
464k
                    tok = read_golomb(&ts->msac) + 15;
701
464k
                    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
464k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
464k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
464k
                    dq = umin(dq, cf_max + sign);
711
23.5M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
23.5M
                    tok = rc_tok >> 11;
714
23.5M
                    dq = ((ac_dq * tok) >> dq_shift);
715
23.5M
                    assert(dq <= cf_max);
716
23.5M
                }
717
23.9M
                cul_level += tok;
718
23.9M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
23.9M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
23.9M
            } while (rc);
722
5.05M
        }
723
3.63M
    }
724
725
    // context
726
6.22M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
6.22M
    return eob;
729
5.19M
}
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
2.20M
{
737
2.20M
    const Dav1dFrameContext *const f = t->f;
738
2.20M
    Dav1dTileState *const ts = t->ts;
739
2.20M
    const Dav1dDSPContext *const dsp = f->dsp;
740
2.20M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
2.20M
    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
2.20M
    if (depth < 2 && tx_split[depth] &&
746
220k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
176k
    {
748
176k
        const enum RectTxfmSize sub = t_dim->sub;
749
176k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
176k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
176k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
176k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
176k
        t->bx += txsw;
755
176k
        if (txw >= txh && t->bx < f->bw)
756
132k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
132k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
176k
        t->bx -= txsw;
759
176k
        t->by += txsh;
760
176k
        if (txh >= txw && t->by < f->bh) {
761
114k
            if (dst)
762
36.9k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
114k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
114k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
114k
            t->bx += txsw;
766
114k
            if (txw >= txh && t->bx < f->bw)
767
73.3k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
73.3k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
114k
            t->bx -= txsw;
770
114k
        }
771
176k
        t->by -= txsh;
772
2.03M
    } else {
773
2.03M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
2.03M
        enum TxfmType txtp;
775
2.03M
        uint8_t cf_ctx;
776
2.03M
        int eob;
777
2.03M
        coef *cf;
778
779
2.03M
        if (t->frame_thread.pass) {
780
2.03M
            const int p = t->frame_thread.pass & 1;
781
2.03M
            assert(ts->frame_thread[p].cf);
782
2.03M
            cf = ts->frame_thread[p].cf;
783
2.03M
            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.03M
        if (t->frame_thread.pass != 2) {
788
1.37M
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
1.37M
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
1.37M
            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.37M
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
1.37M
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
1.37M
#define set_ctx(rep_macro) \
796
5.15M
            for (int y = 0; y < txh; y++) { \
797
3.78M
                rep_macro(txtp_map, 0, txtp); \
798
3.78M
                txtp_map += 32; \
799
3.78M
            }
800
1.37M
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
1.37M
            case_set_upto16(t_dim->lw);
802
1.37M
#undef set_ctx
803
1.37M
            if (t->frame_thread.pass == 1)
804
1.37M
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
1.37M
        } else {
806
659k
            const int cbi = *ts->frame_thread[0].cbi++;
807
659k
            eob  = cbi >> 5;
808
659k
            txtp = cbi & 0x1f;
809
659k
        }
810
2.03M
        if (!(t->frame_thread.pass & 1)) {
811
660k
            assert(dst);
812
660k
            if (eob >= 0) {
813
459k
                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
459k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
459k
                                              HIGHBD_CALL_SUFFIX);
817
459k
                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
459k
            }
820
660k
        }
821
2.03M
    }
822
2.20M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
6.54M
{
827
6.54M
    const Dav1dFrameContext *const f = t->f;
828
6.54M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
6.54M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
6.54M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
6.54M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
6.54M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
6.54M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
6.54M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
6.54M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
5.57M
                           (bw4 > ss_hor || t->bx & 1) &&
837
5.17M
                           (bh4 > ss_ver || t->by & 1);
838
839
6.54M
    if (b->skip) {
840
3.82M
        BlockContext *const a = t->a;
841
3.82M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
3.82M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
3.82M
        if (has_chroma) {
844
2.75M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
2.75M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
2.75M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
2.75M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
2.75M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
2.75M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
2.75M
        }
851
3.82M
        return;
852
3.82M
    }
853
854
2.72M
    Dav1dTileState *const ts = t->ts;
855
2.72M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
2.72M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
2.72M
    assert(t->frame_thread.pass == 1);
858
2.72M
    assert(!b->skip);
859
2.72M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
2.72M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
2.72M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
5.52M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
2.80M
        const int sub_h4 = imin(h4, 16 + init_y);
865
5.72M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
2.92M
            const int sub_w4 = imin(w4, init_x + 16);
867
2.92M
            int y_off = !!init_y, y, x;
868
6.33M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
3.41M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
3.41M
            {
871
3.41M
                int x_off = !!init_x;
872
8.96M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
5.54M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
5.54M
                {
875
5.54M
                    if (!b->intra) {
876
1.15M
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
1.15M
                                       x_off, y_off, NULL);
878
4.39M
                    } else {
879
4.39M
                        uint8_t cf_ctx = 0x40;
880
4.39M
                        enum TxfmType txtp;
881
4.39M
                        const int eob =
882
4.39M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
4.39M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
4.39M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
4.39M
                        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.39M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
4.39M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
4.39M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
4.39M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
4.39M
                    }
893
5.54M
                }
894
3.41M
                t->bx -= x;
895
3.41M
            }
896
2.92M
            t->by -= y;
897
898
2.92M
            if (!has_chroma) continue;
899
900
2.22M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
2.22M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
6.66M
            for (int pl = 0; pl < 2; pl++) {
903
9.35M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
4.91M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
4.91M
                {
906
11.4M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
6.50M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
6.50M
                    {
909
6.50M
                        uint8_t cf_ctx = 0x40;
910
6.50M
                        enum TxfmType txtp;
911
6.50M
                        if (!b->intra)
912
1.66M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.66M
                                                        bx4 + (x << ss_hor)];
914
6.50M
                        const int eob =
915
6.50M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
6.50M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
6.50M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
6.50M
                                         &txtp, &cf_ctx);
919
6.50M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
6.50M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
6.50M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
6.50M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
6.50M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
6.50M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
6.50M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
6.50M
                    }
930
4.91M
                    t->bx -= x << ss_hor;
931
4.91M
                }
932
4.44M
                t->by -= y << ss_ver;
933
4.44M
            }
934
2.22M
        }
935
2.80M
    }
936
2.72M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
3.36M
{
827
3.36M
    const Dav1dFrameContext *const f = t->f;
828
3.36M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.36M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.36M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.36M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.36M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.36M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.36M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.36M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
3.11M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.88M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.36M
    if (b->skip) {
840
2.02M
        BlockContext *const a = t->a;
841
2.02M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
2.02M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
2.02M
        if (has_chroma) {
844
1.58M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.58M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.58M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.58M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.58M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.58M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.58M
        }
851
2.02M
        return;
852
2.02M
    }
853
854
1.34M
    Dav1dTileState *const ts = t->ts;
855
1.34M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.34M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.34M
    assert(t->frame_thread.pass == 1);
858
1.34M
    assert(!b->skip);
859
1.34M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.34M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.34M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.73M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.39M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.83M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.44M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.44M
            int y_off = !!init_y, y, x;
868
3.11M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.67M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.67M
            {
871
1.67M
                int x_off = !!init_x;
872
4.41M
                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
532k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
532k
                                       x_off, y_off, NULL);
878
2.21M
                    } else {
879
2.21M
                        uint8_t cf_ctx = 0x40;
880
2.21M
                        enum TxfmType txtp;
881
2.21M
                        const int eob =
882
2.21M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.21M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.21M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.21M
                        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.21M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.21M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.21M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.21M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.21M
                    }
893
2.74M
                }
894
1.67M
                t->bx -= x;
895
1.67M
            }
896
1.44M
            t->by -= y;
897
898
1.44M
            if (!has_chroma) continue;
899
900
1.16M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.16M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.48M
            for (int pl = 0; pl < 2; pl++) {
903
4.83M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.50M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.50M
                {
906
5.71M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.20M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.20M
                    {
909
3.20M
                        uint8_t cf_ctx = 0x40;
910
3.20M
                        enum TxfmType txtp;
911
3.20M
                        if (!b->intra)
912
770k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
770k
                                                        bx4 + (x << ss_hor)];
914
3.20M
                        const int eob =
915
3.20M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.20M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.20M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.20M
                                         &txtp, &cf_ctx);
919
3.20M
                        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.20M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.20M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.20M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.20M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.20M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.20M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.20M
                    }
930
2.50M
                    t->bx -= x << ss_hor;
931
2.50M
                }
932
2.32M
                t->by -= y << ss_ver;
933
2.32M
            }
934
1.16M
        }
935
1.39M
    }
936
1.34M
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
3.17M
{
827
3.17M
    const Dav1dFrameContext *const f = t->f;
828
3.17M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.17M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.17M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.17M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.17M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.17M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.17M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.17M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.46M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.29M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.17M
    if (b->skip) {
840
1.80M
        BlockContext *const a = t->a;
841
1.80M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.80M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.80M
        if (has_chroma) {
844
1.16M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.16M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.16M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.16M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.16M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.16M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.16M
        }
851
1.80M
        return;
852
1.80M
    }
853
854
1.37M
    Dav1dTileState *const ts = t->ts;
855
1.37M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.37M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.37M
    assert(t->frame_thread.pass == 1);
858
1.37M
    assert(!b->skip);
859
1.37M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.37M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.37M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.79M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.41M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.89M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.47M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.47M
            int y_off = !!init_y, y, x;
868
3.22M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.74M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.74M
            {
871
1.74M
                int x_off = !!init_x;
872
4.55M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.80M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.80M
                {
875
2.80M
                    if (!b->intra) {
876
619k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
619k
                                       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
2.80M
                }
894
1.74M
                t->bx -= x;
895
1.74M
            }
896
1.47M
            t->by -= y;
897
898
1.47M
            if (!has_chroma) continue;
899
900
1.06M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.06M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.18M
            for (int pl = 0; pl < 2; pl++) {
903
4.52M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.40M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.40M
                {
906
5.70M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.30M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.30M
                    {
909
3.30M
                        uint8_t cf_ctx = 0x40;
910
3.30M
                        enum TxfmType txtp;
911
3.30M
                        if (!b->intra)
912
897k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
897k
                                                        bx4 + (x << ss_hor)];
914
3.30M
                        const int eob =
915
3.30M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.30M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.30M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.30M
                                         &txtp, &cf_ctx);
919
3.30M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
3.30M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.30M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.30M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.30M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.30M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.30M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.30M
                    }
930
2.40M
                    t->bx -= x << ss_hor;
931
2.40M
                }
932
2.12M
                t->by -= y << ss_ver;
933
2.12M
            }
934
1.06M
        }
935
1.41M
    }
936
1.37M
}
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
2.45M
{
945
2.45M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
2.45M
    const Dav1dFrameContext *const f = t->f;
947
2.45M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
2.45M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
2.45M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
2.45M
    const int mvx = mv.x, mvy = mv.y;
951
2.45M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
2.45M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
2.45M
    const pixel *ref;
954
955
2.45M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
1.39M
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
1.39M
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
1.39M
        int w, h;
959
960
1.39M
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
889k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
889k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
889k
        } else {
964
501k
            w = f->bw * 4 >> ss_hor;
965
501k
            h = f->bh * 4 >> ss_ver;
966
501k
        }
967
1.39M
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
1.06M
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
750k
            dy + bh4 * v_mul + !!my * 4 > h)
970
747k
        {
971
747k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
747k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
747k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
747k
                                emu_edge_buf, 192 * sizeof(pixel),
975
747k
                                refp->p.data[pl], ref_stride);
976
747k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
747k
            ref_stride = 192 * sizeof(pixel);
978
747k
        } else {
979
643k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
643k
        }
981
982
1.39M
        if (dst8 != NULL) {
983
1.15M
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
1.15M
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
1.15M
                                     HIGHBD_CALL_SUFFIX);
986
1.15M
        } else {
987
232k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
232k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
232k
                                      HIGHBD_CALL_SUFFIX);
990
232k
        }
991
1.39M
    } else {
992
1.06M
        assert(refp != &f->sr_cur);
993
994
1.06M
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
1.06M
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
2.12M
#define scale_mv(res, val, scale) do { \
997
2.12M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
2.12M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
2.12M
        } while (0)
1000
1.06M
        int pos_y, pos_x;
1001
1.06M
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
1.06M
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
1.06M
#undef scale_mv
1004
1.06M
        const int left = pos_x >> 10;
1005
1.06M
        const int top = pos_y >> 10;
1006
1.06M
        const int right =
1007
1.06M
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
1.06M
        const int bottom =
1009
1.06M
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
1.06M
        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.06M
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
1.06M
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
1.06M
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
634k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
634k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
634k
                                w, h, left - 3, top - 3,
1023
634k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
634k
                                refp->p.data[pl], ref_stride);
1025
634k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
634k
            ref_stride = 320 * sizeof(pixel);
1027
634k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
634k
        } else {
1029
429k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
429k
        }
1031
1032
1.06M
        if (dst8 != NULL) {
1033
884k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
884k
                                            bw4 * h_mul, bh4 * v_mul,
1035
884k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
884k
                                            f->svc[refidx][0].step,
1037
884k
                                            f->svc[refidx][1].step
1038
884k
                                            HIGHBD_CALL_SUFFIX);
1039
884k
        } else {
1040
179k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
179k
                                             bw4 * h_mul, bh4 * v_mul,
1042
179k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
179k
                                             f->svc[refidx][0].step,
1044
179k
                                             f->svc[refidx][1].step
1045
179k
                                             HIGHBD_CALL_SUFFIX);
1046
179k
        }
1047
1.06M
    }
1048
1049
2.45M
    return 0;
1050
2.45M
}
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
193k
{
1057
193k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
193k
    const Dav1dFrameContext *const f = t->f;
1059
193k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
193k
    pixel *const lap = bitfn(t->scratch.lap);
1061
193k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
193k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
193k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
193k
    int res;
1065
1066
193k
    if (t->by > t->ts->tiling.row_start &&
1067
166k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
143k
    {
1069
303k
        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
160k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
160k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
160k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
160k
            if (a_r->ref.ref[0] > 0) {
1076
158k
                const int ow4 = imin(step4, b_dim[0]);
1077
158k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
158k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
158k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
158k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
158k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
158k
                if (res) return res;
1083
158k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
158k
                                   h_mul * ow4, v_mul * oh4);
1085
158k
                i++;
1086
158k
            }
1087
160k
            x += step4;
1088
160k
        }
1089
143k
    }
1090
1091
193k
    if (t->bx > t->ts->tiling.col_start)
1092
349k
        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
181k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
181k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
181k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
181k
            if (l_r->ref.ref[0] > 0) {
1099
179k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
179k
                const int oh4 = imin(step4, b_dim[1]);
1101
179k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
179k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
179k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
179k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
179k
                if (res) return res;
1106
179k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
179k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
179k
                i++;
1109
179k
            }
1110
181k
            y += step4;
1111
181k
        }
1112
193k
    return 0;
1113
193k
}
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
45.7k
{
1121
45.7k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
45.7k
    const Dav1dFrameContext *const f = t->f;
1123
45.7k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
45.7k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
45.7k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
45.7k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
45.7k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
45.7k
    const int32_t *const mat = wmp->matrix;
1129
45.7k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
45.7k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
144k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
98.8k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
98.8k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
98.8k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
383k
        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
284k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
284k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
284k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
284k
            const int dx = (int) (mvx >> 16) - 4;
1144
284k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
284k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
284k
            const int dy = (int) (mvy >> 16) - 4;
1147
284k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
284k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
284k
            const pixel *ref_ptr;
1151
284k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
284k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
185k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
185k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
185k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
185k
                                    refp->p.data[pl], ref_stride);
1158
185k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
185k
                ref_stride = 32 * sizeof(pixel);
1160
185k
            } else {
1161
98.2k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
98.2k
            }
1163
284k
            if (dst16 != NULL)
1164
60.9k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
60.9k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
223k
            else
1167
223k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
223k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
284k
        }
1170
98.8k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
22.6k
        else      dst16 += 8 * dstride;
1172
98.8k
    }
1173
45.7k
    return 0;
1174
45.7k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
2.65M
{
1180
2.65M
    Dav1dTileState *const ts = t->ts;
1181
2.65M
    const Dav1dFrameContext *const f = t->f;
1182
2.65M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
2.65M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
2.65M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
2.65M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
2.65M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
2.65M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
2.65M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
2.65M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
2.65M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
2.65M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
2.19M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
2.04M
                           (bh4 > ss_ver || t->by & 1);
1194
2.65M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
2.65M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
2.65M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
2.65M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
2.65M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
5.39M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
2.74M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
2.74M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
5.60M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
2.86M
            if (b->pal_sz[0]) {
1208
17.3k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
17.3k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
17.3k
                const uint8_t *pal_idx;
1211
17.3k
                if (t->frame_thread.pass) {
1212
17.3k
                    const int p = t->frame_thread.pass & 1;
1213
17.3k
                    assert(ts->frame_thread[p].pal_idx);
1214
17.3k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
17.3k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
17.3k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
17.3k
                const pixel *const pal = t->frame_thread.pass ?
1220
17.3k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
17.3k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
17.3k
                    bytefn(t->scratch.pal)[0];
1223
17.3k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
17.3k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
17.3k
                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
17.3k
            }
1229
1230
2.86M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
2.86M
                                     sm_flag(&t->l, by4) |
1232
2.86M
                                     intra_edge_filter_flag);
1233
2.86M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
2.74M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
2.86M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
2.74M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
2.86M
            int y, x;
1238
2.86M
            const int sub_w4 = imin(w4, init_x + 16);
1239
6.52M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
3.65M
                 y += t_dim->h, t->by += t_dim->h)
1241
3.65M
            {
1242
3.65M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
3.65M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
3.65M
                                    t->bx + init_x);
1245
10.9M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
7.26M
                     x += t_dim->w, t->bx += t_dim->w)
1247
7.26M
                {
1248
7.26M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
7.23M
                    int angle = b->y_angle;
1251
7.23M
                    const enum EdgeFlags edge_flags =
1252
7.23M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
5.52M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
7.23M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
5.20M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
7.23M
                    const pixel *top_sb_edge = NULL;
1257
7.23M
                    if (!(t->by & (f->sb_step - 1))) {
1258
1.13M
                        top_sb_edge = f->ipred_edge[0];
1259
1.13M
                        const int sby = t->by >> f->sb_shift;
1260
1.13M
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
1.13M
                    }
1262
7.23M
                    const enum IntraPredMode m =
1263
7.23M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
7.23M
                                                          t->bx > ts->tiling.col_start,
1265
7.23M
                                                          t->by,
1266
7.23M
                                                          t->by > ts->tiling.row_start,
1267
7.23M
                                                          ts->tiling.col_end,
1268
7.23M
                                                          ts->tiling.row_end,
1269
7.23M
                                                          edge_flags, dst,
1270
7.23M
                                                          f->cur.stride[0], top_sb_edge,
1271
7.23M
                                                          b->y_mode, &angle,
1272
7.23M
                                                          t_dim->w, t_dim->h,
1273
7.23M
                                                          f->seq_hdr->intra_edge_filter,
1274
7.23M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
7.23M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
7.23M
                                             t_dim->w * 4, t_dim->h * 4,
1277
7.23M
                                             angle | intra_flags,
1278
7.23M
                                             4 * f->bw - 4 * t->bx,
1279
7.23M
                                             4 * f->bh - 4 * t->by
1280
7.23M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
7.23M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
7.26M
                skip_y_pred: {}
1293
7.26M
                    if (!b->skip) {
1294
2.00M
                        coef *cf;
1295
2.00M
                        int eob;
1296
2.00M
                        enum TxfmType txtp;
1297
2.00M
                        if (t->frame_thread.pass) {
1298
2.00M
                            const int p = t->frame_thread.pass & 1;
1299
2.00M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
2.00M
                            cf = ts->frame_thread[p].cf;
1301
2.00M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
2.00M
                            eob  = cbi >> 5;
1303
2.00M
                            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
2.00M
                        if (eob >= 0) {
1317
1.46M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
1.46M
                            dsp->itx.itxfm_add[b->tx]
1321
1.46M
                                              [txtp](dst,
1322
1.46M
                                                     f->cur.stride[0],
1323
1.46M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.46M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
1.46M
                        }
1328
5.26M
                    } 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
7.26M
                    dst += 4 * t_dim->w;
1333
7.26M
                }
1334
3.65M
                t->bx -= x;
1335
3.65M
            }
1336
2.86M
            t->by -= y;
1337
1338
2.86M
            if (!has_chroma) continue;
1339
1340
2.05M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
2.05M
            if (b->uv_mode == CFL_PRED) {
1343
393k
                assert(!init_x && !init_y);
1344
1345
393k
                int16_t *const ac = t->scratch.ac;
1346
393k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
393k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
393k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
393k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
393k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
393k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
393k
                const int furthest_r =
1354
393k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
393k
                const int furthest_b =
1356
393k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
393k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
393k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
393k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
393k
                                                         cbw4 * 4, cbh4 * 4);
1361
1.18M
                for (int pl = 0; pl < 2; pl++) {
1362
786k
                    if (!b->cfl_alpha[pl]) continue;
1363
632k
                    int angle = 0;
1364
632k
                    const pixel *top_sb_edge = NULL;
1365
632k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
148k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
148k
                        const int sby = t->by >> f->sb_shift;
1368
148k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
148k
                    }
1370
632k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
632k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
632k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
632k
                    const enum IntraPredMode m =
1374
632k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
632k
                                                          ypos, ypos > ystart,
1376
632k
                                                          ts->tiling.col_end >> ss_hor,
1377
632k
                                                          ts->tiling.row_end >> ss_ver,
1378
632k
                                                          0, uv_dst[pl], stride,
1379
632k
                                                          top_sb_edge, DC_PRED, &angle,
1380
632k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
632k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
632k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
632k
                                           uv_t_dim->w * 4,
1384
632k
                                           uv_t_dim->h * 4,
1385
632k
                                           ac, b->cfl_alpha[pl]
1386
632k
                                           HIGHBD_CALL_SUFFIX);
1387
632k
                }
1388
393k
                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.65M
            } else if (b->pal_sz[1]) {
1394
5.31k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
5.31k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
5.31k
                const pixel (*pal)[8];
1397
5.31k
                const uint8_t *pal_idx;
1398
5.31k
                if (t->frame_thread.pass) {
1399
5.31k
                    const int p = t->frame_thread.pass & 1;
1400
5.31k
                    assert(ts->frame_thread[p].pal_idx);
1401
5.31k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
5.31k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
5.31k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
5.31k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
5.31k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
5.31k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
5.31k
                                       f->cur.stride[1], pal[1],
1412
5.31k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
5.31k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
5.31k
                                       f->cur.stride[1], pal[2],
1415
5.31k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
5.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
5.31k
            }
1425
1426
2.05M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
2.05M
                                 sm_uv_flag(&t->l, cby4);
1428
2.05M
            const int uv_sb_has_tr =
1429
2.05M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.95M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
2.05M
            const int uv_sb_has_bl =
1432
2.05M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.95M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
2.05M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
6.15M
            for (int pl = 0; pl < 2; pl++) {
1436
8.69M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
4.58M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
4.59M
                {
1439
4.59M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
4.59M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
4.59M
                                        ((t->bx + init_x) >> ss_hor));
1442
10.8M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
6.26M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
6.27M
                    {
1445
6.27M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
5.64M
                            b->pal_sz[1])
1447
644k
                        {
1448
644k
                            goto skip_uv_pred;
1449
644k
                        }
1450
1451
5.62M
                        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.62M
                        const enum EdgeFlags edge_flags =
1456
5.62M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
2.89M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
4.12M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
5.62M
                            ((x > (init_x >> ss_hor) ||
1460
3.94M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
3.68M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
5.62M
                        const pixel *top_sb_edge = NULL;
1463
5.62M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
1.44M
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
1.44M
                            const int sby = t->by >> f->sb_shift;
1466
1.44M
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
1.44M
                        }
1468
5.62M
                        const enum IntraPredMode uv_mode =
1469
5.62M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
5.62M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
5.62M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
5.62M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
5.62M
                        const enum IntraPredMode m =
1474
5.62M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
5.62M
                                                              ypos, ypos > ystart,
1476
5.62M
                                                              ts->tiling.col_end >> ss_hor,
1477
5.62M
                                                              ts->tiling.row_end >> ss_ver,
1478
5.62M
                                                              edge_flags, dst, stride,
1479
5.62M
                                                              top_sb_edge, uv_mode,
1480
5.62M
                                                              &angle, uv_t_dim->w,
1481
5.62M
                                                              uv_t_dim->h,
1482
5.62M
                                                              f->seq_hdr->intra_edge_filter,
1483
5.62M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
5.62M
                        angle |= intra_edge_filter_flag;
1485
5.62M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
5.62M
                                                 uv_t_dim->w * 4,
1487
5.62M
                                                 uv_t_dim->h * 4,
1488
5.62M
                                                 angle | sm_uv_fl,
1489
5.62M
                                                 (4 * f->bw + ss_hor -
1490
5.62M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
5.62M
                                                 (4 * f->bh + ss_ver -
1492
5.62M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
5.62M
                                                 HIGHBD_CALL_SUFFIX);
1494
5.62M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
6.26M
                    skip_uv_pred: {}
1505
6.26M
                        if (!b->skip) {
1506
2.01M
                            enum TxfmType txtp;
1507
2.01M
                            int eob;
1508
2.01M
                            coef *cf;
1509
2.01M
                            if (t->frame_thread.pass) {
1510
2.01M
                                const int p = t->frame_thread.pass & 1;
1511
2.01M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
2.01M
                                cf = ts->frame_thread[p].cf;
1513
2.01M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
2.01M
                                eob  = cbi >> 5;
1515
2.01M
                                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.01M
                            if (eob >= 0) {
1533
637k
                                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
637k
                                dsp->itx.itxfm_add[b->uvtx]
1537
637k
                                                  [txtp](dst, stride,
1538
637k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
637k
                                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
637k
                            }
1543
4.25M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
6.26M
                        dst += uv_t_dim->w * 4;
1548
6.26M
                    }
1549
4.58M
                    t->bx -= x << ss_hor;
1550
4.58M
                }
1551
4.10M
                t->by -= y << ss_ver;
1552
4.10M
            }
1553
2.05M
        }
1554
2.74M
    }
1555
2.65M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
1.43M
{
1180
1.43M
    Dav1dTileState *const ts = t->ts;
1181
1.43M
    const Dav1dFrameContext *const f = t->f;
1182
1.43M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.43M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.43M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.43M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.43M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.43M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.43M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.43M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.43M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.43M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.35M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.25M
                           (bh4 > ss_ver || t->by & 1);
1194
1.43M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.43M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.43M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.43M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.43M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.92M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.47M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.47M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.02M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.53M
            if (b->pal_sz[0]) {
1208
7.83k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.83k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.83k
                const uint8_t *pal_idx;
1211
7.83k
                if (t->frame_thread.pass) {
1212
7.83k
                    const int p = t->frame_thread.pass & 1;
1213
7.83k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.83k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.83k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.83k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.83k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.83k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.83k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.83k
                    bytefn(t->scratch.pal)[0];
1223
7.83k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.83k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.83k
                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.83k
            }
1229
1230
1.53M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.53M
                                     sm_flag(&t->l, by4) |
1232
1.53M
                                     intra_edge_filter_flag);
1233
1.53M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.47M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.53M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.47M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.53M
            int y, x;
1238
1.53M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.49M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.95M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.94M
            {
1242
1.94M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.94M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.94M
                                    t->bx + init_x);
1245
6.17M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
4.22M
                     x += t_dim->w, t->bx += t_dim->w)
1247
4.21M
                {
1248
4.21M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
4.20M
                    int angle = b->y_angle;
1251
4.20M
                    const enum EdgeFlags edge_flags =
1252
4.20M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
3.29M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
4.20M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
3.12M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
4.20M
                    const pixel *top_sb_edge = NULL;
1257
4.20M
                    if (!(t->by & (f->sb_step - 1))) {
1258
596k
                        top_sb_edge = f->ipred_edge[0];
1259
596k
                        const int sby = t->by >> f->sb_shift;
1260
596k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
596k
                    }
1262
4.20M
                    const enum IntraPredMode m =
1263
4.20M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
4.20M
                                                          t->bx > ts->tiling.col_start,
1265
4.20M
                                                          t->by,
1266
4.20M
                                                          t->by > ts->tiling.row_start,
1267
4.20M
                                                          ts->tiling.col_end,
1268
4.20M
                                                          ts->tiling.row_end,
1269
4.20M
                                                          edge_flags, dst,
1270
4.20M
                                                          f->cur.stride[0], top_sb_edge,
1271
4.20M
                                                          b->y_mode, &angle,
1272
4.20M
                                                          t_dim->w, t_dim->h,
1273
4.20M
                                                          f->seq_hdr->intra_edge_filter,
1274
4.20M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
4.20M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
4.20M
                                             t_dim->w * 4, t_dim->h * 4,
1277
4.20M
                                             angle | intra_flags,
1278
4.20M
                                             4 * f->bw - 4 * t->bx,
1279
4.20M
                                             4 * f->bh - 4 * t->by
1280
4.20M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
4.20M
                    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.22M
                skip_y_pred: {}
1293
4.22M
                    if (!b->skip) {
1294
1.01M
                        coef *cf;
1295
1.01M
                        int eob;
1296
1.01M
                        enum TxfmType txtp;
1297
1.01M
                        if (t->frame_thread.pass) {
1298
1.01M
                            const int p = t->frame_thread.pass & 1;
1299
1.01M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.01M
                            cf = ts->frame_thread[p].cf;
1301
1.01M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.01M
                            eob  = cbi >> 5;
1303
1.01M
                            txtp = cbi & 0x1f;
1304
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.01M
                        if (eob >= 0) {
1317
765k
                            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
765k
                            dsp->itx.itxfm_add[b->tx]
1321
765k
                                              [txtp](dst,
1322
765k
                                                     f->cur.stride[0],
1323
765k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
765k
                            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
765k
                        }
1328
3.20M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
4.22M
                    dst += 4 * t_dim->w;
1333
4.22M
                }
1334
1.95M
                t->bx -= x;
1335
1.95M
            }
1336
1.54M
            t->by -= y;
1337
1338
1.54M
            if (!has_chroma) continue;
1339
1340
1.23M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.23M
            if (b->uv_mode == CFL_PRED) {
1343
238k
                assert(!init_x && !init_y);
1344
1345
238k
                int16_t *const ac = t->scratch.ac;
1346
238k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
238k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
238k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
238k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
238k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
238k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
238k
                const int furthest_r =
1354
238k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
238k
                const int furthest_b =
1356
238k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
238k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
238k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
238k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
238k
                                                         cbw4 * 4, cbh4 * 4);
1361
714k
                for (int pl = 0; pl < 2; pl++) {
1362
476k
                    if (!b->cfl_alpha[pl]) continue;
1363
378k
                    int angle = 0;
1364
378k
                    const pixel *top_sb_edge = NULL;
1365
378k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
79.1k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
79.1k
                        const int sby = t->by >> f->sb_shift;
1368
79.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
79.1k
                    }
1370
378k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
378k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
378k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
378k
                    const enum IntraPredMode m =
1374
378k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
378k
                                                          ypos, ypos > ystart,
1376
378k
                                                          ts->tiling.col_end >> ss_hor,
1377
378k
                                                          ts->tiling.row_end >> ss_ver,
1378
378k
                                                          0, uv_dst[pl], stride,
1379
378k
                                                          top_sb_edge, DC_PRED, &angle,
1380
378k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
378k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
378k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
378k
                                           uv_t_dim->w * 4,
1384
378k
                                           uv_t_dim->h * 4,
1385
378k
                                           ac, b->cfl_alpha[pl]
1386
378k
                                           HIGHBD_CALL_SUFFIX);
1387
378k
                }
1388
238k
                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.00M
            } else if (b->pal_sz[1]) {
1394
3.07k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.07k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.07k
                const pixel (*pal)[8];
1397
3.07k
                const uint8_t *pal_idx;
1398
3.07k
                if (t->frame_thread.pass) {
1399
3.07k
                    const int p = t->frame_thread.pass & 1;
1400
3.07k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.07k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.07k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.07k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.07k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.07k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.07k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.07k
                                       f->cur.stride[1], pal[1],
1412
3.07k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.07k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.07k
                                       f->cur.stride[1], pal[2],
1415
3.07k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.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
3.07k
            }
1425
1426
1.23M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.23M
                                 sm_uv_flag(&t->l, cby4);
1428
1.23M
            const int uv_sb_has_tr =
1429
1.23M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.19M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.23M
            const int uv_sb_has_bl =
1432
1.23M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.19M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.23M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.70M
            for (int pl = 0; pl < 2; pl++) {
1436
5.16M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.69M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.69M
                {
1439
2.69M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.69M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.69M
                                        ((t->bx + init_x) >> ss_hor));
1442
6.10M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
3.41M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
3.41M
                    {
1445
3.41M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
3.03M
                            b->pal_sz[1])
1447
385k
                        {
1448
385k
                            goto skip_uv_pred;
1449
385k
                        }
1450
1451
3.02M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
3.02M
                        const enum EdgeFlags edge_flags =
1456
3.02M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.45M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
2.16M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
3.02M
                            ((x > (init_x >> ss_hor) ||
1460
2.31M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.92M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
3.02M
                        const pixel *top_sb_edge = NULL;
1463
3.02M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
782k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
782k
                            const int sby = t->by >> f->sb_shift;
1466
782k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
782k
                        }
1468
3.02M
                        const enum IntraPredMode uv_mode =
1469
3.02M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
3.02M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
3.02M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
3.02M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
3.02M
                        const enum IntraPredMode m =
1474
3.02M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
3.02M
                                                              ypos, ypos > ystart,
1476
3.02M
                                                              ts->tiling.col_end >> ss_hor,
1477
3.02M
                                                              ts->tiling.row_end >> ss_ver,
1478
3.02M
                                                              edge_flags, dst, stride,
1479
3.02M
                                                              top_sb_edge, uv_mode,
1480
3.02M
                                                              &angle, uv_t_dim->w,
1481
3.02M
                                                              uv_t_dim->h,
1482
3.02M
                                                              f->seq_hdr->intra_edge_filter,
1483
3.02M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
3.02M
                        angle |= intra_edge_filter_flag;
1485
3.02M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
3.02M
                                                 uv_t_dim->w * 4,
1487
3.02M
                                                 uv_t_dim->h * 4,
1488
3.02M
                                                 angle | sm_uv_fl,
1489
3.02M
                                                 (4 * f->bw + ss_hor -
1490
3.02M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
3.02M
                                                 (4 * f->bh + ss_ver -
1492
3.02M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
3.02M
                                                 HIGHBD_CALL_SUFFIX);
1494
3.02M
                        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.41M
                    skip_uv_pred: {}
1505
3.41M
                        if (!b->skip) {
1506
1.06M
                            enum TxfmType txtp;
1507
1.06M
                            int eob;
1508
1.06M
                            coef *cf;
1509
1.06M
                            if (t->frame_thread.pass) {
1510
1.06M
                                const int p = t->frame_thread.pass & 1;
1511
1.06M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.06M
                                cf = ts->frame_thread[p].cf;
1513
1.06M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.06M
                                eob  = cbi >> 5;
1515
1.06M
                                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.06M
                            if (eob >= 0) {
1533
330k
                                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
330k
                                dsp->itx.itxfm_add[b->uvtx]
1537
330k
                                                  [txtp](dst, stride,
1538
330k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
330k
                                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
330k
                            }
1543
2.34M
                        } 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.41M
                        dst += uv_t_dim->w * 4;
1548
3.41M
                    }
1549
2.69M
                    t->bx -= x << ss_hor;
1550
2.69M
                }
1551
2.46M
                t->by -= y << ss_ver;
1552
2.46M
            }
1553
1.23M
        }
1554
1.47M
    }
1555
1.43M
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
1.21M
{
1180
1.21M
    Dav1dTileState *const ts = t->ts;
1181
1.21M
    const Dav1dFrameContext *const f = t->f;
1182
1.21M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.21M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.21M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.21M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.21M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.21M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.21M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.21M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.21M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.21M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
839k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
791k
                           (bh4 > ss_ver || t->by & 1);
1194
1.21M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.21M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.21M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.21M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.21M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.46M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.26M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.26M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.58M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.32M
            if (b->pal_sz[0]) {
1208
9.54k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
9.54k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
9.54k
                const uint8_t *pal_idx;
1211
9.54k
                if (t->frame_thread.pass) {
1212
9.54k
                    const int p = t->frame_thread.pass & 1;
1213
9.54k
                    assert(ts->frame_thread[p].pal_idx);
1214
9.54k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
9.54k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
9.54k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
9.54k
                const pixel *const pal = t->frame_thread.pass ?
1220
9.54k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
9.54k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
9.54k
                    bytefn(t->scratch.pal)[0];
1223
9.54k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
9.54k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
9.54k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
9.54k
            }
1229
1230
1.32M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.32M
                                     sm_flag(&t->l, by4) |
1232
1.32M
                                     intra_edge_filter_flag);
1233
1.32M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.26M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.32M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.26M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.32M
            int y, x;
1238
1.32M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.02M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.70M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.70M
            {
1242
1.70M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.70M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.70M
                                    t->bx + init_x);
1245
4.74M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.04M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.04M
                {
1248
3.04M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.02M
                    int angle = b->y_angle;
1251
3.02M
                    const enum EdgeFlags edge_flags =
1252
3.02M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.23M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.02M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.07M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.02M
                    const pixel *top_sb_edge = NULL;
1257
3.02M
                    if (!(t->by & (f->sb_step - 1))) {
1258
542k
                        top_sb_edge = f->ipred_edge[0];
1259
542k
                        const int sby = t->by >> f->sb_shift;
1260
542k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
542k
                    }
1262
3.02M
                    const enum IntraPredMode m =
1263
3.02M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.02M
                                                          t->bx > ts->tiling.col_start,
1265
3.02M
                                                          t->by,
1266
3.02M
                                                          t->by > ts->tiling.row_start,
1267
3.02M
                                                          ts->tiling.col_end,
1268
3.02M
                                                          ts->tiling.row_end,
1269
3.02M
                                                          edge_flags, dst,
1270
3.02M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.02M
                                                          b->y_mode, &angle,
1272
3.02M
                                                          t_dim->w, t_dim->h,
1273
3.02M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.02M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.02M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.02M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.02M
                                             angle | intra_flags,
1278
3.02M
                                             4 * f->bw - 4 * t->bx,
1279
3.02M
                                             4 * f->bh - 4 * t->by
1280
3.02M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.02M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
3.04M
                skip_y_pred: {}
1293
3.04M
                    if (!b->skip) {
1294
986k
                        coef *cf;
1295
986k
                        int eob;
1296
986k
                        enum TxfmType txtp;
1297
986k
                        if (t->frame_thread.pass) {
1298
986k
                            const int p = t->frame_thread.pass & 1;
1299
986k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
986k
                            cf = ts->frame_thread[p].cf;
1301
986k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
986k
                            eob  = cbi >> 5;
1303
986k
                            txtp = cbi & 0x1f;
1304
986k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
986k
                        if (eob >= 0) {
1317
704k
                            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
704k
                            dsp->itx.itxfm_add[b->tx]
1321
704k
                                              [txtp](dst,
1322
704k
                                                     f->cur.stride[0],
1323
704k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
704k
                            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
704k
                        }
1328
2.05M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
3.04M
                    dst += 4 * t_dim->w;
1333
3.04M
                }
1334
1.70M
                t->bx -= x;
1335
1.70M
            }
1336
1.32M
            t->by -= y;
1337
1338
1.32M
            if (!has_chroma) continue;
1339
1340
811k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
811k
            if (b->uv_mode == CFL_PRED) {
1343
155k
                assert(!init_x && !init_y);
1344
1345
155k
                int16_t *const ac = t->scratch.ac;
1346
155k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
155k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
155k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
155k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
155k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
155k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
155k
                const int furthest_r =
1354
155k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
155k
                const int furthest_b =
1356
155k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
155k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
155k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
155k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
155k
                                                         cbw4 * 4, cbh4 * 4);
1361
466k
                for (int pl = 0; pl < 2; pl++) {
1362
310k
                    if (!b->cfl_alpha[pl]) continue;
1363
254k
                    int angle = 0;
1364
254k
                    const pixel *top_sb_edge = NULL;
1365
254k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
69.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
69.0k
                        const int sby = t->by >> f->sb_shift;
1368
69.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
69.0k
                    }
1370
254k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
254k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
254k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
254k
                    const enum IntraPredMode m =
1374
254k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
254k
                                                          ypos, ypos > ystart,
1376
254k
                                                          ts->tiling.col_end >> ss_hor,
1377
254k
                                                          ts->tiling.row_end >> ss_ver,
1378
254k
                                                          0, uv_dst[pl], stride,
1379
254k
                                                          top_sb_edge, DC_PRED, &angle,
1380
254k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
254k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
254k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
254k
                                           uv_t_dim->w * 4,
1384
254k
                                           uv_t_dim->h * 4,
1385
254k
                                           ac, b->cfl_alpha[pl]
1386
254k
                                           HIGHBD_CALL_SUFFIX);
1387
254k
                }
1388
155k
                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
656k
            } else if (b->pal_sz[1]) {
1394
2.24k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.24k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.24k
                const pixel (*pal)[8];
1397
2.24k
                const uint8_t *pal_idx;
1398
2.24k
                if (t->frame_thread.pass) {
1399
2.24k
                    const int p = t->frame_thread.pass & 1;
1400
2.24k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.24k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.24k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.24k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.24k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.24k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.24k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.24k
                                       f->cur.stride[1], pal[1],
1412
2.24k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.24k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.24k
                                       f->cur.stride[1], pal[2],
1415
2.24k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.24k
                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.24k
            }
1425
1426
811k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
811k
                                 sm_uv_flag(&t->l, cby4);
1428
811k
            const int uv_sb_has_tr =
1429
811k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
767k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
811k
            const int uv_sb_has_bl =
1432
811k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
767k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
811k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.44M
            for (int pl = 0; pl < 2; pl++) {
1436
3.52M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.89M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.89M
                {
1439
1.89M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.89M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.89M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.75M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.85M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.85M
                    {
1445
2.85M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.60M
                            b->pal_sz[1])
1447
259k
                        {
1448
259k
                            goto skip_uv_pred;
1449
259k
                        }
1450
1451
2.59M
                        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.59M
                        const enum EdgeFlags edge_flags =
1456
2.59M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.44M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.95M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.59M
                            ((x > (init_x >> ss_hor) ||
1460
1.63M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.75M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.59M
                        const pixel *top_sb_edge = NULL;
1463
2.59M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
664k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
664k
                            const int sby = t->by >> f->sb_shift;
1466
664k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
664k
                        }
1468
2.59M
                        const enum IntraPredMode uv_mode =
1469
2.59M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.59M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.59M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.59M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.59M
                        const enum IntraPredMode m =
1474
2.59M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.59M
                                                              ypos, ypos > ystart,
1476
2.59M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.59M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.59M
                                                              edge_flags, dst, stride,
1479
2.59M
                                                              top_sb_edge, uv_mode,
1480
2.59M
                                                              &angle, uv_t_dim->w,
1481
2.59M
                                                              uv_t_dim->h,
1482
2.59M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.59M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.59M
                        angle |= intra_edge_filter_flag;
1485
2.59M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.59M
                                                 uv_t_dim->w * 4,
1487
2.59M
                                                 uv_t_dim->h * 4,
1488
2.59M
                                                 angle | sm_uv_fl,
1489
2.59M
                                                 (4 * f->bw + ss_hor -
1490
2.59M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.59M
                                                 (4 * f->bh + ss_ver -
1492
2.59M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.59M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.59M
                        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.85M
                    skip_uv_pred: {}
1505
2.85M
                        if (!b->skip) {
1506
952k
                            enum TxfmType txtp;
1507
952k
                            int eob;
1508
952k
                            coef *cf;
1509
952k
                            if (t->frame_thread.pass) {
1510
952k
                                const int p = t->frame_thread.pass & 1;
1511
952k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
952k
                                cf = ts->frame_thread[p].cf;
1513
952k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
952k
                                eob  = cbi >> 5;
1515
952k
                                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
952k
                            if (eob >= 0) {
1533
307k
                                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
307k
                                dsp->itx.itxfm_add[b->uvtx]
1537
307k
                                                  [txtp](dst, stride,
1538
307k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
307k
                                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
307k
                            }
1543
1.90M
                        } 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.85M
                        dst += uv_t_dim->w * 4;
1548
2.85M
                    }
1549
1.89M
                    t->bx -= x << ss_hor;
1550
1.89M
                }
1551
1.63M
                t->by -= y << ss_ver;
1552
1.63M
            }
1553
811k
        }
1554
1.26M
    }
1555
1.21M
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
813k
{
1560
813k
    Dav1dTileState *const ts = t->ts;
1561
813k
    const Dav1dFrameContext *const f = t->f;
1562
813k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
813k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
813k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
813k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
813k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
813k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
813k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
813k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
813k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
594k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
561k
                           (bh4 > ss_ver || t->by & 1);
1573
813k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
813k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
813k
    int res;
1576
1577
    // prediction
1578
813k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
813k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
813k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
813k
    const ptrdiff_t uvdstoff =
1582
813k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
813k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
212k
        assert(!f->frame_hdr->super_res.enabled);
1586
212k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
212k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
212k
        if (res) return res;
1589
434k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
289k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
289k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
289k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
289k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
289k
            if (res) return res;
1595
289k
        }
1596
600k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
514k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
514k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
514k
        if (imin(bw4, bh4) > 1 &&
1601
327k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
318k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
14.2k
        {
1604
14.2k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
14.2k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
14.2k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
14.2k
            if (res) return res;
1608
500k
        } else {
1609
500k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
500k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
500k
            if (res) return res;
1612
500k
            if (b->motion_mode == MM_OBMC) {
1613
84.2k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
84.2k
                if (res) return res;
1615
84.2k
            }
1616
500k
        }
1617
514k
        if (b->interintra_type) {
1618
20.9k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
20.9k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
17.4k
                                   SMOOTH_PRED : b->interintra_mode;
1621
20.9k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
20.9k
            int angle = 0;
1623
20.9k
            const pixel *top_sb_edge = NULL;
1624
20.9k
            if (!(t->by & (f->sb_step - 1))) {
1625
9.25k
                top_sb_edge = f->ipred_edge[0];
1626
9.25k
                const int sby = t->by >> f->sb_shift;
1627
9.25k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
9.25k
            }
1629
20.9k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
20.9k
                                                  t->by, t->by > ts->tiling.row_start,
1631
20.9k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
20.9k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
20.9k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
20.9k
                                                  HIGHBD_CALL_SUFFIX);
1635
20.9k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
20.9k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
20.9k
                                     HIGHBD_CALL_SUFFIX);
1638
20.9k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
20.9k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
20.9k
        }
1641
1642
514k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
321k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
321k
        refmvs_block *const *r;
1647
321k
        if (is_sub8x8) {
1648
30.9k
            assert(ss_hor == 1);
1649
30.9k
            r = &t->rt.r[(t->by & 31) + 5];
1650
30.9k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
30.9k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
30.9k
            if (bw4 == 1 && bh4 == ss_ver)
1653
4.51k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
30.9k
        }
1655
1656
        // chroma prediction
1657
321k
        if (is_sub8x8) {
1658
30.1k
            assert(ss_hor == 1);
1659
30.1k
            ptrdiff_t h_off = 0, v_off = 0;
1660
30.1k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
13.2k
                for (int pl = 0; pl < 2; pl++) {
1662
8.82k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
8.82k
                             NULL, f->cur.stride[1],
1664
8.82k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
8.82k
                             r[-1][t->bx - 1].mv.mv[0],
1666
8.82k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
8.82k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
8.82k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
8.82k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
8.82k
                    if (res) return res;
1671
8.82k
                }
1672
4.41k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
4.41k
                h_off = 2;
1674
4.41k
            }
1675
30.1k
            if (bw4 == 1) {
1676
15.4k
                const enum Filter2d left_filter_2d =
1677
15.4k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
46.3k
                for (int pl = 0; pl < 2; pl++) {
1679
30.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
30.8k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
30.8k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
30.8k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
30.8k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
30.8k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
30.8k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
30.8k
                    if (res) return res;
1687
30.8k
                }
1688
15.4k
                h_off = 2;
1689
15.4k
            }
1690
30.1k
            if (bh4 == ss_ver) {
1691
19.1k
                const enum Filter2d top_filter_2d =
1692
19.1k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
57.3k
                for (int pl = 0; pl < 2; pl++) {
1694
38.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
38.2k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
38.2k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
38.2k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
38.2k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
38.2k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
38.2k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
38.2k
                    if (res) return res;
1702
38.2k
                }
1703
19.1k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
19.1k
            }
1705
90.4k
            for (int pl = 0; pl < 2; pl++) {
1706
60.2k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
60.2k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
60.2k
                         refp, b->ref[0], filter_2d);
1709
60.2k
                if (res) return res;
1710
60.2k
            }
1711
291k
        } else {
1712
291k
            if (imin(cbw4, cbh4) > 1 &&
1713
148k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
143k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
8.89k
            {
1716
26.6k
                for (int pl = 0; pl < 2; pl++) {
1717
17.7k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
17.7k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
17.7k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
17.7k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
17.7k
                    if (res) return res;
1722
17.7k
                }
1723
282k
            } else {
1724
846k
                for (int pl = 0; pl < 2; pl++) {
1725
564k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
564k
                             NULL, f->cur.stride[1],
1727
564k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
564k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
564k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
564k
                    if (res) return res;
1731
564k
                    if (b->motion_mode == MM_OBMC) {
1732
108k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
108k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
108k
                        if (res) return res;
1735
108k
                    }
1736
564k
                }
1737
282k
            }
1738
291k
            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
18.1k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
54.5k
                for (int pl = 0; pl < 2; pl++) {
1745
36.3k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
36.3k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
36.3k
                    enum IntraPredMode m =
1748
36.3k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
30.5k
                        SMOOTH_PRED : b->interintra_mode;
1750
36.3k
                    int angle = 0;
1751
36.3k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
36.3k
                    const pixel *top_sb_edge = NULL;
1753
36.3k
                    if (!(t->by & (f->sb_step - 1))) {
1754
14.6k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
14.6k
                        const int sby = t->by >> f->sb_shift;
1756
14.6k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
14.6k
                    }
1758
36.3k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
36.3k
                                                          (t->bx >> ss_hor) >
1760
36.3k
                                                              (ts->tiling.col_start >> ss_hor),
1761
36.3k
                                                          t->by >> ss_ver,
1762
36.3k
                                                          (t->by >> ss_ver) >
1763
36.3k
                                                              (ts->tiling.row_start >> ss_ver),
1764
36.3k
                                                          ts->tiling.col_end >> ss_hor,
1765
36.3k
                                                          ts->tiling.row_end >> ss_ver,
1766
36.3k
                                                          0, uvdst, f->cur.stride[1],
1767
36.3k
                                                          top_sb_edge, m,
1768
36.3k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
36.3k
                                                          HIGHBD_CALL_SUFFIX);
1770
36.3k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
36.3k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
36.3k
                                             HIGHBD_CALL_SUFFIX);
1773
36.3k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
36.3k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
36.3k
                }
1776
18.1k
            }
1777
291k
        }
1778
1779
514k
    skip_inter_chroma_pred: {}
1780
514k
        t->tl_4x4_filter = filter_2d;
1781
514k
    } else {
1782
85.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
85.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
85.9k
        int jnt_weight;
1786
85.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
85.9k
        const uint8_t *mask;
1788
1789
257k
        for (int i = 0; i < 2; i++) {
1790
171k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
171k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
7.12k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
7.12k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
7.12k
                if (res) return res;
1796
164k
            } else {
1797
164k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
164k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
164k
                if (res) return res;
1800
164k
            }
1801
171k
        }
1802
85.9k
        switch (b->comp_type) {
1803
57.5k
        case COMP_INTER_AVG:
1804
57.5k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
57.5k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
57.5k
            break;
1807
12.5k
        case COMP_INTER_WEIGHTED_AVG:
1808
12.5k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
12.5k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
12.5k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
12.5k
            break;
1812
10.0k
        case COMP_INTER_SEG:
1813
10.0k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
10.0k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
10.0k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
10.0k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
10.0k
            mask = seg_mask;
1818
10.0k
            break;
1819
5.72k
        case COMP_INTER_WEDGE:
1820
5.72k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
5.72k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
5.72k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
5.72k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
5.72k
            if (has_chroma)
1825
4.47k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
5.72k
            break;
1827
85.9k
        }
1828
1829
        // chroma
1830
190k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
381k
            for (int i = 0; i < 2; i++) {
1832
254k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
254k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
39.2k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
6.59k
                {
1836
6.59k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
6.59k
                                      b_dim, 1 + pl,
1838
6.59k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
6.59k
                    if (res) return res;
1840
247k
                } else {
1841
247k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
247k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
247k
                    if (res) return res;
1844
247k
                }
1845
254k
            }
1846
127k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
127k
            switch (b->comp_type) {
1848
83.4k
            case COMP_INTER_AVG:
1849
83.4k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
83.4k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
83.4k
                            HIGHBD_CALL_SUFFIX);
1852
83.4k
                break;
1853
18.1k
            case COMP_INTER_WEIGHTED_AVG:
1854
18.1k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
18.1k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
18.1k
                              HIGHBD_CALL_SUFFIX);
1857
18.1k
                break;
1858
8.94k
            case COMP_INTER_WEDGE:
1859
25.6k
            case COMP_INTER_SEG:
1860
25.6k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
25.6k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
25.6k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
25.6k
                             HIGHBD_CALL_SUFFIX);
1864
25.6k
                break;
1865
127k
            }
1866
127k
        }
1867
85.9k
    }
1868
1869
812k
    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
812k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
812k
    if (b->skip) {
1882
        // reset coef contexts
1883
392k
        BlockContext *const a = t->a;
1884
392k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
392k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
392k
        if (has_chroma) {
1887
238k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
238k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
238k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
238k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
238k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
238k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
238k
        }
1894
392k
        return 0;
1895
392k
    }
1896
1897
420k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
420k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
420k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
851k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
871k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
440k
            int y_off = !!init_y, y;
1905
440k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
908k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
468k
                 y += ytx->h, y_off++)
1908
468k
            {
1909
468k
                int x, x_off = !!init_x;
1910
1.02M
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
559k
                     x += ytx->w, x_off++)
1912
559k
                {
1913
559k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
559k
                                   x_off, y_off, &dst[x * 4]);
1915
559k
                    t->bx += ytx->w;
1916
559k
                }
1917
468k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
468k
                t->bx -= x;
1919
468k
                t->by += ytx->h;
1920
468k
            }
1921
440k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
440k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
921k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
614k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
614k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
614k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.28M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
670k
                {
1931
670k
                    int x;
1932
670k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.50M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
831k
                    {
1935
831k
                        coef *cf;
1936
831k
                        int eob;
1937
831k
                        enum TxfmType txtp;
1938
831k
                        if (t->frame_thread.pass) {
1939
831k
                            const int p = t->frame_thread.pass & 1;
1940
831k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
831k
                            cf = ts->frame_thread[p].cf;
1942
831k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
831k
                            eob  = cbi >> 5;
1944
831k
                            txtp = cbi & 0x1f;
1945
831k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
831k
                        if (eob >= 0) {
1964
239k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
239k
                            dsp->itx.itxfm_add[b->uvtx]
1967
239k
                                              [txtp](&uvdst[4 * x],
1968
239k
                                                     f->cur.stride[1],
1969
239k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
239k
                            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
239k
                        }
1974
831k
                        t->bx += uvtx->w << ss_hor;
1975
831k
                    }
1976
670k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
670k
                    t->bx -= x << ss_hor;
1978
670k
                    t->by += uvtx->h << ss_ver;
1979
670k
                }
1980
614k
                t->by -= y << ss_ver;
1981
614k
            }
1982
440k
        }
1983
431k
    }
1984
420k
    return 0;
1985
812k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
423k
{
1560
423k
    Dav1dTileState *const ts = t->ts;
1561
423k
    const Dav1dFrameContext *const f = t->f;
1562
423k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
423k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
423k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
423k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
423k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
423k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
423k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
423k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
423k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
367k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
344k
                           (bh4 > ss_ver || t->by & 1);
1573
423k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
423k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
423k
    int res;
1576
1577
    // prediction
1578
423k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
423k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
423k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
423k
    const ptrdiff_t uvdstoff =
1582
423k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
423k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
132k
        assert(!f->frame_hdr->super_res.enabled);
1586
132k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
132k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
132k
        if (res) return res;
1589
275k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
183k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
183k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
183k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
183k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
183k
            if (res) return res;
1595
183k
        }
1596
291k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
250k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
250k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
250k
        if (imin(bw4, bh4) > 1 &&
1601
164k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
158k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
8.40k
        {
1604
8.40k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
8.40k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
8.40k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
8.40k
            if (res) return res;
1608
241k
        } else {
1609
241k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
241k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
241k
            if (res) return res;
1612
241k
            if (b->motion_mode == MM_OBMC) {
1613
39.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
39.1k
                if (res) return res;
1615
39.1k
            }
1616
241k
        }
1617
250k
        if (b->interintra_type) {
1618
12.4k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
12.4k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
10.3k
                                   SMOOTH_PRED : b->interintra_mode;
1621
12.4k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
12.4k
            int angle = 0;
1623
12.4k
            const pixel *top_sb_edge = NULL;
1624
12.4k
            if (!(t->by & (f->sb_step - 1))) {
1625
5.56k
                top_sb_edge = f->ipred_edge[0];
1626
5.56k
                const int sby = t->by >> f->sb_shift;
1627
5.56k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
5.56k
            }
1629
12.4k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
12.4k
                                                  t->by, t->by > ts->tiling.row_start,
1631
12.4k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
12.4k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
12.4k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
12.4k
                                                  HIGHBD_CALL_SUFFIX);
1635
12.4k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
12.4k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
12.4k
                                     HIGHBD_CALL_SUFFIX);
1638
12.4k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
12.4k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
12.4k
        }
1641
1642
250k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
198k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
198k
        refmvs_block *const *r;
1647
198k
        if (is_sub8x8) {
1648
17.6k
            assert(ss_hor == 1);
1649
17.6k
            r = &t->rt.r[(t->by & 31) + 5];
1650
17.6k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
17.6k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
17.6k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.48k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
17.6k
        }
1655
1656
        // chroma prediction
1657
198k
        if (is_sub8x8) {
1658
17.3k
            assert(ss_hor == 1);
1659
17.3k
            ptrdiff_t h_off = 0, v_off = 0;
1660
17.3k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
7.27k
                for (int pl = 0; pl < 2; pl++) {
1662
4.85k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
4.85k
                             NULL, f->cur.stride[1],
1664
4.85k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
4.85k
                             r[-1][t->bx - 1].mv.mv[0],
1666
4.85k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
4.85k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
4.85k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
4.85k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
4.85k
                    if (res) return res;
1671
4.85k
                }
1672
2.42k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.42k
                h_off = 2;
1674
2.42k
            }
1675
17.3k
            if (bw4 == 1) {
1676
8.78k
                const enum Filter2d left_filter_2d =
1677
8.78k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
26.3k
                for (int pl = 0; pl < 2; pl++) {
1679
17.5k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
17.5k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
17.5k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
17.5k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
17.5k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
17.5k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
17.5k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
17.5k
                    if (res) return res;
1687
17.5k
                }
1688
8.78k
                h_off = 2;
1689
8.78k
            }
1690
17.3k
            if (bh4 == ss_ver) {
1691
11.0k
                const enum Filter2d top_filter_2d =
1692
11.0k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
33.1k
                for (int pl = 0; pl < 2; pl++) {
1694
22.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
22.0k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
22.0k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
22.0k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
22.0k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
22.0k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
22.0k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
22.0k
                    if (res) return res;
1702
22.0k
                }
1703
11.0k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
11.0k
            }
1705
52.1k
            for (int pl = 0; pl < 2; pl++) {
1706
34.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
34.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
34.7k
                         refp, b->ref[0], filter_2d);
1709
34.7k
                if (res) return res;
1710
34.7k
            }
1711
180k
        } else {
1712
180k
            if (imin(cbw4, cbh4) > 1 &&
1713
92.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
89.2k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
5.27k
            {
1716
15.8k
                for (int pl = 0; pl < 2; pl++) {
1717
10.5k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
10.5k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
10.5k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
10.5k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
10.5k
                    if (res) return res;
1722
10.5k
                }
1723
175k
            } else {
1724
526k
                for (int pl = 0; pl < 2; pl++) {
1725
350k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
350k
                             NULL, f->cur.stride[1],
1727
350k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
350k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
350k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
350k
                    if (res) return res;
1731
350k
                    if (b->motion_mode == MM_OBMC) {
1732
65.8k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
65.8k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
65.8k
                        if (res) return res;
1735
65.8k
                    }
1736
350k
                }
1737
175k
            }
1738
180k
            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
11.2k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
33.6k
                for (int pl = 0; pl < 2; pl++) {
1745
22.4k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
22.4k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
22.4k
                    enum IntraPredMode m =
1748
22.4k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
18.8k
                        SMOOTH_PRED : b->interintra_mode;
1750
22.4k
                    int angle = 0;
1751
22.4k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
22.4k
                    const pixel *top_sb_edge = NULL;
1753
22.4k
                    if (!(t->by & (f->sb_step - 1))) {
1754
9.23k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
9.23k
                        const int sby = t->by >> f->sb_shift;
1756
9.23k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
9.23k
                    }
1758
22.4k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
22.4k
                                                          (t->bx >> ss_hor) >
1760
22.4k
                                                              (ts->tiling.col_start >> ss_hor),
1761
22.4k
                                                          t->by >> ss_ver,
1762
22.4k
                                                          (t->by >> ss_ver) >
1763
22.4k
                                                              (ts->tiling.row_start >> ss_ver),
1764
22.4k
                                                          ts->tiling.col_end >> ss_hor,
1765
22.4k
                                                          ts->tiling.row_end >> ss_ver,
1766
22.4k
                                                          0, uvdst, f->cur.stride[1],
1767
22.4k
                                                          top_sb_edge, m,
1768
22.4k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
22.4k
                                                          HIGHBD_CALL_SUFFIX);
1770
22.4k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
22.4k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
22.4k
                                             HIGHBD_CALL_SUFFIX);
1773
22.4k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
22.4k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
22.4k
                }
1776
11.2k
            }
1777
180k
        }
1778
1779
249k
    skip_inter_chroma_pred: {}
1780
249k
        t->tl_4x4_filter = filter_2d;
1781
249k
    } else {
1782
41.7k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
41.7k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
41.7k
        int jnt_weight;
1786
41.7k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
41.7k
        const uint8_t *mask;
1788
1789
125k
        for (int i = 0; i < 2; i++) {
1790
83.4k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
83.4k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
3.34k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
3.34k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
3.34k
                if (res) return res;
1796
80.1k
            } else {
1797
80.1k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
80.1k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
80.1k
                if (res) return res;
1800
80.1k
            }
1801
83.4k
        }
1802
41.7k
        switch (b->comp_type) {
1803
28.7k
        case COMP_INTER_AVG:
1804
28.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
28.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
28.7k
            break;
1807
5.15k
        case COMP_INTER_WEIGHTED_AVG:
1808
5.15k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
5.15k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
5.15k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
5.15k
            break;
1812
5.00k
        case COMP_INTER_SEG:
1813
5.00k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
5.00k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
5.00k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
5.00k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
5.00k
            mask = seg_mask;
1818
5.00k
            break;
1819
2.80k
        case COMP_INTER_WEDGE:
1820
2.80k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.80k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.80k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.80k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.80k
            if (has_chroma)
1825
2.25k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.80k
            break;
1827
41.7k
        }
1828
1829
        // chroma
1830
99.8k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
199k
            for (int i = 0; i < 2; i++) {
1832
133k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
133k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
19.6k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.39k
                {
1836
3.39k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.39k
                                      b_dim, 1 + pl,
1838
3.39k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.39k
                    if (res) return res;
1840
129k
                } else {
1841
129k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
129k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
129k
                    if (res) return res;
1844
129k
                }
1845
133k
            }
1846
66.5k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
66.5k
            switch (b->comp_type) {
1848
44.9k
            case COMP_INTER_AVG:
1849
44.9k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
44.9k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
44.9k
                            HIGHBD_CALL_SUFFIX);
1852
44.9k
                break;
1853
8.81k
            case COMP_INTER_WEIGHTED_AVG:
1854
8.81k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
8.81k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
8.81k
                              HIGHBD_CALL_SUFFIX);
1857
8.81k
                break;
1858
4.50k
            case COMP_INTER_WEDGE:
1859
12.8k
            case COMP_INTER_SEG:
1860
12.8k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
12.8k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
12.8k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
12.8k
                             HIGHBD_CALL_SUFFIX);
1864
12.8k
                break;
1865
66.5k
            }
1866
66.5k
        }
1867
41.7k
    }
1868
1869
423k
    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
423k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
423k
    if (b->skip) {
1882
        // reset coef contexts
1883
200k
        BlockContext *const a = t->a;
1884
200k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
200k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
200k
        if (has_chroma) {
1887
149k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
149k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
149k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
149k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
149k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
149k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
149k
        }
1894
200k
        return 0;
1895
200k
    }
1896
1897
223k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
223k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
223k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
452k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
463k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
234k
            int y_off = !!init_y, y;
1905
234k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
480k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
245k
                 y += ytx->h, y_off++)
1908
245k
            {
1909
245k
                int x, x_off = !!init_x;
1910
533k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
287k
                     x += ytx->w, x_off++)
1912
287k
                {
1913
287k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
287k
                                   x_off, y_off, &dst[x * 4]);
1915
287k
                    t->bx += ytx->w;
1916
287k
                }
1917
245k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
245k
                t->bx -= x;
1919
245k
                t->by += ytx->h;
1920
245k
            }
1921
234k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
234k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
551k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
367k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
367k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
367k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
764k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
396k
                {
1931
396k
                    int x;
1932
396k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
871k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
474k
                    {
1935
474k
                        coef *cf;
1936
474k
                        int eob;
1937
474k
                        enum TxfmType txtp;
1938
474k
                        if (t->frame_thread.pass) {
1939
474k
                            const int p = t->frame_thread.pass & 1;
1940
474k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
474k
                            cf = ts->frame_thread[p].cf;
1942
474k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
474k
                            eob  = cbi >> 5;
1944
474k
                            txtp = cbi & 0x1f;
1945
474k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
474k
                        if (eob >= 0) {
1964
133k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
133k
                            dsp->itx.itxfm_add[b->uvtx]
1967
133k
                                              [txtp](&uvdst[4 * x],
1968
133k
                                                     f->cur.stride[1],
1969
133k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
133k
                            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
133k
                        }
1974
474k
                        t->bx += uvtx->w << ss_hor;
1975
474k
                    }
1976
396k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
396k
                    t->bx -= x << ss_hor;
1978
396k
                    t->by += uvtx->h << ss_ver;
1979
396k
                }
1980
367k
                t->by -= y << ss_ver;
1981
367k
            }
1982
234k
        }
1983
228k
    }
1984
223k
    return 0;
1985
423k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
389k
{
1560
389k
    Dav1dTileState *const ts = t->ts;
1561
389k
    const Dav1dFrameContext *const f = t->f;
1562
389k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
389k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
389k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
389k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
389k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
389k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
389k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
389k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
389k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
227k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
216k
                           (bh4 > ss_ver || t->by & 1);
1573
389k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
389k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
389k
    int res;
1576
1577
    // prediction
1578
389k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
389k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
389k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
389k
    const ptrdiff_t uvdstoff =
1582
389k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
389k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
80.0k
        assert(!f->frame_hdr->super_res.enabled);
1586
80.0k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
80.0k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
80.0k
        if (res) return res;
1589
158k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
105k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
105k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
105k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
105k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
105k
            if (res) return res;
1595
105k
        }
1596
309k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
264k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
264k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
264k
        if (imin(bw4, bh4) > 1 &&
1601
162k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
159k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.82k
        {
1604
5.82k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.82k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.82k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.82k
            if (res) return res;
1608
259k
        } else {
1609
259k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
259k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
259k
            if (res) return res;
1612
259k
            if (b->motion_mode == MM_OBMC) {
1613
45.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
45.1k
                if (res) return res;
1615
45.1k
            }
1616
259k
        }
1617
264k
        if (b->interintra_type) {
1618
8.51k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
8.51k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
7.09k
                                   SMOOTH_PRED : b->interintra_mode;
1621
8.51k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
8.51k
            int angle = 0;
1623
8.51k
            const pixel *top_sb_edge = NULL;
1624
8.51k
            if (!(t->by & (f->sb_step - 1))) {
1625
3.69k
                top_sb_edge = f->ipred_edge[0];
1626
3.69k
                const int sby = t->by >> f->sb_shift;
1627
3.69k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
3.69k
            }
1629
8.51k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
8.51k
                                                  t->by, t->by > ts->tiling.row_start,
1631
8.51k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
8.51k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
8.51k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
8.51k
                                                  HIGHBD_CALL_SUFFIX);
1635
8.51k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
8.51k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
8.51k
                                     HIGHBD_CALL_SUFFIX);
1638
8.51k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
8.51k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
8.51k
        }
1641
1642
264k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
123k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
123k
        refmvs_block *const *r;
1647
123k
        if (is_sub8x8) {
1648
13.3k
            assert(ss_hor == 1);
1649
13.3k
            r = &t->rt.r[(t->by & 31) + 5];
1650
13.3k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
13.3k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
13.3k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.02k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
13.3k
        }
1655
1656
        // chroma prediction
1657
123k
        if (is_sub8x8) {
1658
12.7k
            assert(ss_hor == 1);
1659
12.7k
            ptrdiff_t h_off = 0, v_off = 0;
1660
12.7k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.95k
                for (int pl = 0; pl < 2; pl++) {
1662
3.97k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.97k
                             NULL, f->cur.stride[1],
1664
3.97k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.97k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.97k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.97k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.97k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.97k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.97k
                    if (res) return res;
1671
3.97k
                }
1672
1.98k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.98k
                h_off = 2;
1674
1.98k
            }
1675
12.7k
            if (bw4 == 1) {
1676
6.66k
                const enum Filter2d left_filter_2d =
1677
6.66k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
19.9k
                for (int pl = 0; pl < 2; pl++) {
1679
13.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
13.3k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
13.3k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
13.3k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
13.3k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
13.3k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
13.3k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
13.3k
                    if (res) return res;
1687
13.3k
                }
1688
6.66k
                h_off = 2;
1689
6.66k
            }
1690
12.7k
            if (bh4 == ss_ver) {
1691
8.07k
                const enum Filter2d top_filter_2d =
1692
8.07k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
24.2k
                for (int pl = 0; pl < 2; pl++) {
1694
16.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
16.1k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
16.1k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
16.1k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
16.1k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
16.1k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
16.1k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
16.1k
                    if (res) return res;
1702
16.1k
                }
1703
8.07k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
8.07k
            }
1705
38.2k
            for (int pl = 0; pl < 2; pl++) {
1706
25.5k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
25.5k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
25.5k
                         refp, b->ref[0], filter_2d);
1709
25.5k
                if (res) return res;
1710
25.5k
            }
1711
110k
        } else {
1712
110k
            if (imin(cbw4, cbh4) > 1 &&
1713
56.1k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
54.4k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.62k
            {
1716
10.8k
                for (int pl = 0; pl < 2; pl++) {
1717
7.24k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
7.24k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
7.24k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
7.24k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
7.24k
                    if (res) return res;
1722
7.24k
                }
1723
107k
            } else {
1724
320k
                for (int pl = 0; pl < 2; pl++) {
1725
213k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
213k
                             NULL, f->cur.stride[1],
1727
213k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
213k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
213k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
213k
                    if (res) return res;
1731
213k
                    if (b->motion_mode == MM_OBMC) {
1732
43.0k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
43.0k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
43.0k
                        if (res) return res;
1735
43.0k
                    }
1736
213k
                }
1737
107k
            }
1738
110k
            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
6.96k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
20.8k
                for (int pl = 0; pl < 2; pl++) {
1745
13.9k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
13.9k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
13.9k
                    enum IntraPredMode m =
1748
13.9k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
11.7k
                        SMOOTH_PRED : b->interintra_mode;
1750
13.9k
                    int angle = 0;
1751
13.9k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
13.9k
                    const pixel *top_sb_edge = NULL;
1753
13.9k
                    if (!(t->by & (f->sb_step - 1))) {
1754
5.43k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
5.43k
                        const int sby = t->by >> f->sb_shift;
1756
5.43k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
5.43k
                    }
1758
13.9k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
13.9k
                                                          (t->bx >> ss_hor) >
1760
13.9k
                                                              (ts->tiling.col_start >> ss_hor),
1761
13.9k
                                                          t->by >> ss_ver,
1762
13.9k
                                                          (t->by >> ss_ver) >
1763
13.9k
                                                              (ts->tiling.row_start >> ss_ver),
1764
13.9k
                                                          ts->tiling.col_end >> ss_hor,
1765
13.9k
                                                          ts->tiling.row_end >> ss_ver,
1766
13.9k
                                                          0, uvdst, f->cur.stride[1],
1767
13.9k
                                                          top_sb_edge, m,
1768
13.9k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
13.9k
                                                          HIGHBD_CALL_SUFFIX);
1770
13.9k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
13.9k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
13.9k
                                             HIGHBD_CALL_SUFFIX);
1773
13.9k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
13.9k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
13.9k
                }
1776
6.96k
            }
1777
110k
        }
1778
1779
264k
    skip_inter_chroma_pred: {}
1780
264k
        t->tl_4x4_filter = filter_2d;
1781
264k
    } else {
1782
44.1k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
44.1k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
44.1k
        int jnt_weight;
1786
44.1k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
44.1k
        const uint8_t *mask;
1788
1789
132k
        for (int i = 0; i < 2; i++) {
1790
88.3k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
88.3k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
3.78k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
3.78k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
3.78k
                if (res) return res;
1796
84.5k
            } else {
1797
84.5k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
84.5k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
84.5k
                if (res) return res;
1800
84.5k
            }
1801
88.3k
        }
1802
44.1k
        switch (b->comp_type) {
1803
28.7k
        case COMP_INTER_AVG:
1804
28.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
28.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
28.7k
            break;
1807
7.40k
        case COMP_INTER_WEIGHTED_AVG:
1808
7.40k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
7.40k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
7.40k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
7.40k
            break;
1812
5.06k
        case COMP_INTER_SEG:
1813
5.06k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
5.06k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
5.06k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
5.06k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
5.06k
            mask = seg_mask;
1818
5.06k
            break;
1819
2.92k
        case COMP_INTER_WEDGE:
1820
2.92k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.92k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.92k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.92k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.92k
            if (has_chroma)
1825
2.21k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.92k
            break;
1827
44.1k
        }
1828
1829
        // chroma
1830
90.9k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
181k
            for (int i = 0; i < 2; i++) {
1832
121k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
121k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
19.5k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.20k
                {
1836
3.20k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.20k
                                      b_dim, 1 + pl,
1838
3.20k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.20k
                    if (res) return res;
1840
118k
                } else {
1841
118k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
118k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
118k
                    if (res) return res;
1844
118k
                }
1845
121k
            }
1846
60.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
60.6k
            switch (b->comp_type) {
1848
38.5k
            case COMP_INTER_AVG:
1849
38.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
38.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
38.5k
                            HIGHBD_CALL_SUFFIX);
1852
38.5k
                break;
1853
9.31k
            case COMP_INTER_WEIGHTED_AVG:
1854
9.31k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
9.31k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
9.31k
                              HIGHBD_CALL_SUFFIX);
1857
9.31k
                break;
1858
4.43k
            case COMP_INTER_WEDGE:
1859
12.7k
            case COMP_INTER_SEG:
1860
12.7k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
12.7k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
12.7k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
12.7k
                             HIGHBD_CALL_SUFFIX);
1864
12.7k
                break;
1865
60.6k
            }
1866
60.6k
        }
1867
44.1k
    }
1868
1869
388k
    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
388k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
388k
    if (b->skip) {
1882
        // reset coef contexts
1883
191k
        BlockContext *const a = t->a;
1884
191k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
191k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
191k
        if (has_chroma) {
1887
89.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
89.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
89.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
89.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
89.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
89.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
89.2k
        }
1894
191k
        return 0;
1895
191k
    }
1896
1897
196k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
196k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
196k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
399k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
407k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
205k
            int y_off = !!init_y, y;
1905
205k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
427k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
222k
                 y += ytx->h, y_off++)
1908
222k
            {
1909
222k
                int x, x_off = !!init_x;
1910
493k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
271k
                     x += ytx->w, x_off++)
1912
271k
                {
1913
271k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
271k
                                   x_off, y_off, &dst[x * 4]);
1915
271k
                    t->bx += ytx->w;
1916
271k
                }
1917
222k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
222k
                t->bx -= x;
1919
222k
                t->by += ytx->h;
1920
222k
            }
1921
205k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
205k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
370k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
246k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
246k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
246k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
520k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
273k
                {
1931
273k
                    int x;
1932
273k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
630k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
356k
                    {
1935
356k
                        coef *cf;
1936
356k
                        int eob;
1937
356k
                        enum TxfmType txtp;
1938
356k
                        if (t->frame_thread.pass) {
1939
356k
                            const int p = t->frame_thread.pass & 1;
1940
356k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
356k
                            cf = ts->frame_thread[p].cf;
1942
356k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
356k
                            eob  = cbi >> 5;
1944
356k
                            txtp = cbi & 0x1f;
1945
356k
                        } 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
356k
                        if (eob >= 0) {
1964
106k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
106k
                            dsp->itx.itxfm_add[b->uvtx]
1967
106k
                                              [txtp](&uvdst[4 * x],
1968
106k
                                                     f->cur.stride[1],
1969
106k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
106k
                            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
106k
                        }
1974
356k
                        t->bx += uvtx->w << ss_hor;
1975
356k
                    }
1976
273k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
273k
                    t->bx -= x << ss_hor;
1978
273k
                    t->by += uvtx->h << ss_ver;
1979
273k
                }
1980
246k
                t->by -= y << ss_ver;
1981
246k
            }
1982
205k
        }
1983
202k
    }
1984
196k
    return 0;
1985
388k
}
1986
1987
315k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
315k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
315k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
315k
    const int y = sby * f->sb_step * 4;
1994
315k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
315k
    pixel *const p[3] = {
1996
315k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
315k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
315k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
315k
    };
2000
315k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
315k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
315k
                                        f->lf.start_of_tile_row[sby]);
2003
315k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
155k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
155k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
155k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
155k
    const int y = sby * f->sb_step * 4;
1994
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
155k
    pixel *const p[3] = {
1996
155k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
155k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
155k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
155k
    };
2000
155k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
155k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
155k
                                        f->lf.start_of_tile_row[sby]);
2003
155k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
160k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
160k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
160k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
160k
    const int y = sby * f->sb_step * 4;
1994
160k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
160k
    pixel *const p[3] = {
1996
160k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
160k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
160k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
160k
    };
2000
160k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
160k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
160k
                                        f->lf.start_of_tile_row[sby]);
2003
160k
}
2004
2005
372k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
372k
    const int y = sby * f->sb_step * 4;
2007
372k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
372k
    pixel *const p[3] = {
2009
372k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
372k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
372k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
372k
    };
2013
372k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
372k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
372k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
315k
    {
2017
315k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
315k
    }
2019
372k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
294k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
294k
    }
2023
372k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
182k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
182k
    const int y = sby * f->sb_step * 4;
2007
182k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
182k
    pixel *const p[3] = {
2009
182k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
182k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
182k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
182k
    };
2013
182k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
182k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
182k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
155k
    {
2017
155k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
155k
    }
2019
182k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
133k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
133k
    }
2023
182k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
190k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
190k
    const int y = sby * f->sb_step * 4;
2007
190k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
190k
    pixel *const p[3] = {
2009
190k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
190k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
190k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
190k
    };
2013
190k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
190k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
190k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
160k
    {
2017
160k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
160k
    }
2019
190k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
160k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
160k
    }
2023
190k
}
2024
2025
189k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
189k
    const Dav1dFrameContext *const f = tc->f;
2027
189k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
189k
    const int sbsz = f->sb_step;
2029
189k
    const int y = sby * sbsz * 4;
2030
189k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
189k
    pixel *const p[3] = {
2032
189k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
189k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
189k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
189k
    };
2036
189k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
189k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
189k
    const int start = sby * sbsz;
2039
189k
    if (sby) {
2040
91.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
91.3k
        pixel *p_up[3] = {
2042
91.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
91.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
91.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
91.3k
        };
2046
91.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
91.3k
    }
2048
189k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
189k
    const int end = imin(start + n_blks, f->bh);
2050
189k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
189k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
94.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
94.7k
    const Dav1dFrameContext *const f = tc->f;
2027
94.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
94.7k
    const int sbsz = f->sb_step;
2029
94.7k
    const int y = sby * sbsz * 4;
2030
94.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
94.7k
    pixel *const p[3] = {
2032
94.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
94.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
94.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
94.7k
    };
2036
94.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
94.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
94.7k
    const int start = sby * sbsz;
2039
94.7k
    if (sby) {
2040
44.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
44.2k
        pixel *p_up[3] = {
2042
44.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
44.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
44.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
44.2k
        };
2046
44.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
44.2k
    }
2048
94.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
94.7k
    const int end = imin(start + n_blks, f->bh);
2050
94.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
94.7k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
94.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
94.9k
    const Dav1dFrameContext *const f = tc->f;
2027
94.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
94.9k
    const int sbsz = f->sb_step;
2029
94.9k
    const int y = sby * sbsz * 4;
2030
94.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
94.9k
    pixel *const p[3] = {
2032
94.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
94.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
94.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
94.9k
    };
2036
94.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
94.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
94.9k
    const int start = sby * sbsz;
2039
94.9k
    if (sby) {
2040
47.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
47.0k
        pixel *p_up[3] = {
2042
47.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
47.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
47.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
47.0k
        };
2046
47.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
47.0k
    }
2048
94.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
94.9k
    const int end = imin(start + n_blks, f->bh);
2050
94.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
94.9k
}
2052
2053
79.4k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
79.4k
    const int sbsz = f->sb_step;
2055
79.4k
    const int y = sby * sbsz * 4;
2056
79.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
79.4k
    const pixel *const p[3] = {
2058
79.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
79.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
79.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
79.4k
    };
2062
79.4k
    pixel *const sr_p[3] = {
2063
79.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
79.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
79.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
79.4k
    };
2067
79.4k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
290k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
211k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
211k
        const int h_start = 8 * !!sby >> ss_ver;
2071
211k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
211k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
211k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
211k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
211k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
211k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
211k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
211k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
211k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
211k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
211k
                          imin(img_h, h_end) + h_start, src_w,
2083
211k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
211k
                          HIGHBD_CALL_SUFFIX);
2085
211k
    }
2086
79.4k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
35.1k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
35.1k
    const int sbsz = f->sb_step;
2055
35.1k
    const int y = sby * sbsz * 4;
2056
35.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
35.1k
    const pixel *const p[3] = {
2058
35.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
35.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
35.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
35.1k
    };
2062
35.1k
    pixel *const sr_p[3] = {
2063
35.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
35.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
35.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
35.1k
    };
2067
35.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
127k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
92.6k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
92.6k
        const int h_start = 8 * !!sby >> ss_ver;
2071
92.6k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
92.6k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
92.6k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
92.6k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
92.6k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
92.6k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
92.6k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
92.6k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
92.6k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
92.6k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
92.6k
                          imin(img_h, h_end) + h_start, src_w,
2083
92.6k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
92.6k
                          HIGHBD_CALL_SUFFIX);
2085
92.6k
    }
2086
35.1k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
44.3k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
44.3k
    const int sbsz = f->sb_step;
2055
44.3k
    const int y = sby * sbsz * 4;
2056
44.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
44.3k
    const pixel *const p[3] = {
2058
44.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
44.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
44.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
44.3k
    };
2062
44.3k
    pixel *const sr_p[3] = {
2063
44.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
44.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
44.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
44.3k
    };
2067
44.3k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
162k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
118k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
118k
        const int h_start = 8 * !!sby >> ss_ver;
2071
118k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
118k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
118k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
118k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
118k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
118k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
118k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
118k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
118k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
118k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
118k
                          imin(img_h, h_end) + h_start, src_w,
2083
118k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
118k
                          HIGHBD_CALL_SUFFIX);
2085
118k
    }
2086
44.3k
}
2087
2088
195k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
195k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
195k
    const int y = sby * f->sb_step * 4;
2091
195k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
195k
    pixel *const sr_p[3] = {
2093
195k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
195k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
195k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
195k
    };
2097
195k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
195k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
88.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
88.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
88.4k
    const int y = sby * f->sb_step * 4;
2091
88.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
88.4k
    pixel *const sr_p[3] = {
2093
88.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
88.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
88.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
88.4k
    };
2097
88.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
88.4k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
107k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
107k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
107k
    const int y = sby * f->sb_step * 4;
2091
107k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
107k
    pixel *const sr_p[3] = {
2093
107k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
107k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
107k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
107k
    };
2097
107k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
107k
}
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
426k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
426k
    const Dav1dFrameContext *const f = t->f;
2113
426k
    Dav1dTileState *const ts = t->ts;
2114
426k
    const int sby = t->by >> f->sb_shift;
2115
426k
    const int sby_off = f->sb128w * 128 * sby;
2116
426k
    const int x_off = ts->tiling.col_start;
2117
2118
426k
    const pixel *const y =
2119
426k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
426k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
426k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
426k
               4 * (ts->tiling.col_end - x_off));
2123
2124
426k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
316k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
316k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
316k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
316k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
949k
        for (int pl = 1; pl <= 2; pl++)
2131
632k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
340k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
340k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
316k
    }
2135
426k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
210k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
210k
    const Dav1dFrameContext *const f = t->f;
2113
210k
    Dav1dTileState *const ts = t->ts;
2114
210k
    const int sby = t->by >> f->sb_shift;
2115
210k
    const int sby_off = f->sb128w * 128 * sby;
2116
210k
    const int x_off = ts->tiling.col_start;
2117
2118
210k
    const pixel *const y =
2119
210k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
210k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
210k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
210k
               4 * (ts->tiling.col_end - x_off));
2123
2124
210k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
170k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
170k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
170k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
170k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
510k
        for (int pl = 1; pl <= 2; pl++)
2131
340k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
340k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
340k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
170k
    }
2135
210k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
215k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
215k
    const Dav1dFrameContext *const f = t->f;
2113
215k
    Dav1dTileState *const ts = t->ts;
2114
215k
    const int sby = t->by >> f->sb_shift;
2115
215k
    const int sby_off = f->sb128w * 128 * sby;
2116
215k
    const int x_off = ts->tiling.col_start;
2117
2118
215k
    const pixel *const y =
2119
215k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
215k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
215k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
215k
               4 * (ts->tiling.col_end - x_off));
2123
2124
215k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
146k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
146k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
146k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
146k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
439k
        for (int pl = 1; pl <= 2; pl++)
2131
292k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
146k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
146k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
146k
    }
2135
215k
}
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
51.8k
{
2142
51.8k
    const Dav1dFrameContext *const f = t->f;
2143
51.8k
    pixel *const pal = t->frame_thread.pass ?
2144
51.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
51.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
51.8k
        bytefn(t->scratch.pal)[0];
2147
247k
    for (int x = 0; x < bw4; x++)
2148
195k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
216k
    for (int y = 0; y < bh4; y++)
2150
164k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
51.8k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
23.8k
{
2142
23.8k
    const Dav1dFrameContext *const f = t->f;
2143
23.8k
    pixel *const pal = t->frame_thread.pass ?
2144
23.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
23.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
23.8k
        bytefn(t->scratch.pal)[0];
2147
112k
    for (int x = 0; x < bw4; x++)
2148
88.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
99.2k
    for (int y = 0; y < bh4; y++)
2150
75.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
23.8k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
27.9k
{
2142
27.9k
    const Dav1dFrameContext *const f = t->f;
2143
27.9k
    pixel *const pal = t->frame_thread.pass ?
2144
27.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
27.9k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
27.9k
        bytefn(t->scratch.pal)[0];
2147
134k
    for (int x = 0; x < bw4; x++)
2148
106k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
117k
    for (int y = 0; y < bh4; y++)
2150
89.5k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
27.9k
}
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.4k
{
2158
18.4k
    const Dav1dFrameContext *const f = t->f;
2159
18.4k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
18.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
18.4k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
18.4k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
55.3k
    for (int pl = 1; pl <= 2; pl++) {
2165
216k
        for (int x = 0; x < bw4; x++)
2166
179k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
182k
        for (int y = 0; y < bh4; y++)
2168
146k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
36.8k
    }
2170
18.4k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
8.65k
{
2158
8.65k
    const Dav1dFrameContext *const f = t->f;
2159
8.65k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.65k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.65k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.65k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
25.9k
    for (int pl = 1; pl <= 2; pl++) {
2165
100k
        for (int x = 0; x < bw4; x++)
2166
82.7k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
88.9k
        for (int y = 0; y < bh4; y++)
2168
71.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
17.3k
    }
2170
8.65k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
9.79k
{
2158
9.79k
    const Dav1dFrameContext *const f = t->f;
2159
9.79k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
9.79k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
9.79k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
9.79k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
29.3k
    for (int pl = 1; pl <= 2; pl++) {
2165
115k
        for (int x = 0; x < bw4; x++)
2166
96.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
94.0k
        for (int y = 0; y < bh4; y++)
2168
74.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
19.5k
    }
2170
9.79k
}
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
70.3k
{
2176
70.3k
    Dav1dTileState *const ts = t->ts;
2177
70.3k
    const Dav1dFrameContext *const f = t->f;
2178
70.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
70.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
70.3k
    pixel cache[16], used_cache[8];
2181
70.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
70.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
70.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
70.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
70.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
118k
    while (l_cache && a_cache) {
2190
48.4k
        if (*l < *a) {
2191
17.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
17.4k
                cache[n_cache++] = *l;
2193
17.6k
            l++;
2194
17.6k
            l_cache--;
2195
30.7k
        } else {
2196
30.7k
            if (*a == *l) {
2197
12.3k
                l++;
2198
12.3k
                l_cache--;
2199
12.3k
            }
2200
30.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
29.5k
                cache[n_cache++] = *a;
2202
30.7k
            a++;
2203
30.7k
            a_cache--;
2204
30.7k
        }
2205
48.4k
    }
2206
70.3k
    if (l_cache) {
2207
83.5k
        do {
2208
83.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
67.5k
                cache[n_cache++] = *l;
2210
83.5k
            l++;
2211
83.5k
        } while (--l_cache > 0);
2212
50.3k
    } else if (a_cache) {
2213
59.1k
        do {
2214
59.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
46.8k
                cache[n_cache++] = *a;
2216
59.1k
            a++;
2217
59.1k
        } while (--a_cache > 0);
2218
14.6k
    }
2219
2220
    // find reused cache entries
2221
70.3k
    int i = 0;
2222
214k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
143k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
71.2k
            used_cache[i++] = cache[n];
2225
70.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
70.3k
    pixel *const pal = t->frame_thread.pass ?
2229
70.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
70.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
70.3k
        bytefn(t->scratch.pal)[pl];
2232
70.3k
    if (i < pal_sz) {
2233
61.3k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
61.3k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
61.3k
        if (i < pal_sz) {
2237
55.6k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
55.6k
            const int max = (1 << bpc) - 1;
2239
2240
129k
            do {
2241
129k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
129k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
129k
                if (prev + !pl >= max) {
2244
74.3k
                    for (; i < pal_sz; i++)
2245
48.4k
                        pal[i] = max;
2246
25.8k
                    break;
2247
25.8k
                }
2248
103k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
103k
            } while (i < pal_sz);
2250
55.6k
        }
2251
2252
        // merge cache+new entries
2253
61.3k
        int n = 0, m = n_used_cache;
2254
347k
        for (i = 0; i < pal_sz; i++) {
2255
286k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
46.7k
                pal[i] = used_cache[n++];
2257
239k
            } else {
2258
239k
                assert(m < pal_sz);
2259
239k
                pal[i] = pal[m++];
2260
239k
            }
2261
286k
        }
2262
61.3k
    } else {
2263
8.99k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
8.99k
    }
2265
2266
70.3k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
70.3k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
32.5k
{
2176
32.5k
    Dav1dTileState *const ts = t->ts;
2177
32.5k
    const Dav1dFrameContext *const f = t->f;
2178
32.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
32.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
32.5k
    pixel cache[16], used_cache[8];
2181
32.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
32.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
32.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
32.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
32.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
56.1k
    while (l_cache && a_cache) {
2190
23.5k
        if (*l < *a) {
2191
8.70k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
8.57k
                cache[n_cache++] = *l;
2193
8.70k
            l++;
2194
8.70k
            l_cache--;
2195
14.8k
        } else {
2196
14.8k
            if (*a == *l) {
2197
6.03k
                l++;
2198
6.03k
                l_cache--;
2199
6.03k
            }
2200
14.8k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
14.3k
                cache[n_cache++] = *a;
2202
14.8k
            a++;
2203
14.8k
            a_cache--;
2204
14.8k
        }
2205
23.5k
    }
2206
32.5k
    if (l_cache) {
2207
38.9k
        do {
2208
38.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
31.0k
                cache[n_cache++] = *l;
2210
38.9k
            l++;
2211
38.9k
        } while (--l_cache > 0);
2212
23.2k
    } else if (a_cache) {
2213
27.1k
        do {
2214
27.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
21.4k
                cache[n_cache++] = *a;
2216
27.1k
            a++;
2217
27.1k
        } while (--a_cache > 0);
2218
6.77k
    }
2219
2220
    // find reused cache entries
2221
32.5k
    int i = 0;
2222
99.6k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
67.0k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
33.2k
            used_cache[i++] = cache[n];
2225
32.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
32.5k
    pixel *const pal = t->frame_thread.pass ?
2229
32.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
32.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
32.5k
        bytefn(t->scratch.pal)[pl];
2232
32.5k
    if (i < pal_sz) {
2233
28.4k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
28.4k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
28.4k
        if (i < pal_sz) {
2237
25.6k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
25.6k
            const int max = (1 << bpc) - 1;
2239
2240
59.7k
            do {
2241
59.7k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
59.7k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
59.7k
                if (prev + !pl >= max) {
2244
35.2k
                    for (; i < pal_sz; i++)
2245
23.0k
                        pal[i] = max;
2246
12.1k
                    break;
2247
12.1k
                }
2248
47.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
47.5k
            } while (i < pal_sz);
2250
25.6k
        }
2251
2252
        // merge cache+new entries
2253
28.4k
        int n = 0, m = n_used_cache;
2254
161k
        for (i = 0; i < pal_sz; i++) {
2255
133k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
22.0k
                pal[i] = used_cache[n++];
2257
111k
            } else {
2258
111k
                assert(m < pal_sz);
2259
111k
                pal[i] = pal[m++];
2260
111k
            }
2261
133k
        }
2262
28.4k
    } else {
2263
4.10k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
4.10k
    }
2265
2266
32.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
32.5k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
37.7k
{
2176
37.7k
    Dav1dTileState *const ts = t->ts;
2177
37.7k
    const Dav1dFrameContext *const f = t->f;
2178
37.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
37.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
37.7k
    pixel cache[16], used_cache[8];
2181
37.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
37.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
37.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
37.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
37.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
62.6k
    while (l_cache && a_cache) {
2190
24.8k
        if (*l < *a) {
2191
8.96k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
8.91k
                cache[n_cache++] = *l;
2193
8.96k
            l++;
2194
8.96k
            l_cache--;
2195
15.9k
        } else {
2196
15.9k
            if (*a == *l) {
2197
6.31k
                l++;
2198
6.31k
                l_cache--;
2199
6.31k
            }
2200
15.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
15.1k
                cache[n_cache++] = *a;
2202
15.9k
            a++;
2203
15.9k
            a_cache--;
2204
15.9k
        }
2205
24.8k
    }
2206
37.7k
    if (l_cache) {
2207
44.5k
        do {
2208
44.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
36.5k
                cache[n_cache++] = *l;
2210
44.5k
            l++;
2211
44.5k
        } while (--l_cache > 0);
2212
27.0k
    } else if (a_cache) {
2213
31.9k
        do {
2214
31.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
25.4k
                cache[n_cache++] = *a;
2216
31.9k
            a++;
2217
31.9k
        } while (--a_cache > 0);
2218
7.88k
    }
2219
2220
    // find reused cache entries
2221
37.7k
    int i = 0;
2222
114k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
76.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
37.9k
            used_cache[i++] = cache[n];
2225
37.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
37.7k
    pixel *const pal = t->frame_thread.pass ?
2229
37.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
37.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
37.7k
        bytefn(t->scratch.pal)[pl];
2232
37.7k
    if (i < pal_sz) {
2233
32.8k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
32.8k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
32.8k
        if (i < pal_sz) {
2237
29.9k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
29.9k
            const int max = (1 << bpc) - 1;
2239
2240
69.8k
            do {
2241
69.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
69.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
69.8k
                if (prev + !pl >= max) {
2244
39.1k
                    for (; i < pal_sz; i++)
2245
25.4k
                        pal[i] = max;
2246
13.7k
                    break;
2247
13.7k
                }
2248
56.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
56.0k
            } while (i < pal_sz);
2250
29.9k
        }
2251
2252
        // merge cache+new entries
2253
32.8k
        int n = 0, m = n_used_cache;
2254
185k
        for (i = 0; i < pal_sz; i++) {
2255
152k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
24.7k
                pal[i] = used_cache[n++];
2257
128k
            } else {
2258
128k
                assert(m < pal_sz);
2259
128k
                pal[i] = pal[m++];
2260
128k
            }
2261
152k
        }
2262
32.8k
    } else {
2263
4.89k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
4.89k
    }
2265
2266
37.7k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
37.7k
}
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.4k
{
2281
18.4k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
18.4k
    Dav1dTileState *const ts = t->ts;
2285
18.4k
    const Dav1dFrameContext *const f = t->f;
2286
18.4k
    pixel *const pal = t->frame_thread.pass ?
2287
18.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
18.4k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
18.4k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
18.4k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
9.59k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
9.59k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
9.59k
        const int max = (1 << bpc) - 1;
2295
40.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
30.7k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
30.7k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
30.7k
            prev = pal[i] = (prev + delta) & max;
2299
30.7k
        }
2300
9.59k
    } else {
2301
46.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
37.2k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
8.85k
    }
2304
18.4k
    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.4k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
8.65k
{
2281
8.65k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.65k
    Dav1dTileState *const ts = t->ts;
2285
8.65k
    const Dav1dFrameContext *const f = t->f;
2286
8.65k
    pixel *const pal = t->frame_thread.pass ?
2287
8.65k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.65k
                            ((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
8.65k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.47k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.47k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.47k
        const int max = (1 << bpc) - 1;
2295
19.2k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
14.7k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
14.7k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
14.7k
            prev = pal[i] = (prev + delta) & max;
2299
14.7k
        }
2300
4.47k
    } else {
2301
21.7k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
17.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.18k
    }
2304
8.65k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
8.65k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
9.79k
{
2281
9.79k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
9.79k
    Dav1dTileState *const ts = t->ts;
2285
9.79k
    const Dav1dFrameContext *const f = t->f;
2286
9.79k
    pixel *const pal = t->frame_thread.pass ?
2287
9.79k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
9.79k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
9.79k
        bytefn(t->scratch.pal)[2];
2290
9.79k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
9.79k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
5.12k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
5.12k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
5.12k
        const int max = (1 << bpc) - 1;
2295
21.0k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
15.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
15.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
15.9k
            prev = pal[i] = (prev + delta) & max;
2299
15.9k
        }
2300
5.12k
    } else {
2301
24.3k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
19.6k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.66k
    }
2304
9.79k
    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
9.79k
}