optimization question + equation library?

Started by
3 comments, last by Charles B 19 years, 9 months ago
Is there a way to optimize the distance equation in C to get it faster than this: d = sqrt(x*x + y*y + z*z); //3d loss in accuracy is acceptable, to a degree, if the speed gain is substantial. Also, does there exist an open source math/physics C library that covers a wide array of math/physics equations? For example, one that covers collisions of all sorts, distance finding (between points, along equations, etc), and a lot of the math/physics questions we see in this forum?
Advertisement
Actually, I have a similar question: does anyone know a good "language" for user-supplied equation parsing and solving? I used a Python interpreter for an app, but it involved an absolutely monstrous amount of events. 90% of the events were simple arithmetic like "return (mouseX * mousespeed)" and simple things like that, events we wanted developers to have access to without recompiling, but at the same time were way too numerous. THere is substantial overhead involved in converting the argumetns to PyObjects, fetching the function, launching the function with the arguments, and returning the results. Even worse, we were using the functions as a flat file instead of a PyFunction object, so the pycode object had to be launched with the arguments in the namespace dictionary instead of the argument tuple, meaning the interpreter was using hashing to fetch the arguments instead of tuple index lookups.

In other words: Python too slow and heavy for user-defined arithmetic. Want fast embedding "language" for running user-defined equations with engine-supplied variables int a program.
-- Single player is masturbation.
check out this thread:
carmacks sqrt
also lookup 3dnow&sse versions of the sqrt function.
You may not even need to do the square root at all. For example, if you use it to compare two distances, you can leave them both squared.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Exact Raloth. In my experience, the only significant (time consumming) cases where sqrt or rsqrt are actually required are for normalization of vectors, that is, in practice, recomputing normals in RT (ex : deformable mesh) for lighting. It's rarely required for collision detection or culling.

Else, as mentionned the rsqrt topic has been discussed a lot here.

Also always give your context of use. Generic optimizations mean nearly nothing unless you write a math library like me. There is always a context to exploit. The more additionnal info, the more opportunities to optimize. If you process an array of vectors with some continuity of norm, a very speedy normalization is possible using a variant of NR.
"Coding math tricks in asm is more fun than Java"

This topic is closed to new replies.

Advertisement