Coverage Report

Created: 2026-05-30 06:06

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
4.24M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
4.24M
    assert(n >= 1 && n <= 32);
46
4.24M
    if ((n&(n-1)) == 0) {
47
4.16M
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
4.16M
    } else {
49
83.2k
        memset(ptr, value, n);
50
83.2k
    }
51
4.24M
}
Unexecuted instantiation: decode.c:dav1d_memset_likely_pow2
lf_mask.c:dav1d_memset_likely_pow2
Line
Count
Source
44
1.00M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
1.00M
    assert(n >= 1 && n <= 32);
46
1.00M
    if ((n&(n-1)) == 0) {
47
952k
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
952k
    } else {
49
51.7k
        memset(ptr, value, n);
50
51.7k
    }
51
1.00M
}
recon_tmpl.c:dav1d_memset_likely_pow2
Line
Count
Source
44
3.24M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
3.24M
    assert(n >= 1 && n <= 32);
46
3.24M
    if ((n&(n-1)) == 0) {
47
3.21M
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
3.21M
    } else {
49
31.4k
        memset(ptr, value, n);
50
31.4k
    }
51
3.24M
}
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
14.0M
    ((union alias8 *) &(var)[off])->u8 = (val) * 0x01
57
#define set_ctx2(var, off, val) \
58
5.99M
    ((union alias16 *) &(var)[off])->u16 = (val) * 0x0101
59
#define set_ctx4(var, off, val) \
60
4.29M
    ((union alias32 *) &(var)[off])->u32 = (val) * 0x01010101U
61
#define set_ctx8(var, off, val) \
62
2.89M
    ((union alias64 *) &(var)[off])->u64 = (val) * 0x0101010101010101ULL
63
1.69M
#define set_ctx16(var, off, val) do { \
64
1.69M
        memset(&(var)[off], val, 16); \
65
1.69M
    } while (0)
66
350k
#define set_ctx32(var, off, val) do { \
67
350k
        memset(&(var)[off], val, 32); \
68
350k
    } while (0)
69
#define case_set(var) \
70
2.74M
    switch (var) { \
71
8.30M
    case 0: set_ctx(set_ctx1); break; \
72
3.80M
    case 1: set_ctx(set_ctx2); break; \
73
2.86M
    case 2: set_ctx(set_ctx4); break; \
74
1.99M
    case 3: set_ctx(set_ctx8); break; \
75
1.28M
    case 4: set_ctx(set_ctx16); break; \
76
292k
    case 5: set_ctx(set_ctx32); break; \
77
0
    default: assert(0); \
78
2.74M
    }
79
#define case_set_upto16(var) \
80
768k
    switch (var) { \
81
645k
    case 0: set_ctx(set_ctx1); break; \
82
431k
    case 1: set_ctx(set_ctx2); break; \
83
338k
    case 2: set_ctx(set_ctx4); break; \
84
216k
    case 3: set_ctx(set_ctx8); break; \
85
153k
    case 4: set_ctx(set_ctx16); break; \
86
0
    default: assert(0); \
87
768k
    }
88
89
#endif /* DAV1D_SRC_CTX_H */