Coverage Report

Created: 2025-08-28 07:16

/src/libavif/ext/dav1d/src/ctx.h
Line
Count
Source (jump to first uncovered line)
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
46.7M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
46.7M
    assert(n >= 1 && n <= 32);
46
46.7M
    if ((n&(n-1)) == 0) {
47
46.1M
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
46.1M
    } else {
49
611k
        memset(ptr, value, n);
50
611k
    }
51
46.7M
}
Unexecuted instantiation: decode.c:dav1d_memset_likely_pow2
lf_mask.c:dav1d_memset_likely_pow2
Line
Count
Source
44
11.9M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
11.9M
    assert(n >= 1 && n <= 32);
46
11.9M
    if ((n&(n-1)) == 0) {
47
11.5M
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
11.5M
    } else {
49
357k
        memset(ptr, value, n);
50
357k
    }
51
11.9M
}
recon_tmpl.c:dav1d_memset_likely_pow2
Line
Count
Source
44
34.8M
static inline void dav1d_memset_likely_pow2(void *const ptr, const int value, const int n) {
45
34.8M
    assert(n >= 1 && n <= 32);
46
34.8M
    if ((n&(n-1)) == 0) {
47
34.5M
        dav1d_memset_pow2[ulog2(n)](ptr, value);
48
34.5M
    } else {
49
254k
        memset(ptr, value, n);
50
254k
    }
51
34.8M
}
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
113M
    ((union alias8 *) &(var)[off])->u8 = (val) * 0x01
57
#define set_ctx2(var, off, val) \
58
111M
    ((union alias16 *) &(var)[off])->u16 = (val) * 0x0101
59
#define set_ctx4(var, off, val) \
60
30.6M
    ((union alias32 *) &(var)[off])->u32 = (val) * 0x01010101U
61
#define set_ctx8(var, off, val) \
62
18.0M
    ((union alias64 *) &(var)[off])->u64 = (val) * 0x0101010101010101ULL
63
8.74M
#define set_ctx16(var, off, val) do { \
64
8.74M
        memset(&(var)[off], val, 16); \
65
8.74M
    } while (0)
66
2.61M
#define set_ctx32(var, off, val) do { \
67
2.61M
        memset(&(var)[off], val, 32); \
68
2.61M
    } while (0)
69
#define case_set(var) \
70
20.3M
    switch (var) { \
71
58.7M
    case 0: set_ctx(set_ctx1); break; \
72
84.0M
    case 1: set_ctx(set_ctx2); break; \
73
20.5M
    case 2: set_ctx(set_ctx4); break; \
74
10.9M
    case 3: set_ctx(set_ctx8); break; \
75
5.71M
    case 4: set_ctx(set_ctx16); break; \
76
2.46M
    case 5: set_ctx(set_ctx32); break; \
77
0
    default: assert(0); \
78
20.3M
    }
79
#define case_set_upto16(var) \
80
7.99M
    switch (var) { \
81
10.1M
    case 0: set_ctx(set_ctx1); break; \
82
4.13M
    case 1: set_ctx(set_ctx2); break; \
83
2.25M
    case 2: set_ctx(set_ctx4); break; \
84
1.18M
    case 3: set_ctx(set_ctx8); break; \
85
1.51M
    case 4: set_ctx(set_ctx16); break; \
86
0
    default: assert(0); \
87
7.99M
    }
88
89
#endif /* DAV1D_SRC_CTX_H */