Coverage Report

Created: 2026-09-13 06:34

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