FFmpeg
aarch64.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2025, Niklas Haas
3  * Copyright © 2018, VideoLAN and dav1d authors
4  * Copyright © 2018, Two Orioles, LLC
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef CHECKASM_PERF_AARCH64_H
30 #define CHECKASM_PERF_AARCH64_H
31 
32 #include <stdint.h>
33 
34 #if defined(__APPLE__)
35 
36  /* Don't attempt to read pmccntr directly; this is never accessible
37  * on Darwin in any known configurations. */
38  #undef CHECKASM_PERF_ASM
39  #undef CHECKASM_PERF_ASM_NAME
40  #undef CHECKASM_PERF_ASM_UNIT
41 
42 #elif defined(_MSC_VER) && !defined(__clang__)
43  #include <windows.h>
44 
45  #define CHECKASM_PERF_ASM() \
46  (_InstructionSynchronizationBarrier(), ReadTimeStampCounter())
47  #define CHECKASM_PERF_ASM_NAME "aarch64 (pmccntr)"
48  #define CHECKASM_PERF_ASM_UNIT "cycle"
49  #define CHECKASM_PERF_ASM_USABLE 1
50 
51 #else /* !MSVC */
52 
53 static inline uint64_t checkasm_pmccntr(void)
54 {
55  uint64_t cycle_counter;
56  /* This requires enabling user mode access to the cycle counter
57  * (which can only be done from kernel space). */
58  __asm__ __volatile__("isb\nmrs %0, pmccntr_el0" : "=r"(cycle_counter)::"memory");
59  return cycle_counter;
60 }
61  #define CHECKASM_PERF_ASM() checkasm_pmccntr()
62  #define CHECKASM_PERF_ASM_NAME "aarch64 (pmccntr)"
63  #define CHECKASM_PERF_ASM_UNIT "cycle"
64 
65 #endif /* MSVC */
66 
67 #endif /* CHECKASM_PERF_AARCH64_H */
__asm__
__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")
checkasm_pmccntr
static uint64_t checkasm_pmccntr(void)
Definition: aarch64.h:53