Skip to content

Commit 66a24ce

Browse files
richardlauRafaelGSS
authored andcommitted
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: #46573 Refs: openssl/openssl#20244 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent d8559aa commit 66a24ce

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

deps/openssl/openssl/crypto/bn/rsa_sup_mul.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,34 @@ static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
110110
*lo = (limb_t)t;
111111
}
112112
#elif (BN_BYTES == 8) && (defined _MSC_VER)
113-
/* https://learn.microsoft.com/en-us/cpp/intrinsics/umul128?view=msvc-170 */
113+
# if defined(_M_X64)
114+
/*
115+
* on x86_64 (x64) we can use the _umul128 intrinsic to get one `mul`
116+
* instruction to get both high and low 64 bits of the multiplication.
117+
* https://learn.microsoft.com/en-us/cpp/intrinsics/umul128?view=msvc-140
118+
*/
119+
#include <intrin.h>
114120
#pragma intrinsic(_umul128)
115121
static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
116122
{
117123
*lo = _umul128(a, b, hi);
118124
}
125+
# elif defined(_M_ARM64) || defined (_M_IA64)
126+
/*
127+
* We can't use the __umulh() on x86_64 as then msvc generates two `mul`
128+
* instructions; so use this more portable intrinsic on platforms that
129+
* don't support _umul128 (like aarch64 (ARM64) or ia64)
130+
* https://learn.microsoft.com/en-us/cpp/intrinsics/umulh?view=msvc-140
131+
*/
132+
#include <intrin.h>
133+
static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
134+
{
135+
*lo = a * b;
136+
*hi = __umulh(a, b);
137+
}
138+
# else
139+
# error Only x64, ARM64 and IA64 supported.
140+
# endif /* defined(_M_X64) */
119141
#else
120142
/*
121143
* if the compiler doesn't have either a 128bit data type nor a "return

0 commit comments

Comments
 (0)