浏览代码

AES-NI/NEON detection for iOS

Requires 64-bit CPU
Grant Limberg 4 年之前
父节点
当前提交
0f2887265c
共有 3 个文件被更改,包括 22 次插入0 次删除
  1. 4 0
      node/AES.cpp
  2. 6 0
      node/Constants.hpp
  3. 12 0
      node/Utils.cpp

+ 4 - 0
node/AES.cpp

@@ -18,6 +18,10 @@
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
+#ifdef __APPLE__
+#include <arm_neon.h>
+#endif
+
 #define Te1_r(x) ZT_ROR32(Te0[x], 8U)
 #define Te2_r(x) ZT_ROR32(Te0[x], 16U)
 #define Te3_r(x) ZT_ROR32(Te0[x], 24U)

+ 6 - 0
node/Constants.hpp

@@ -112,12 +112,18 @@
 #endif
 
 #if (defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(ZT_ARCH_ARM_HAS_NEON))
+#if defined(__APPLE__) && !defined(__LP64__)
+#ifdef ZT_ARCH_ARM_HAS_NEON
+#undef ZT_ARCH_ARM_HAS_NEON
+#endif
+#else
 #ifndef ZT_ARCH_ARM_HAS_NEON
 #define ZT_ARCH_ARM_HAS_NEON 1
 #endif
 #include <arm_neon.h>
 /*#include <arm_acle.h>*/
 #endif
+#endif
 
 // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64.
 #if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386)))

+ 12 - 0
node/Utils.cpp

@@ -42,6 +42,10 @@
 #include "Mutex.hpp"
 #include "Salsa20.hpp"
 
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#endif
+
 namespace ZeroTier {
 
 const uint64_t Utils::ZERO256[4] = {0ULL,0ULL,0ULL,0ULL};
@@ -51,6 +55,13 @@ const char Utils::HEXCHARS[16] = { '0','1','2','3','4','5','6','7','8','9','a','
 #ifdef ZT_ARCH_ARM_HAS_NEON
 Utils::ARMCapabilities::ARMCapabilities() noexcept
 {
+#if TARGET_OS_IPHONE
+    this->aes = true;
+    this->crc32 = true;
+    this->pmull = true;
+    this->sha1 = true;
+    this->sha2 = true;
+#else
 #ifdef HWCAP2_AES
 	if (sizeof(void *) == 4) {
 		const long hwcaps2 = getauxval(AT_HWCAP2);
@@ -70,6 +81,7 @@ Utils::ARMCapabilities::ARMCapabilities() noexcept
 #ifdef HWCAP2_AES
 	}
 #endif
+#endif // TARGET_OS_IPHONE
 }
 
 const Utils::ARMCapabilities Utils::ARMCAP;