Electroneum
Loading...
Searching...
No Matches
scalar_4x64_impl.h File Reference
#include "checkmem.h"
#include "int128.h"
#include "modinv64_impl.h"
Include dependency graph for scalar_4x64_impl.h:

Go to the source code of this file.

Macros

#define SECP256K1_N_0   ((uint64_t)0xBFD25E8CD0364141ULL)
#define SECP256K1_N_1   ((uint64_t)0xBAAEDCE6AF48A03BULL)
#define SECP256K1_N_2   ((uint64_t)0xFFFFFFFFFFFFFFFEULL)
#define SECP256K1_N_3   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
#define SECP256K1_N_C_0   (~SECP256K1_N_0 + 1)
#define SECP256K1_N_C_1   (~SECP256K1_N_1)
#define SECP256K1_N_C_2   (1)
#define SECP256K1_N_H_0   ((uint64_t)0xDFE92F46681B20A0ULL)
#define SECP256K1_N_H_1   ((uint64_t)0x5D576E7357A4501DULL)
#define SECP256K1_N_H_2   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
#define SECP256K1_N_H_3   ((uint64_t)0x7FFFFFFFFFFFFFFFULL)
#define muladd(a, b)
#define muladd_fast(a, b)
#define sumadd(a)
#define sumadd_fast(a)
#define extract(n)
#define extract_fast(n)

Macro Definition Documentation

◆ extract

#define extract ( n)
Value:
{ \
(n) = c0; \
c0 = c1; \
c1 = c2; \
c2 = 0; \
}

Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.

Definition at line 260 of file scalar_4x64_impl.h.

260#define extract(n) { \
261 (n) = c0; \
262 c0 = c1; \
263 c1 = c2; \
264 c2 = 0; \
265}

◆ extract_fast

#define extract_fast ( n)
Value:
{ \
(n) = c0; \
c0 = c1; \
c1 = 0; \
VERIFY_CHECK(c2 == 0); \
}

Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits. c2 is required to be zero.

Definition at line 268 of file scalar_4x64_impl.h.

268#define extract_fast(n) { \
269 (n) = c0; \
270 c0 = c1; \
271 c1 = 0; \
272 VERIFY_CHECK(c2 == 0); \
273}

◆ muladd

#define muladd ( a,
b )
Value:
{ \
uint64_t tl, th; \
{ \
secp256k1_u128_mul(&t, a, b); \
th = secp256k1_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \
tl = secp256k1_u128_to_u64(&t); \
} \
c0 += tl; /* overflow is handled on the next line */ \
th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \
c1 += th; /* overflow is handled on the next line */ \
c2 += (c1 < th); /* never overflows by contract (verified in the next line) */ \
VERIFY_CHECK((c1 >= th) || (c2 != 0)); \
}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
unsigned __int64 uint64_t
Definition stdint.h:136

Add a*b to the number defined by (c0,c1,c2). c2 must never overflow.

Definition at line 212 of file scalar_4x64_impl.h.

212#define muladd(a,b) { \
213 uint64_t tl, th; \
214 { \
215 secp256k1_uint128 t; \
216 secp256k1_u128_mul(&t, a, b); \
217 th = secp256k1_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \
218 tl = secp256k1_u128_to_u64(&t); \
219 } \
220 c0 += tl; /* overflow is handled on the next line */ \
221 th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \
222 c1 += th; /* overflow is handled on the next line */ \
223 c2 += (c1 < th); /* never overflows by contract (verified in the next line) */ \
224 VERIFY_CHECK((c1 >= th) || (c2 != 0)); \
225}

◆ muladd_fast

#define muladd_fast ( a,
b )
Value:
{ \
uint64_t tl, th; \
{ \
secp256k1_u128_mul(&t, a, b); \
th = secp256k1_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \
tl = secp256k1_u128_to_u64(&t); \
} \
c0 += tl; /* overflow is handled on the next line */ \
th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \
c1 += th; /* never overflows by contract (verified in the next line) */ \
VERIFY_CHECK(c1 >= th); \
}

Add a*b to the number defined by (c0,c1). c1 must never overflow.

Definition at line 228 of file scalar_4x64_impl.h.

