Skip to content

Commit d80e831

Browse files
committedFeb 13, 2023
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: #46568 Refs: openssl/openssl#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>
1 parent de5c8d2 commit d80e831

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)
Please sign in to comment.