tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_CPU.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11#pragma once
12
13#ifdef _WIN32
14 #include <intrin.h>
15#elif defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
16 // Use clang built-in
17#else
18 #include <x86intrin.h>
19#endif
20
21#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
22 // Use asm yield
23#elif __has_include(<emmintrin.h>)
24 #include <emmintrin.h>
25#endif
26
27namespace tracktion { inline namespace core
28{
29
32{
33 #if defined (__arm__) || defined (__aarch64__) || (defined (__arm64__) && defined (__APPLE__))
34 std::uint64_t result;
35 __asm __volatile("mrs %0, CNTVCT_EL0" : "=&r" (result));
36 return result;
37 #elif defined __has_builtin
38 #if __has_builtin(__builtin_readcyclecounter)
39 return __builtin_readcyclecounter();
40 #else
41 return __rdtsc();
42 #endif
43 #else
44 return __rdtsc();
45 #endif
46}
47
51inline void pause()
52{
53 #if defined (__arm__) || defined (__arm64__) || defined (__aarch64__)
54 __asm__ __volatile__ ("yield");
55 #elif __has_include(<emmintrin.h>)
56 _mm_pause();
57 #else
58 static_assert (false, "Unknown platform");
59 #endif
60}
61
62}} // namespace tracktion { inline namespace core
std::uint64_t rdtsc()
Returns the CPU cycle count, useful for benchmarking.
pause