@@ -230,21 +230,34 @@ static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag)
230230 * r = (int )(r_masked | a_masked );
231231}
232232
233- /* If USE_FORCE_WIDEMUL_{INT128, INT128_STRUCT, INT64} is set, use that wide multiplication implementation.
234- * Otherwise use the presence of __SIZEOF_INT128__ to decide.
235- */
236233#if defined(USE_FORCE_WIDEMUL_INT128_STRUCT )
234+ /* If USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */
237235# define SECP256K1_WIDEMUL_INT128 1
238236# define SECP256K1_INT128_STRUCT 1
239237#elif defined(USE_FORCE_WIDEMUL_INT128 )
238+ /* If USE_FORCE_WIDEMUL_INT128 is set, use int128. */
240239# define SECP256K1_WIDEMUL_INT128 1
241240# define SECP256K1_INT128_NATIVE 1
242241#elif defined(USE_FORCE_WIDEMUL_INT64 )
242+ /* If USE_FORCE_WIDEMUL_INT64 is set, use int64. */
243243# define SECP256K1_WIDEMUL_INT64 1
244244#elif defined(UINT128_MAX ) || defined(__SIZEOF_INT128__ )
245+ /* If a native 128-bit integer type exists, use int128. */
245246# define SECP256K1_WIDEMUL_INT128 1
246247# define SECP256K1_INT128_NATIVE 1
248+ #elif defined(_MSC_VER ) && (defined(_M_X64 ) || defined(_M_ARM64 ))
249+ /* On 64-bit MSVC targets (x86_64 and arm64), use int128_struct
250+ * (which has special logic to implement using intrinsics on those systems). */
251+ # define SECP256K1_WIDEMUL_INT128 1
252+ # define SECP256K1_INT128_STRUCT 1
253+ #elif SIZE_MAX > 0xffffffff
254+ /* Systems with 64-bit pointers (and thus registers) very likely benefit from
255+ * using 64-bit based arithmetic (even if we need to fall back to 32x32->64 based
256+ * multiplication logic). */
257+ # define SECP256K1_WIDEMUL_INT128 1
258+ # define SECP256K1_INT128_STRUCT 1
247259#else
260+ /* Lastly, fall back to int64 based arithmetic. */
248261# define SECP256K1_WIDEMUL_INT64 1
249262#endif
250263
0 commit comments