Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
862 views
in Technique[技术] by (71.8m points)

algorithm - efficient way to divide a very large number stored in 2 registers by a constant

Let's say I want to calculate the following:

A/Z

Where A is of length 128 bit and Z is 64 bit long. A is stored in 2 64 bit registers since the registers of the system can store up to 64 bits. What would be an efficient way to calculate the result?

P.S: I've solved similar multiplication problems by using CSD representations. However, this would require calculating 1/Z first.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The right way to solve such a problem, is by returning to the basics:

  • divide the most significant register by the denominator
  • calculate the quotient Q and the rest R
  • define a new temporary register preferrably with the same length as the other 2
  • the rest should occupy the most significant bits in the temporary register
  • shift the lesser significant register to the right by the same amount of bits contained iR and add to the result to the temporary register.
  • go back to step 1

after the division, the resulting rest must be casted to double, divided by the denominator then added to the quotient.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...