|
||||
File indexing completed on 2024-11-15 09:01:08
0001 // Copyright 2017 The Abseil Authors. 0002 // 0003 // Licensed under the Apache License, Version 2.0 (the "License"); 0004 // you may not use this file except in compliance with the License. 0005 // You may obtain a copy of the License at 0006 // 0007 // https://www.apache.org/licenses/LICENSE-2.0 0008 // 0009 // Unless required by applicable law or agreed to in writing, software 0010 // distributed under the License is distributed on an "AS IS" BASIS, 0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 // See the License for the specific language governing permissions and 0013 // limitations under the License. 0014 0015 #ifndef ABSL_RANDOM_INTERNAL_PLATFORM_H_ 0016 #define ABSL_RANDOM_INTERNAL_PLATFORM_H_ 0017 0018 // HERMETIC NOTE: The randen_hwaes target must not introduce duplicate 0019 // symbols from arbitrary system and other headers, since it may be built 0020 // with different flags from other targets, using different levels of 0021 // optimization, potentially introducing ODR violations. 0022 0023 // ----------------------------------------------------------------------------- 0024 // Platform Feature Checks 0025 // ----------------------------------------------------------------------------- 0026 0027 // Currently supported operating systems and associated preprocessor 0028 // symbols: 0029 // 0030 // Linux and Linux-derived __linux__ 0031 // Android __ANDROID__ (implies __linux__) 0032 // Linux (non-Android) __linux__ && !__ANDROID__ 0033 // Darwin (macOS and iOS) __APPLE__ 0034 // Akaros (http://akaros.org) __ros__ 0035 // Windows _WIN32 0036 // NaCL __native_client__ 0037 // AsmJS __asmjs__ 0038 // WebAssembly __wasm__ 0039 // Fuchsia __Fuchsia__ 0040 // 0041 // Note that since Android defines both __ANDROID__ and __linux__, one 0042 // may probe for either Linux or Android by simply testing for __linux__. 0043 // 0044 // NOTE: For __APPLE__ platforms, we use #include <TargetConditionals.h> 0045 // to distinguish os variants. 0046 // 0047 // http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system 0048 0049 #if defined(__APPLE__) 0050 #include <TargetConditionals.h> 0051 #endif 0052 0053 // ----------------------------------------------------------------------------- 0054 // Architecture Checks 0055 // ----------------------------------------------------------------------------- 0056 0057 // These preprocessor directives are trying to determine CPU architecture, 0058 // including necessary headers to support hardware AES. 0059 // 0060 // ABSL_ARCH_{X86/PPC/ARM} macros determine the platform. 0061 #if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || \ 0062 defined(_M_X64) 0063 #define ABSL_ARCH_X86_64 0064 #elif defined(__i386) || defined(_M_IX86) 0065 #define ABSL_ARCH_X86_32 0066 #elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) 0067 #define ABSL_ARCH_AARCH64 0068 #elif defined(__arm__) || defined(__ARMEL__) || defined(_M_ARM) 0069 #define ABSL_ARCH_ARM 0070 #elif defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \ 0071 defined(__ppc__) || defined(__PPC__) 0072 #define ABSL_ARCH_PPC 0073 #else 0074 // Unsupported architecture. 0075 // * https://sourceforge.net/p/predef/wiki/Architectures/ 0076 // * https://msdn.microsoft.com/en-us/library/b0084kay.aspx 0077 // * for gcc, clang: "echo | gcc -E -dM -" 0078 #endif 0079 0080 // ----------------------------------------------------------------------------- 0081 // Attribute Checks 0082 // ----------------------------------------------------------------------------- 0083 0084 // ABSL_RANDOM_INTERNAL_RESTRICT annotates whether pointers may be considered 0085 // to be unaliased. 0086 #if defined(__clang__) || defined(__GNUC__) 0087 #define ABSL_RANDOM_INTERNAL_RESTRICT __restrict__ 0088 #elif defined(_MSC_VER) 0089 #define ABSL_RANDOM_INTERNAL_RESTRICT __restrict 0090 #else 0091 #define ABSL_RANDOM_INTERNAL_RESTRICT 0092 #endif 0093 0094 // ABSL_HAVE_ACCELERATED_AES indicates whether the currently active compiler 0095 // flags (e.g. -maes) allow using hardware accelerated AES instructions, which 0096 // implies us assuming that the target platform supports them. 0097 #define ABSL_HAVE_ACCELERATED_AES 0 0098 0099 #if defined(ABSL_ARCH_X86_64) 0100 0101 #if defined(__AES__) || defined(__AVX__) 0102 #undef ABSL_HAVE_ACCELERATED_AES 0103 #define ABSL_HAVE_ACCELERATED_AES 1 0104 #endif 0105 0106 #elif defined(ABSL_ARCH_PPC) 0107 0108 // Rely on VSX and CRYPTO extensions for vcipher on PowerPC. 0109 #if (defined(__VEC__) || defined(__ALTIVEC__)) && defined(__VSX__) && \ 0110 defined(__CRYPTO__) 0111 #undef ABSL_HAVE_ACCELERATED_AES 0112 #define ABSL_HAVE_ACCELERATED_AES 1 0113 #endif 0114 0115 #elif defined(ABSL_ARCH_ARM) || defined(ABSL_ARCH_AARCH64) 0116 0117 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf 0118 // Rely on NEON+CRYPTO extensions for ARM. 0119 #if defined(__ARM_NEON) && defined(__ARM_FEATURE_CRYPTO) 0120 #undef ABSL_HAVE_ACCELERATED_AES 0121 #define ABSL_HAVE_ACCELERATED_AES 1 0122 #endif 0123 0124 #endif 0125 0126 // NaCl does not allow AES. 0127 #if defined(__native_client__) 0128 #undef ABSL_HAVE_ACCELERATED_AES 0129 #define ABSL_HAVE_ACCELERATED_AES 0 0130 #endif 0131 0132 // ABSL_RANDOM_INTERNAL_AES_DISPATCH indicates whether the currently active 0133 // platform has, or should use run-time dispatch for selecting the 0134 // accelerated Randen implementation. 0135 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 0 0136 0137 #if defined(ABSL_ARCH_X86_64) 0138 // Dispatch is available on x86_64 0139 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0140 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 1 0141 #elif defined(__linux__) && defined(ABSL_ARCH_PPC) 0142 // Or when running linux PPC 0143 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0144 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 1 0145 #elif defined(__linux__) && defined(ABSL_ARCH_AARCH64) 0146 // Or when running linux AArch64 0147 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0148 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 1 0149 #elif defined(__linux__) && defined(ABSL_ARCH_ARM) && (__ARM_ARCH >= 8) 0150 // Or when running linux ARM v8 or higher. 0151 // (This captures a lot of Android configurations.) 0152 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0153 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 1 0154 #endif 0155 0156 // NaCl does not allow dispatch. 0157 #if defined(__native_client__) 0158 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0159 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 0 0160 #endif 0161 0162 // iOS does not support dispatch, even on x86, since applications 0163 // should be bundled as fat binaries, with a different build tailored for 0164 // each specific supported platform/architecture. 0165 #if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \ 0166 (defined(TARGET_OS_IPHONE_SIMULATOR) && TARGET_OS_IPHONE_SIMULATOR) 0167 #undef ABSL_RANDOM_INTERNAL_AES_DISPATCH 0168 #define ABSL_RANDOM_INTERNAL_AES_DISPATCH 0 0169 #endif 0170 0171 #endif // ABSL_RANDOM_INTERNAL_PLATFORM_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |