Optional Two-phase heap tracing
[hiphop-php.git] / hphp / util / arch.h
blob949cf26b1bf4c9faf9279a0c3cd1da10def69544
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_ARCH_H
18 #define incl_HPHP_ARCH_H
20 #include "hphp/util/assertions.h"
22 namespace HPHP {
23 ///////////////////////////////////////////////////////////////////////////////
25 enum class Arch { X64, ARM, PPC64, };
27 constexpr Arch arch() {
28 #if defined(__powerpc64__)
29 return Arch::PPC64;
30 #elif defined(__aarch64__)
31 return Arch::ARM;
32 #else
33 return Arch::X64;
34 #endif
37 constexpr bool arch_any() { return false; }
40 * Convenience helper for guarding on a set of architectures.
42 template<class... Tail>
43 bool arch_any(Arch a, Tail&&... archs) {
44 return arch() == a || arch_any(archs...);
48 * MSVC's Preprocessor is completely idiotic, so we have to play by its rules
49 * and forcefully expand the variadic args so they aren't all interpreted as the
50 * first argument to func.
52 #define MSVC_GLUE(x, y) x y
55 * Macro for defining easy arch-dispatch wrappers.
57 * We need to specify the return type explicitly, or else we may drop refs.
59 #define ARCH_SWITCH_CALL(func, ...) \
60 ([&]() -> decltype(x64::func(__VA_ARGS__)) { \
61 switch (arch()) { \
62 case Arch::X64: \
63 return x64::MSVC_GLUE(func, (__VA_ARGS__)); \
64 case Arch::ARM: \
65 return arm::MSVC_GLUE(func, (__VA_ARGS__)); \
66 case Arch::PPC64: \
67 return ppc64::MSVC_GLUE(func, (__VA_ARGS__)); \
68 } \
69 not_reached(); \
70 }())
72 ///////////////////////////////////////////////////////////////////////////////
76 #endif