Skip to content

Commit 63ff064

Browse files
real-or-randomsipa
authored andcommitted
int128: Add test override for testing __(u)mulh on MSVC X64
Also add a corresponding CI job
1 parent f2b7e88 commit 63ff064

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.cirrus.yml

+4
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ task:
288288
- name: "x86_64 (MSVC): Windows (Debian stable, Wine, int128_struct)"
289289
env:
290290
WIDEMUL: int128_struct
291+
- name: "x86_64 (MSVC): Windows (Debian stable, Wine, int128_struct with __(u)mulh)"
292+
env:
293+
WIDEMUL: int128_struct
294+
CPPFLAGS: -DSECP256K1_MSVC_MULH_TEST_OVERRIDE
291295
- name: "i686 (MSVC): Windows (Debian stable, Wine)"
292296
env:
293297
HOST: i686-w64-mingw32

src/int128_struct_impl.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) /* MSVC */
77
# include <intrin.h>
8-
# if defined(_M_X64)
9-
/* On x84_64 MSVC, use native _(u)mul128 for 64x64->128 multiplications. */
10-
# define secp256k1_umul128 _umul128
11-
# define secp256k1_mul128 _mul128
12-
# else
13-
/* On ARM64 MSVC, use __(u)mulh for the upper half of 64x64 multiplications. */
8+
# if defined(_M_ARM64) || defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE)
9+
/* On ARM64 MSVC, use __(u)mulh for the upper half of 64x64 multiplications.
10+
(Define SECP256K1_MSVC_MULH_TEST_OVERRIDE to test this code path on X64,
11+
which supports both __(u)mulh and _umul128.) */
12+
# if defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE)
13+
# pragma message(__FILE__ ": SECP256K1_MSVC_MULH_TEST_OVERRIDE is defined, forcing use of __(u)mulh.")
14+
# endif
1415
static SECP256K1_INLINE uint64_t secp256k1_umul128(uint64_t a, uint64_t b, uint64_t* hi) {
1516
*hi = __umulh(a, b);
1617
return a * b;
@@ -20,6 +21,10 @@ static SECP256K1_INLINE int64_t secp256k1_mul128(int64_t a, int64_t b, int64_t*
2021
*hi = __mulh(a, b);
2122
return a * b;
2223
}
24+
# else
25+
/* On x84_64 MSVC, use native _(u)mul128 for 64x64->128 multiplications. */
26+
# define secp256k1_umul128 _umul128
27+
# define secp256k1_mul128 _mul128
2328
# endif
2429
#else
2530
/* On other systems, emulate 64x64->128 multiplications using 32x32->64 multiplications. */

0 commit comments

Comments
 (0)