diff options
author | Richard Lau <rlau@redhat.com> | 2023-02-08 14:13:24 +0100 |
---|---|---|
committer | Richard Lau <rlau@redhat.com> | 2023-02-13 13:39:28 +0000 |
commit | d80e8312fda77eacb8f74af309f3e70676cc6462 (patch) | |
tree | 386ea2b824c56f1ecc5b4c42f00365a78e7d64b9 | |
parent | de5c8d2c2f5819fd49f78abdb675716e05d0b230 (diff) | |
download | node-new-d80e8312fda77eacb8f74af309f3e70676cc6462.tar.gz |
deps: cherry-pick Windows ARM64 fix for openssl
Original commit message:
rsa: add msvc intrinsic for non x64 platforms
_umul128() is x86_64 (x64) only, while __umulh() works everywhere, but
doesn't generate optimal code on x64
PR-URL: https://github.com/nodejs/node/pull/46568
Refs: https://github.com/openssl/openssl/pull/20244
Refs: https://mta.openssl.org/pipermail/openssl-announce/2023-February/000251.html
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
-rw-r--r-- | deps/openssl/openssl/crypto/bn/rsa_sup_mul.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/deps/openssl/openssl/crypto/bn/rsa_sup_mul.c b/deps/openssl/openssl/crypto/bn/rsa_sup_mul.c index acafefd5fe..c027ba411e 100644 --- a/deps/openssl/openssl/crypto/bn/rsa_sup_mul.c +++ b/deps/openssl/openssl/crypto/bn/rsa_sup_mul.c @@ -110,12 +110,34 @@ static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b) *lo = (limb_t)t; } #elif (BN_BYTES == 8) && (defined _MSC_VER) -/* https://learn.microsoft.com/en-us/cpp/intrinsics/umul128?view=msvc-170 */ +# if defined(_M_X64) +/* + * on x86_64 (x64) we can use the _umul128 intrinsic to get one `mul` + * instruction to get both high and low 64 bits of the multiplication. + * https://learn.microsoft.com/en-us/cpp/intrinsics/umul128?view=msvc-140 + */ +#include <intrin.h> #pragma intrinsic(_umul128) static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b) { *lo = _umul128(a, b, hi); } +# elif defined(_M_ARM64) || defined (_M_IA64) +/* + * We can't use the __umulh() on x86_64 as then msvc generates two `mul` + * instructions; so use this more portable intrinsic on platforms that + * don't support _umul128 (like aarch64 (ARM64) or ia64) + * https://learn.microsoft.com/en-us/cpp/intrinsics/umulh?view=msvc-140 + */ +#include <intrin.h> +static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b) +{ + *lo = a * b; + *hi = __umulh(a, b); +} +# else +# error Only x64, ARM64 and IA64 supported. +# endif /* defined(_M_X64) */ #else /* * if the compiler doesn't have either a 128bit data type nor a "return |