Skip to content

Commit

Permalink
moved u128+u128 to int128.h
Browse files Browse the repository at this point in the history
  • Loading branch information
dderjoel committed Jul 27, 2023
1 parent 7c67d34 commit 21e95b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
19 changes: 1 addition & 18 deletions src/field_5x52_int128_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,9 @@ static FIAT_SECP256K1_DETTMAN_FIAT_INLINE uint64_t u64_and_u128_u64(secp256k1_ui
}

static FIAT_SECP256K1_DETTMAN_FIAT_INLINE secp256k1_uint128 u128_add_u128_u128(secp256k1_uint128 a, secp256k1_uint128 b) {
uint64_t bl;
uint64_t bh;
uint64_t rh;
uint64_t rl;
secp256k1_uint128 r = a;

bl = secp256k1_u128_to_u64(&b);

/* adding low b to r*/
secp256k1_u128_accum_u64(&r, bl);

rl = secp256k1_u128_to_u64(&r);
rh = secp256k1_u128_hi_u64(&r);

/* adding high b*/
bh = secp256k1_u128_hi_u64(&b);
rh += bh;

/* saving all in r*/
secp256k1_u128_load(&r, rh, rl);
secp256k1_u128_accum(&r, &b);

return r;
}
Expand Down
5 changes: 5 additions & 0 deletions src/int128.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint
*/
static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint64_t a);

/* Add an unsigned 128-bit value a to r.
* The final result is taken modulo 2^128.
*/
static SECP256K1_INLINE void secp256k1_u128_accum(secp256k1_uint128 *r, secp256k1_uint128 *a);

/* Unsigned (logical) right shift.
* Non-constant time in n.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/int128_native_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint
*r += a;
}

static SECP256K1_INLINE void secp256k1_u128_accum(secp256k1_uint128 *r, secp256k1_uint128 *a){
*r += *a;
}

static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n) {
VERIFY_CHECK(n < 128);
*r >>= n;
Expand Down
5 changes: 5 additions & 0 deletions src/int128_struct_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint
r->hi += r->lo < a;
}

static SECP256K1_INLINE void secp256k1_u128_accum(secp256k1_uint128 *r, secp256k1_uint128 *a){
r->lo += a->lo;
r->hi += r->lo < a->lo + a->hi;
}

/* Unsigned (logical) right shift.
* Non-constant time in n.
*/
Expand Down

0 comments on commit 21e95b4

Please sign in to comment.