Fast reciprocal square root algorithm

Click For Summary
SUMMARY

The forum discussion centers on the fast reciprocal square root algorithm, specifically the implementation used in Quake III, popularized by John Carmack. The algorithm significantly outperforms the standard C library function for calculating the reciprocal square root, achieving results within 1% accuracy while executing over one hundred times faster. The code provided demonstrates a clever use of bit manipulation and Newton's method for approximation. Additionally, the discussion touches on modern variations and optimizations, including Intel's AVX instructions for further performance enhancements.

PREREQUISITES
  • Understanding of C programming and floating-point arithmetic
  • Familiarity with Newton's method for numerical approximations
  • Knowledge of assembly language for performance measurement
  • Experience with optimization techniques in software development
NEXT STEPS
  • Research Intel AVX (Advanced Vector eXtensions) instructions for optimizing mathematical computations
  • Explore modern modifications to the fast inverse square root algorithm
  • Learn about the CORDIC algorithm for efficient trigonometric calculations
  • Investigate the performance characteristics of different numerical libraries, such as Python's math module
USEFUL FOR

Software developers, game programmers, and performance engineers interested in optimizing mathematical computations and understanding advanced algorithms for numerical methods.

  • #31
I quoted Fröberg since it was on the required list for my Numerical Algorithms exam back in 1964. After I referred to it, I started to get very unsure of the validity of the algorithm - and, sure enough, it converges badly for a starting value of 1 if a is greater than 1. I have checked and found that the best way is to modify the start value according to this algorithm;
Code:
Start with x0=2
if a>1
   repeat
      x0=x0/2
      t=(3-x0*x0*a)
   until (t<2) and (t>0)
Then use the Fröberg algorithm with the resulting x0.
 
Last edited:
  • Like
Likes   Reactions: Baluncore

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
22
Views
5K
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
11
Views
4K
  • · Replies 13 ·
Replies
13
Views
6K