mirror of
https://github.com/cuberite/polarssl.git
synced 2025-10-03 10:34:16 -04:00
Merge pull request #8044 from daverodgman/msft-aarch64
Better support for MSVC aarch64 aka ARM64 and ARM64EC
This commit is contained in:
commit
422951b9ed
@ -62,6 +62,11 @@
|
|||||||
#define MBEDTLS_ARCH_IS_X86
|
#define MBEDTLS_ARCH_IS_X86
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \
|
||||||
|
(defined(_M_ARM64) || defined(_M_ARM64EC))
|
||||||
|
#define MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This is defined if the architecture is Armv8-A, or higher */
|
/* This is defined if the architecture is Armv8-A, or higher */
|
||||||
#if !defined(MBEDTLS_ARCH_IS_ARMV8_A)
|
#if !defined(MBEDTLS_ARCH_IS_ARMV8_A)
|
||||||
#if defined(__ARM_ARCH) && defined(__ARM_ARCH_PROFILE)
|
#if defined(__ARM_ARCH) && defined(__ARM_ARCH_PROFILE)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* By defining the macros ourselves we gain access to those declarations without
|
* By defining the macros ourselves we gain access to those declarations without
|
||||||
* requiring -march on the command line.
|
* requiring -march on the command line.
|
||||||
*
|
*
|
||||||
* `arm_neon.h` could be included by any header file, so we put these defines
|
* `arm_neon.h` is included by common.h, so we put these defines
|
||||||
* at the top of this file, before any includes.
|
* at the top of this file, before any includes.
|
||||||
*/
|
*/
|
||||||
#define __ARM_FEATURE_CRYPTO 1
|
#define __ARM_FEATURE_CRYPTO 1
|
||||||
@ -76,12 +76,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ARM_NEON
|
|
||||||
#include <arm_neon.h>
|
|
||||||
#else
|
|
||||||
#error "Target does not support NEON instructions"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !(defined(__ARM_FEATURE_CRYPTO) || defined(__ARM_FEATURE_AES)) || \
|
#if !(defined(__ARM_FEATURE_CRYPTO) || defined(__ARM_FEATURE_AES)) || \
|
||||||
defined(MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG)
|
defined(MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG)
|
||||||
# if defined(__ARMCOMPILER_VERSION)
|
# if defined(__ARMCOMPILER_VERSION)
|
||||||
@ -619,6 +613,6 @@ void mbedtls_aesce_gcm_mult(unsigned char c[16],
|
|||||||
#undef MBEDTLS_POP_TARGET_PRAGMA
|
#undef MBEDTLS_POP_TARGET_PRAGMA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* MBEDTLS_ARCH_IS_ARMV8_A */
|
#endif /* MBEDTLS_AESCE_HAVE_CODE */
|
||||||
|
|
||||||
#endif /* MBEDTLS_AESCE_C */
|
#endif /* MBEDTLS_AESCE_C */
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(__ARM_NEON) \
|
#if defined(MBEDTLS_AESCE_C) \
|
||||||
|
&& defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_HAVE_NEON_INTRINSICS) \
|
||||||
&& (defined(MBEDTLS_COMPILER_IS_GCC) || defined(__clang__) || defined(MSC_VER))
|
&& (defined(MBEDTLS_COMPILER_IS_GCC) || defined(__clang__) || defined(MSC_VER))
|
||||||
|
|
||||||
/* MBEDTLS_AESCE_HAVE_CODE is defined if we have a suitable target platform, and a
|
/* MBEDTLS_AESCE_HAVE_CODE is defined if we have a suitable target platform, and a
|
||||||
@ -129,7 +130,7 @@ int mbedtls_aesce_setkey_enc(unsigned char *rk,
|
|||||||
#error "AES hardware acceleration not supported on this platform / compiler"
|
#error "AES hardware acceleration not supported on this platform / compiler"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* MBEDTLS_AESCE_C && MBEDTLS_ARCH_IS_ARMV8_A && __ARM_NEON &&
|
#endif /* MBEDTLS_AESCE_C && MBEDTLS_ARCH_IS_ARMV8_A && MBEDTLS_HAVE_NEON_INTRINSICS &&
|
||||||
(MBEDTLS_COMPILER_IS_GCC || __clang__ || MSC_VER) */
|
(MBEDTLS_COMPILER_IS_GCC || __clang__ || MSC_VER) */
|
||||||
|
|
||||||
#endif /* MBEDTLS_AESCE_H */
|
#endif /* MBEDTLS_AESCE_H */
|
||||||
|
@ -23,11 +23,16 @@
|
|||||||
* efficient when this is not defined.
|
* efficient when this is not defined.
|
||||||
*/
|
*/
|
||||||
#if defined(__ARM_FEATURE_UNALIGNED) \
|
#if defined(__ARM_FEATURE_UNALIGNED) \
|
||||||
|| defined(__i386__) || defined(__amd64__) || defined(__x86_64__)
|
|| defined(MBEDTLS_ARCH_IS_X86) || defined(MBEDTLS_ARCH_IS_X64) \
|
||||||
|
|| defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
/*
|
/*
|
||||||
* __ARM_FEATURE_UNALIGNED is defined where appropriate by armcc, gcc 7, clang 9
|
* __ARM_FEATURE_UNALIGNED is defined where appropriate by armcc, gcc 7, clang 9
|
||||||
* (and later versions) for Arm v7 and later; all x86 platforms should have
|
* (and later versions) for Arm v7 and later; all x86 platforms should have
|
||||||
* efficient unaligned access.
|
* efficient unaligned access.
|
||||||
|
*
|
||||||
|
* https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#alignment
|
||||||
|
* specifies that on Windows-on-Arm64, unaligned access is safe (except for uncached
|
||||||
|
* device memory).
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS
|
#define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS
|
||||||
#endif
|
#endif
|
||||||
|
@ -102,7 +102,8 @@ int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X,
|
|||||||
* about whether the assignment was made or not.
|
* about whether the assignment was made or not.
|
||||||
* (Leaking information about the respective sizes of X and Y is ok however.)
|
* (Leaking information about the respective sizes of X and Y is ok however.)
|
||||||
*/
|
*/
|
||||||
#if defined(_MSC_VER) && defined(_M_ARM64) && (_MSC_FULL_VER < 193131103)
|
#if defined(_MSC_VER) && defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \
|
||||||
|
(_MSC_FULL_VER < 193131103)
|
||||||
/*
|
/*
|
||||||
* MSVC miscompiles this function if it's inlined prior to Visual Studio 2022 version 17.1. See:
|
* MSVC miscompiles this function if it's inlined prior to Visual Studio 2022 version 17.1. See:
|
||||||
* https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989
|
* https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989
|
||||||
|
@ -21,7 +21,11 @@
|
|||||||
|
|
||||||
#if defined(__ARM_NEON)
|
#if defined(__ARM_NEON)
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#endif /* __ARM_NEON */
|
#define MBEDTLS_HAVE_NEON_INTRINSICS
|
||||||
|
#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
|
#include <arm64_neon.h>
|
||||||
|
#define MBEDTLS_HAVE_NEON_INTRINSICS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \
|
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \
|
||||||
@ -178,16 +182,16 @@ inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned
|
|||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
||||||
#if defined(__ARM_NEON) && \
|
#if defined(MBEDTLS_HAVE_NEON_INTRINSICS) && \
|
||||||
(!defined(MBEDTLS_COMPILER_IS_GCC) || \
|
(!(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION < 70300))
|
||||||
(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION >= 70300))
|
/* Old GCC versions generate a warning here, so disable the NEON path for these compilers */
|
||||||
for (; (i + 16) <= n; i += 16) {
|
for (; (i + 16) <= n; i += 16) {
|
||||||
uint8x16_t v1 = vld1q_u8(a + i);
|
uint8x16_t v1 = vld1q_u8(a + i);
|
||||||
uint8x16_t v2 = vld1q_u8(b + i);
|
uint8x16_t v2 = vld1q_u8(b + i);
|
||||||
uint8x16_t x = veorq_u8(v1, v2);
|
uint8x16_t x = veorq_u8(v1, v2);
|
||||||
vst1q_u8(r + i, x);
|
vst1q_u8(r + i, x);
|
||||||
}
|
}
|
||||||
#elif defined(__amd64__) || defined(__x86_64__) || defined(__aarch64__)
|
#elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
|
||||||
/* This codepath probably only makes sense on architectures with 64-bit registers */
|
/* This codepath probably only makes sense on architectures with 64-bit registers */
|
||||||
for (; (i + 8) <= n; i += 8) {
|
for (; (i + 8) <= n; i += 8) {
|
||||||
uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
|
uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
|
||||||
@ -226,7 +230,7 @@ static inline void mbedtls_xor_no_simd(unsigned char *r,
|
|||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
||||||
#if defined(__amd64__) || defined(__x86_64__) || defined(__aarch64__)
|
#if defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
|
||||||
/* This codepath probably only makes sense on architectures with 64-bit registers */
|
/* This codepath probably only makes sense on architectures with 64-bit registers */
|
||||||
for (; (i + 8) <= n; i += 8) {
|
for (; (i + 8) <= n; i += 8) {
|
||||||
uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
|
uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
* By defining the macros ourselves we gain access to those declarations without
|
* By defining the macros ourselves we gain access to those declarations without
|
||||||
* requiring -march on the command line.
|
* requiring -march on the command line.
|
||||||
*
|
*
|
||||||
* `arm_neon.h` could be included by any header file, so we put these defines
|
* `arm_neon.h` is included by common.h, so we put these defines
|
||||||
* at the top of this file, before any includes.
|
* at the top of this file, before any includes.
|
||||||
*/
|
*/
|
||||||
#define __ARM_FEATURE_CRYPTO 1
|
#define __ARM_FEATURE_CRYPTO 1
|
||||||
@ -62,9 +62,7 @@
|
|||||||
|
|
||||||
# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
|
# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
|
||||||
defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
|
defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
|
||||||
# ifdef __ARM_NEON
|
# if !defined(MBEDTLS_HAVE_NEON_INTRINSICS)
|
||||||
# include <arm_neon.h>
|
|
||||||
# else
|
|
||||||
# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
|
# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
|
||||||
# warning "Target does not support NEON instructions"
|
# warning "Target does not support NEON instructions"
|
||||||
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
|
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
|
||||||
@ -126,12 +124,7 @@
|
|||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#elif defined(_M_ARM64)
|
#elif !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \
|
|
||||||
defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
|
|
||||||
# include <arm64_neon.h>
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
|
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
|
||||||
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
|
# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
|
||||||
#endif
|
#endif
|
||||||
@ -156,7 +149,7 @@ static int mbedtls_a64_crypto_sha256_determine_support(void)
|
|||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#elif defined(_M_ARM64)
|
#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <processthreadsapi.h>
|
#include <processthreadsapi.h>
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
* By defining the macros ourselves we gain access to those declarations without
|
* By defining the macros ourselves we gain access to those declarations without
|
||||||
* requiring -march on the command line.
|
* requiring -march on the command line.
|
||||||
*
|
*
|
||||||
* `arm_neon.h` could be included by any header file, so we put these defines
|
* `arm_neon.h` is included by common.h, so we put these defines
|
||||||
* at the top of this file, before any includes.
|
* at the top of this file, before any includes.
|
||||||
*/
|
*/
|
||||||
#define __ARM_FEATURE_SHA512 1
|
#define __ARM_FEATURE_SHA512 1
|
||||||
@ -48,9 +48,7 @@
|
|||||||
# if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
|
# if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
|
||||||
defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
|
defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
# ifdef __ARM_NEON
|
# if !defined(MBEDTLS_HAVE_NEON_INTRINSICS)
|
||||||
# include <arm_neon.h>
|
|
||||||
# else
|
|
||||||
# error "Target does not support NEON instructions"
|
# error "Target does not support NEON instructions"
|
||||||
# endif
|
# endif
|
||||||
/*
|
/*
|
||||||
@ -109,12 +107,7 @@
|
|||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#elif defined(_M_ARM64)
|
#elif !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
# if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \
|
|
||||||
defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
|
|
||||||
# include <arm64_neon.h>
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# undef MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
|
# undef MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
|
||||||
# undef MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
|
# undef MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
|
||||||
#endif
|
#endif
|
||||||
@ -142,7 +135,7 @@ static int mbedtls_a64_crypto_sha512_determine_support(void)
|
|||||||
NULL, 0);
|
NULL, 0);
|
||||||
return ret == 0 && value != 0;
|
return ret == 0 && value != 0;
|
||||||
}
|
}
|
||||||
#elif defined(_M_ARM64)
|
#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
|
||||||
/*
|
/*
|
||||||
* As of March 2022, there don't appear to be any PF_ARM_V8_* flags
|
* As of March 2022, there don't appear to be any PF_ARM_V8_* flags
|
||||||
* available to pass to IsProcessorFeaturePresent() to check for
|
* available to pass to IsProcessorFeaturePresent() to check for
|
||||||
|
Loading…
x
Reference in New Issue
Block a user