Skip to content

Commit

Permalink
Optimizing the fast square root further (needs to be tested with rega…
Browse files Browse the repository at this point in the history
…rds to precision though, to make sure it's not much worse?)
  • Loading branch information
hlabrand committed Aug 5, 2021
1 parent 3620f5b commit 368baa4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions inc/sh4_math.h
Expand Up @@ -527,9 +527,10 @@ static inline __attribute__((always_inline)) float MATH_Fast_Divide(float numera

// fast sqrt(x)
// Crazy thing: invert(fsrra(x)) is actually about 3x faster than fsqrt.
// HL: actually, sqrt(x) = 1/sqrt(x) * x, so we don't even need to invert
static inline __attribute__((always_inline)) float MATH_Fast_Sqrt(float x)
{
return MATH_Fast_Invert(MATH_fsrra(x));
return x*MATH_fsrra(x);
}

// Standard, accurate, and slow float divide. Use this if MATH_Fast_Divide() gives you issues.
Expand Down Expand Up @@ -2185,7 +2186,7 @@ static inline __attribute__((always_inline)) float MATH_Kaiser_Window(float x, f
x = normalizer * x;
y = normalizer * y;
z = normalizer * z;
magnitude = MATH_Fast_Invert(normalizer);
magnitude = temp*normalizer;
}
-- end -- */
Expand Down

2 comments on commit 368baa4

@ianmicheal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice :) Wish moop was here to see the update

@hlabrand
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) Me too! I might try to run some kind of test/benchmark one day, for speed and accuracy. Will update you here when I do if you want :)

Please sign in to comment.