Skip to content

Commit

Permalink
Merge bitcoin-core/secp256k1#1336: Use __shiftright128 intrinsic in…
Browse files Browse the repository at this point in the history
… `secp256k1_u128_rshift` on MSVC

5b7bf2e Use `__shiftright128` intrinsic in `secp256k1_u128_rshift` on MSVC (Hennadii Stepanov)

Pull request description:

  Closes bitcoin-core/secp256k1#1324.

  As the `__shiftright128` [docs](https://learn.microsoft.com/en-us/cpp/intrinsics/shiftright128) state:
  > The `Shift` value is always modulo 64...

  it is not applicable for the `n >= 64` branch.

ACKs for top commit:
  sipa:
    utACK 5b7bf2e
  real-or-random:
    ACK 5b7bf2e tested with MSVC x64

Tree-SHA512: bc4c245a9da83c783a0479e751a4bc2ec77a34b99189fcc4431033a5420c93b610f3b960d3f23c15bce2eb010beba665b3e84d468b3fdab3d5846d4f27016898
  • Loading branch information
real-or-random committed Jun 24, 2023
2 parents 3c1a0fd + 5b7bf2e commit 1083683
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/int128_struct_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigne
r->lo = r->hi >> (n-64);
r->hi = 0;
} else if (n > 0) {
#if defined(_MSC_VER) && defined(_M_X64)
VERIFY_CHECK(n < 64);
r->lo = __shiftright128(r->lo, r->hi, n);
#else
r->lo = ((1U * r->hi) << (64-n)) | r->lo >> n;
#endif
r->hi >>= n;
}
}
Expand Down

0 comments on commit 1083683

Please sign in to comment.