Skip to content

Commit c8d49e2

Browse files
Simulated int128 type.
1 parent 5d0dbef commit c8d49e2

13 files changed

+688
-294
lines changed

Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ noinst_HEADERS += src/modinv64.h
4040
noinst_HEADERS += src/modinv64_impl.h
4141
noinst_HEADERS += src/assumptions.h
4242
noinst_HEADERS += src/util.h
43+
noinst_HEADERS += src/int128.h
44+
noinst_HEADERS += src/int128_impl.h
45+
noinst_HEADERS += src/int128_native.h
46+
noinst_HEADERS += src/int128_native_impl.h
47+
noinst_HEADERS += src/int128_struct.h
48+
noinst_HEADERS += src/int128_struct_impl.h
4349
noinst_HEADERS += src/scratch.h
4450
noinst_HEADERS += src/scratch_impl.h
4551
noinst_HEADERS += src/selftest.h

configure.ac

+8-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ AC_ARG_ENABLE(external_default_callbacks,
156156
[use_external_default_callbacks=no])
157157

158158
# Test-only override of the (autodetected by the C code) "widemul" setting.
159-
# Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default).
159+
# Legal values are:
160+
# * int64 (for [u]int64_t),
161+
# * int128 (for [unsigned] __int128),
162+
# * int128_struct (for int128 implemented as a structure),
163+
# * and auto (the default).
160164
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
161165

162166
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
@@ -267,6 +271,9 @@ fi
267271

268272
# Select wide multiplication implementation
269273
case $set_widemul in
274+
int128_struct)
275+
AC_DEFINE(USE_FORCE_WIDEMUL_INT128_STRUCT, 1, [Define this symbol to force the use of the structure for simulating (unsigned) int128 based wide multiplication])
276+
;;
270277
int128)
271278
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
272279
;;

src/assumptions.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <limits.h>
1111

1212
#include "util.h"
13+
#if defined(SECP256K1_INT128_NATIVE)
14+
#include "int128_native.h"
15+
#endif
1316

1417
/* This library, like most software, relies on a number of compiler implementation defined (but not undefined)
1518
behaviours. Although the behaviours we require are essentially universal we test them specifically here to
@@ -55,7 +58,7 @@ struct secp256k1_assumption_checker {
5558

5659
/* To int64_t. */
5760
((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL) &&
58-
#if defined(SECP256K1_WIDEMUL_INT128)
61+
#if defined(SECP256K1_INT128_NATIVE)
5962
((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL) &&
6063
(((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL) &&
6164
(((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL) &&
@@ -71,7 +74,7 @@ struct secp256k1_assumption_checker {
7174
((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A) &&
7275
((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48) &&
7376
((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL) &&
74-
#if defined(SECP256K1_WIDEMUL_INT128)
77+
#if defined(SECP256K1_INT128_NATIVE)
7578
((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL)) &&
7679
#endif
7780
1) * 2 - 1];

0 commit comments

Comments
 (0)