news.volyx.in

The radix 2^51 trick (2017) (chosenplaintext.ca)

431 points by blobcode · 427 days ago · 82 comments on HN

Article summary

The article discusses a technique called the radix 2^51 trick, which can speed up addition and subtraction of large integers on modern CPUs. This trick involves splitting 256-bit numbers into five 51-bit pieces, allowing for more efficient addition and subtraction without the need for carry propagation. The technique can be used to improve the performance of big integer arithmetic. By delaying carry propagation, the radix 2^51 trick can reduce the number of instructions needed and increase parallelism.

Main themes

  • radix 2^51 trick
  • big integer arithmetic
  • CPU optimization
  • carry propagation
  • RISC-V architecture
  • side-channel risks
  • compiler optimizations

What commenters say

  • Some commenters argue that using 64 bits for the top limb and 48 bits for the other limbs could be a better approach, allowing for more additions before overflow.
  • Others counter that this approach would require more instructions and may not be beneficial for all use cases.
  • The optimization technique described in the article is considered legal for a C++ compiler to implement, as it does not change the observable behavior of the program.
  • There are concerns that introducing optimizations like this could potentially create side channels, especially in cryptographic code.
  • Some argue that RISC-V's omission of the carry flag is a good design choice, and that the radix 2^51 trick demonstrates a way to work around this limitation.
  • Others propose alternative implementations, such as using conditional moves instead of branches, but these may introduce new dependencies and complexities.
  • The use of conditional branches in cryptographic code is considered a potential side-channel risk, and alternative approaches like using bitwise operations may be preferred.