@@ -230,21 +230,34 @@ static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag)
230
230
* r = (int )(r_masked | a_masked );
231
231
}
232
232
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
- */
236
233
#if defined(USE_FORCE_WIDEMUL_INT128_STRUCT )
234
+ /* If USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */
237
235
# define SECP256K1_WIDEMUL_INT128 1
238
236
# define SECP256K1_INT128_STRUCT 1
239
237
#elif defined(USE_FORCE_WIDEMUL_INT128 )
238
+ /* If USE_FORCE_WIDEMUL_INT128 is set, use int128. */
240
239
# define SECP256K1_WIDEMUL_INT128 1
241
240
# define SECP256K1_INT128_NATIVE 1
242
241
#elif defined(USE_FORCE_WIDEMUL_INT64 )
242
+ /* If USE_FORCE_WIDEMUL_INT64 is set, use int64. */
243
243
# define SECP256K1_WIDEMUL_INT64 1
244
244
#elif defined(UINT128_MAX ) || defined(__SIZEOF_INT128__ )
245
+ /* If a native 128-bit integer type exists, use int128. */
245
246
# define SECP256K1_WIDEMUL_INT128 1
246
247
# 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
247
259
#else
260
+ /* Lastly, fall back to int64 based arithmetic. */
248
261
# define SECP256K1_WIDEMUL_INT64 1
249
262
#endif
250
263
0 commit comments