Page 3 of 3

Re: Division on Zero

Posted: Wed Feb 15, 2012 2:15 am
by ShiftZ
Would you fixed it?

Re: Division on Zero

Posted: Wed Feb 15, 2012 10:25 am
by slembcke
I could, but why? Are you not running somewhere that offers IEEE floating point compatibility? Chipmunk already uses infinities extensively, I don't understand why this instance is an issue. It works fine on pretty much every reasonable platform I've tested it on from PPC to ARM to x86.

Re: Division on Zero

Posted: Wed Feb 15, 2012 10:50 am
by ShiftZ
I could, but why?
We had discussid it already in this thread. Division by zero is not intended to perform in a real time simulations. It stalls CPU so terrible, even single division by zero per frame results in noticeable freezes. Other then that, it's ok.
This thread would not exist if there was no reason to avoid div by zero.

http://infocenter.arm.com/help/index.js ... a4061.html

Just read first three rows.
Probably you could read this thead from start to remind things.

Re: Division on Zero

Posted: Wed Feb 15, 2012 11:52 am
by slembcke
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.

Image

Re: Division on Zero

Posted: Thu Feb 16, 2012 12:03 am
by ShiftZ
Well, if you target specificaly on iPhone platform, perhaps you are right.