The article you linked is specifically talking about ARM's software floating point library. What platform are you running on where you need to use that? At least for the mainline Chipmunk branch I'd like to keep the algorithm I have as it's faster (at least on x86 and ARMs with hardware FPUs) and shorter than the previous and more branchy algorithm I had.
Going back in the thread I see you are talking about the iPhone specifically, but they all have hardware FPUs as do almost all Android devices now (certainly the ones good enough to run many games on). On both the iPod 4G and iPhone 3G I have on my desk, a divide by zero makes no measurable runtime difference to the following snippet:
- Code: Select all
NSLog(@"starting");
float x = 5.0;
float y = 0.0;
float z = 0.0;
for(int i=0; i<100000000; i++){
z = x/y;
}
NSLog(@"done");
Even running it with optimizations turned off couldn't be hiding that much of a performance hog. Running it in the profiler, loading x and y, and storing z show up 1000x more heavily than the division instruction, and the loop increment is 2x as expensive (a load hit store presumably?) as the whole z = x/y line.
