FFmpeg
Loading...
Searching...
No Matches
perf_internal.h
Go to the documentation of this file.
1/*
2 * Copyright © 2018-2022, VideoLAN and dav1d authors
3 * Copyright © 2018-2022, 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 CHECKASM_PERF_INTERNAL_H
29#define CHECKASM_PERF_INTERNAL_H
30
31#include "checkasm_config.h"
32
33#if ARCH_AARCH64
34
35 #include <stdint.h>
36
37 #if !defined(__APPLE__) && (!defined(_MSC_VER) || defined(__clang__))
38
39static inline void checkasm_pmccntr_enable(void)
40{
41 uint64_t cfg, cen, flt;
42
43 __asm__ __volatile__("mrs %[cfg], pmcr_el0 \n\t"
44 "mrs %[cen], pmcntenset_el0 \n\t"
45 "mrs %[flt], pmccfiltr_el0 \n\t"
46 "orr %[cfg], %[cfg], 1 \n\t"
47 "orr %[cen], %[cen], 1<<31 \n\t"
48 "bic %[flt], %[flt], (1<<30)\n\t"
49 "bic %[flt], %[flt], (1<<28)\n\t"
50 "msr pmcntenset_el0, %[cen] \n\t"
51 "msr pmcr_el0, %[cfg] \n\t"
52 "msr pmccfiltr_el0, %[flt] \n\t"
53 : [cfg] "=&r"(cfg), [cen] "=&r"(cen), [flt] "=&r"(flt));
54}
55
56 #define CHECKASM_PERF_ASM_INIT checkasm_pmccntr_enable
57
58 #endif
59
60#elif ARCH_ARM
61
62 #if !defined(_MSC_VER) && (!defined(__thumb__) || defined(__thumb2__))
63
64static inline void checkasm_counter_enable(void)
65{
66 // PMCR.E (bit 0) = 1
67 __asm__ __volatile__("mcr p15, 0, %0, c9, c12, 0" ::"r"(1));
68 // PMCNTENSET.C (bit 31) = 1
69 __asm__ __volatile__("mcr p15, 0, %0, c9, c12, 1" ::"r"(1 << 31));
70}
71
72 #define CHECKASM_PERF_ASM_INIT checkasm_counter_enable
73
74 #endif
75
76#endif
77
78/* This define isn't set by Meson, but can be deduced straight from the
79 * other defines. */
80#if defined(__APPLE__) && ARCH_AARCH64
81 /* This only depends on <dlfcn.h>, and isn't needed on other architectures. */
82 #define HAVE_MACOS_KPERF 1
83#else
84 #define HAVE_MACOS_KPERF 0
85#endif
86
87#endif /* CHECKASM_PERF_INTERNAL_H */
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
static CheckasmConfig cfg
Definition checkasm.c:74