Skip to content

Commit 1f4dd03

Browse files
Typedef (u)int128_t only when they're not provided by the compiler
1 parent e89278f commit 1f4dd03

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,20 @@ static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag)
260260
# define SECP256K1_WIDEMUL_INT128 1
261261
#elif defined(USE_FORCE_WIDEMUL_INT64)
262262
# define SECP256K1_WIDEMUL_INT64 1
263-
#elif defined(__SIZEOF_INT128__)
263+
#elif defined(UINT128_MAX) || defined(__SIZEOF_INT128__)
264264
# define SECP256K1_WIDEMUL_INT128 1
265265
#else
266266
# define SECP256K1_WIDEMUL_INT64 1
267267
#endif
268268
#if defined(SECP256K1_WIDEMUL_INT128)
269+
# if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__)
269270
SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;
270271
SECP256K1_GNUC_EXT typedef __int128 int128_t;
272+
#define UINT128_MAX ((uint128_t)(-1))
273+
#define INT128_MAX ((int128_t)(UINT128_MAX >> 1))
274+
#define INT128_MIN (-INT128_MAX - 1)
275+
/* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */
276+
# endif
271277
#endif
272278

273279
#endif /* SECP256K1_UTIL_H */

0 commit comments

Comments
 (0)