Skip to content

Commit

Permalink
Update machine_multiplicator.py: branchless
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus authored Feb 12, 2024
1 parent 3622869 commit 7455c73
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions machine_multiplicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

product = 0
for i in range(0, bits):
if (multiplier & 1) == 1:
product = product + multiplicand
multiplicand = multiplicand << 1
multiplier = multiplier >> 1
product += multiplicand * (multiplier & 1)
multiplicand <<= 1
multiplier >>= 1
print(i, multiplicand, multiplier, product)

print("Result: ", product)

0 comments on commit 7455c73

Please sign in to comment.