Coverage Report

Created: 2026-05-16 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/ctx.h
Line
Count
Source
1
/*
2
 * Copyright © 2018, 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
#ifndef DAV1D_SRC_CTX_H
29
#define DAV1D_SRC_CTX_H
30
31
#include <stdint.h>
32
33
#include "common/attributes.h"
34
#include "common/intops.h"
35
36
union alias64 { uint64_t u64; uint8_t u8[8]; } ATTR_ALIAS;
37
union alias32 { uint32_t u32; uint8_t u8[4]; } ATTR_ALIAS;
38
union alias16 { uint16_t u16; uint8_t u8[2]; } ATTR_ALIAS;
39
union alias8 { uint8_t u8; } ATTR_ALIAS;
40
41
typedef void (*dav1d_memset_pow2_fn)(void *ptr, int value);
42
EXTERN const dav1d_memset_pow2_fn dav1d_memset_pow2[6];
43
44
0
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
0
    assert(n >= 1 && n <= 32);
46
0
    if ((n&(n-1)) == 0) {
47
0
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
0
    } else {
49
0
        memset(ptr, value, n);
50
0
    }
51
0
}
Unexecuted instantiation: decode.c:dav1d_memset_likely_pow2
Unexecuted instantiation: lf_mask.c:dav1d_memset_likely_pow2
Unexecuted instantiation: recon_tmpl.c:dav1d_memset_likely_pow2
Unexecuted instantiation: ctx.c:dav1d_memset_likely_pow2
52
53
// For smaller sizes use multiplication to broadcast bytes. memset misbehaves on the smaller sizes.
54
// For the larger sizes, we want to use memset to get access to vector operations.
55
#define set_ctx1(var, off, val) \
56
0
    ((union alias8 *) &(var)[off])->u8 = (val) * 0x01
57
#define set_ctx2(var, off, val) \
58
0
    ((union alias16 *) &(var)[off])->u16 = (val) * 0x0101
59
#define set_ctx4(var, off, val) \
60
0
    ((union alias32 *) &(var)[off])->u32 = (val) * 0x01010101U
61
#define set_ctx8(var, off, val) \
62
0
    ((union alias64 *) &(var)[off])->u64 = (val) * 0x0101010101010101ULL
63
0
#define set_ctx16(var, off, val) do { \
64
0
        memset(&(var)[off], val, 16); \
65
0
    } while (0)
66
0
#define set_ctx32(var, off, val) do { \
67
0
        memset(&(var)[off], val, 32); \
68
0
    } while (0)
69
#define case_set(var) \
70
0
    switch (var) { \
71
0
    case 0: set_ctx(set_ctx1); break; \
72
0
    case 1: set_ctx(set_ctx2); break; \
73
0
    case 2: set_ctx(set_ctx4); break; \
74
0
    case 3: set_ctx(set_ctx8); break; \
75
0
    case 4: set_ctx(set_ctx16); break; \
76
0
    case 5: set_ctx(set_ctx32); break; \
77
0
    default: assert(0); \
78
0
    }
79
#define case_set_upto16(var) \
80
0
    switch (var) { \
81
0
    case 0: set_ctx(set_ctx1); break; \
82
0
    case 1: set_ctx(set_ctx2); break; \
83
0
    case 2: set_ctx(set_ctx4); break; \
84
0
    case 3: set_ctx(set_ctx8); break; \
85
0
    case 4: set_ctx(set_ctx16); break; \
86
0
    default: assert(0); \
87
0
    }
88
89
#endif /* DAV1D_SRC_CTX_H */