-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpu_relax.h
39 lines (37 loc) · 1.24 KB
/
cpu_relax.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* ai-utils -- C++ Core utilities
*
* @file
* @brief Declaration of cpu_relax().
*
* @Copyright (C) 2018 Carlo Wood.
*
* pub dsa3072/C155A4EEE4E527A2 2018-08-16 Carlo Wood (CarloWood on Libera) <carlo@alinoe.com>
* fingerprint: 8020 B266 6305 EE2F D53E 6827 C155 A4EE E4E5 27A2
*
* This file is part of ai-utils.
*
* ai-utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ai-utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ai-utils. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
[[gnu::always_inline]] inline static void cpu_relax()
{
#if defined(__x86_64__) || defined(__i386__)
asm volatile("pause" ::: "memory");
#elif defined(__aarch64__)
asm volatile("yield" ::: "memory");
#else
#error "Please extent utils/cpu_relax.h for your architecture."
#endif
}