Caculating 1/d if you have multiply

  • Thread starter Thread starter rcgldr
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on calculating the reciprocal of a number (1/D) using assembly code, specifically through an integer multiplication method that involves 32-bit by 32-bit multiplication yielding a 64-bit result. The algorithm utilizes an unsigned approach and begins with an initial estimated quotient derived from a table with 8 bits of precision. The iterative formula q_{n+1} = q_n (2 - q_n X) is employed, requiring only 4 to 5 iterations to achieve 32 bits of precision. The conversation raises the question of whether superior algorithms exist for this calculation.

PREREQUISITES
  • Understanding of assembly language programming
  • Familiarity with integer multiplication techniques
  • Knowledge of fixed-point arithmetic
  • Basic grasp of iterative algorithms and convergence
NEXT STEPS
  • Research assembly language optimization techniques for integer operations
  • Explore fixed-point arithmetic in depth
  • Investigate alternative algorithms for calculating reciprocals, such as Newton-Raphson
  • Learn about precision management in numerical computations
USEFUL FOR

Assembly language programmers, systems developers, and anyone involved in low-level numerical computation optimization.

rcgldr
Homework Helper
Messages
8,948
Reaction score
687
This will be done in assembly code, using an integer multiply, 32 bit by 32 bit producing 64 bit result. Unsigned algorithm is good enough.


Generic algorithm to find 1 / D, eq is initial estimated quotient, from table, say with 8 bits of precision.

[tex]q_0\ =\ eq[/tex]

[tex]q_{n+1}\ =\ q_n\ (2\ -\ q_n\ X)[/tex]

For integer math, pre and post shifting of values will be done. Generally only 4 or 5 interations are required to get 32 bits of precision.

Are there better algorithms?
 
Last edited:

Similar threads

  • · Replies 30 ·
2
Replies
30
Views
8K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
Replies
7
Views
15K