FFmpeg
Loading...
Searching...
No Matches
arm.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_ARM_H
30#define CHECKASM_PERF_ARM_H
31
32#if !defined(_MSC_VER) && (!defined(__thumb__) || defined(__thumb2__))
33
34 #include <stdint.h>
35
36static inline uint64_t checkasm_counter(void)
37{
38 uint32_t cycle_counter;
39 /* This requires enabling user mode access to the cycle counter (which
40 * can only be done from kernel space).
41 *
42 * On architectures before ARMv7, this timer isn't accessible, but we
43 * can still assemble the "mrc" instruction for reading it (provided
44 * that we're building either in ARM or Thumb2 mode; this instruction
45 * isn't available in Thumb1) and try accessing it with a signal
46 * handler.
47 */
48 #if defined(__ARM_ARCH) && __ARM_ARCH >= 7
49 /* This barrier can't be assembled unless we're targeting armv7; providing
50 * .inst equivalents below. */
51 __asm__ __volatile__("isb" ::: "memory");
52 #elif defined(__thumb2__)
53 /* Thumb2 representation of "isb" */
54 __asm__ __volatile__(".inst.w 0xf3bf8f6f" ::: "memory");
55 #else
56 /* ARM representation of "isb" */
57 __asm__ __volatile__(".inst 0xf57ff06f" ::: "memory");
58 #endif
59 __asm__ __volatile__("mrc p15, 0, %0, c9, c13, 0" : "=r"(cycle_counter)::"memory");
60 return cycle_counter;
61}
62
63 #define CHECKASM_PERF_ASM() checkasm_counter()
64 #define CHECKASM_PERF_ASM_NAME "armv7 (ccnt)"
65 #define CHECKASM_PERF_ASM_UNIT "cycle"
66
67#else
68
69 #undef CHECKASM_PERF_ASM
70 #undef CHECKASM_PERF_ASM_NAME
71 #undef CHECKASM_PERF_ASM_UNIT
72
73#endif /* !defined(_MSC_VER) && (!defined(__thumb__) || defined(__thumb2__)) */
74#endif /* CHECKASM_PERF_ARM_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 uint64_t checkasm_counter(void)
Definition arm.h:36