Coverage Report

Created: 2026-09-02 06:43

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