AES-NI/NEON detection for iOS

Requires 64-bit CPU
This commit is contained in:
Grant Limberg 2020-09-21 13:17:12 -07:00
parent 1ff45020e2
commit 0f2887265c
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A
3 changed files with 22 additions and 0 deletions

View File

@ -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)

View File

@ -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)))

View File

@ -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;