Deshim VirtualExecutor in folly
[hiphop-php.git] / hphp / util / arch.h
blobfa2ba3c6e1a39ed5acfbde5a81a86a2c6c473f16
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 #pragma once
19 #include "hphp/util/assertions.h"
21 namespace HPHP {
22 ///////////////////////////////////////////////////////////////////////////////
24 enum class Arch { X64, ARM, };
26 constexpr Arch arch() {
27 #if defined(__aarch64__)
28 return Arch::ARM;
29 #else
30 return Arch::X64;
31 #endif
34 constexpr bool arch_any() { return false; }
37 * Convenience helper for guarding on a set of architectures.
39 template<class... Tail>
40 bool arch_any(Arch a, Tail&&... archs) {
41 return arch() == a || arch_any(archs...);
45 * MSVC's Preprocessor is completely idiotic, so we have to play by its rules
46 * and forcefully expand the variadic args so they aren't all interpreted as the
47 * first argument to func.
49 #define MSVC_GLUE(x, y) x y
52 * Macro for defining easy arch-dispatch wrappers.
54 * We need to specify the return type explicitly, or else we may drop refs.
56 #define ARCH_SWITCH_CALL(func, ...) \
57 ([&]() -> decltype(x64::func(__VA_ARGS__)) { \
58 switch (arch()) { \
59 case Arch::X64: \
60 return x64::MSVC_GLUE(func, (__VA_ARGS__)); \
61 case Arch::ARM: \
62 return arm::MSVC_GLUE(func, (__VA_ARGS__)); \
63 } \
64 not_reached(); \
65 }())
67 ///////////////////////////////////////////////////////////////////////////////