2

If there are 32 halvings, why is the if block in the GetBlockSubsidy function checking if there are equal or more than 64 halvings?

enter image description here

Murch
  • 75,206
  • 34
  • 186
  • 622
Efe
  • 407
  • 2
  • 16

1 Answers1

3

Variable nsubsidy is of type CAmount which is an int64.

As the comments say in the code you quoted, a 64-bit integer value can have no more than 64 bitwise right-shift operations meaningfully performed. So this is the limit applied.

It just happens that the initial subsidy 50 * COIN is a much smaller value that falls to zero only around 32 bitwise right shifts.

So the limit is based on the data type not the initial value. Regardless of the initial value, we know that the result must be zero after a 64-bit variable is right shifted 64 times.

A bitwise rightshift is a pretty cheap operation in CPU cycles so there's probably not much to be gained by optimising further here.

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51