228#define muladd_fast(a,b) { \
229 uint64_t tl, th; \
230 { \
231 secp256k1_uint128 t; \
232 secp256k1_u128_mul(&t, a, b); \
233 th = secp256k1_u128_hi_u64(&t); /* at most 0xFFFFFFFFFFFFFFFE */ \
234 tl = secp256k1_u128_to_u64(&t); \
235 } \
236 c0 += tl; /* overflow is handled on the next line */ \
237 th += (c0 < tl); /* at most 0xFFFFFFFFFFFFFFFF */ \
238 c1 += th; /* never overflows by contract (verified in the next line) */ \
239 VERIFY_CHECK(c1 >= th); \
240}

◆ SECP256K1_N_0

#define SECP256K1_N_0   ((uint64_t)0xBFD25E8CD0364141ULL)

Definition at line 15 of file scalar_4x64_impl.h.

◆ SECP256K1_N_1

#define SECP256K1_N_1   ((uint64_t)0xBAAEDCE6AF48A03BULL)

Definition at line 16 of file scalar_4x64_impl.h.

◆ SECP256K1_N_2

#define SECP256K1_N_2   ((uint64_t)0xFFFFFFFFFFFFFFFEULL)

Definition at line 17 of file scalar_4x64_impl.h.

◆ SECP256K1_N_3

#define SECP256K1_N_3   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)

Definition at line 18 of file scalar_4x64_impl.h.

◆ SECP256K1_N_C_0

#define SECP256K1_N_C_0   (~SECP256K1_N_0 + 1)

Definition at line 21 of file scalar_4x64_impl.h.

◆ SECP256K1_N_C_1

#define SECP256K1_N_C_1   (~SECP256K1_N_1)

Definition at line 22 of file scalar_4x64_impl.h.

◆ SECP256K1_N_C_2

#define SECP256K1_N_C_2   (1)

Definition at line 23 of file scalar_4x64_impl.h.

◆ SECP256K1_N_H_0

#define SECP256K1_N_H_0   ((uint64_t)0xDFE92F46681B20A0ULL)

Definition at line 26 of file scalar_4x64_impl.h.

◆ SECP256K1_N_H_1

#define SECP256K1_N_H_1   ((uint64_t)0x5D576E7357A4501DULL)

Definition at line 27 of file scalar_4x64_impl.h.

◆ SECP256K1_N_H_2

#define SECP256K1_N_H_2   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)

Definition at line 28 of file scalar_4x64_impl.h.

◆ SECP256K1_N_H_3

#define SECP256K1_N_H_3   ((uint64_t)0x7FFFFFFFFFFFFFFFULL)

Definition at line 29 of file scalar_4x64_impl.h.

◆ sumadd

#define sumadd ( a)
Value:
{ \
unsigned int over; \
c0 += (a); /* overflow is handled on the next line */ \
over = (c0 < (a)); \
c1 += over; /* overflow is handled on the next line */ \
c2 += (c1 < over); /* never overflows by contract */ \
}

Add a to the number defined by (c0,c1,c2). c2 must never overflow.

Definition at line 243 of file scalar_4x64_impl.h.

243#define sumadd(a) { \
244 unsigned int over; \
245 c0 += (a); /* overflow is handled on the next line */ \
246 over = (c0 < (a)); \
247 c1 += over; /* overflow is handled on the next line */ \
248 c2 += (c1 < over); /* never overflows by contract */ \
249}

◆ sumadd_fast

#define sumadd_fast ( a)
Value:
{ \
c0 += (a); /* overflow is handled on the next line */ \
c1 += (c0 < (a)); /* never overflows by contract (verified the next line) */ \
VERIFY_CHECK((c1 != 0) | (c0 >= (a))); \
VERIFY_CHECK(c2 == 0); \
}

Add a to the number defined by (c0,c1). c1 must never overflow, c2 must be zero.

Definition at line 252 of file scalar_4x64_impl.h.

252#define sumadd_fast(a) { \
253 c0 += (a); /* overflow is handled on the next line */ \
254 c1 += (c0 < (a)); /* never overflows by contract (verified the next line) */ \
255 VERIFY_CHECK((c1 != 0) | (c0 >= (a))); \
256 VERIFY_CHECK(c2 == 0); \
257}