Fixed math farseer

Topics: Developer Forum, Project Management Forum, User Forum
Oct 5, 2009 at 1:16 PM

Hey everyone I was just wondering about something and wanted to know peoples thoughts and ideas on it (that may understand it more than me)

I was talking to some of my friends yesterday and the subject came up about how the Xbox has floating point support that is about 10-20 times slower than a pc per clock... but integer and long math is only about 2 times slower per clock. Also the Zune can only do integer based math "practically".

Well I was wondering can physics engines use integer math?
I have heard that fixed point math can be much more accurate than floating point math and also much much faster, I have also heard that it is determinable (that is I mean its math is always guaranteed to produce the same result) wouldn’t this also make it much more suited for network and synchronised things?

If everything above was true however that could mean a physics engine that is:

1, Faster on PC's.
2, Much much faster on 360.
3, Useable on the new Zune HD.
4, Predictable (useable on network programs then)
5, More accurate?

Anyway I just wanted to know if a fixed point farseer was possible or even desirable because I don’t really know.
If anyone could get back to me that would be great.

Also: Farseer 3.0 is looking great.

Coordinator
Oct 5, 2009 at 2:08 PM

I was sure that I wrote about fixed point math on my blog! I simply can't find it (only a short description)...

Anyway, wait a bit and I will write a post about fixed point math. Can I use your post as reference?

Oct 5, 2009 at 3:07 PM

Yer sure thats fine. I would love to hear what you have to say about it all and if any of the points I made are correct.

Coordinator
Oct 6, 2009 at 1:37 AM

The post is up. I tried answering your questions with high abstractions. I would rather give you the information so that you can come to your own conclusion instead of forcing my views on you.

To give you might view on each of your statements:

1. It might not be faster. It is hard to say what is faster: fixed point math or floating point. It really depends on the application in which it is used. Simple algorithms might benefit a lot from fixed point math, but more advanced algorithms can benefit more from floating point. I'm talking performance only here.

2. Indeed. The Xbox 360 could benefit a lot from fixed point - problem is that it is not easy to create a transparent solution that works with both fixed and floating point math. I will make some performance tests in the future and try to create a transparent solution and post my results.

3. Same as Xbox 360. The floating point performance on Zune HD is really low and it could benefit a lot from fixed point math.

4. Indeed. Having no inconsistencies across platforms in the calculations is a huge improvement over floating point. There are a lot of things to consider when using floats: rounding methods, accuracy and implementations (and instruction sets). Fixed point guarantees you a deterministic simulation.

5. As point number 4, you have more consistent accuracy using fixed point. You will suffer from lower range of values if you use 32bit integers only. I've seen space games that hit the roof quite fast and overflowed. There were better off using 64bit integers or floating point.

---

As for Farseer Physics and fixed point. I've considered creating a fixed point version of Farseer Physics 3.0 and test it out. There are a lot of algorithms that needs to be rebuild using fixed point, but that is a one-time job only. Paul sent me a great fixed point math implementation in C# some time ago. Once 3.0 is up and running I will include it and test it out.

Oct 6, 2009 at 3:38 AM

Great article. Very informative, I have heard that if the XNA on the 360 had AltiVec instruction set it would be much much faster, I wonder if they will ever impliment this...

A fixed point math implimention of farseer would be quite good by the sounds of it.
Would using longs still provide a performace benifit on 360? Or wouldnt a physics engine need 64bit ints? and would be fine with 32bit ints?

I would love to try a fixed point of farseer 3.0 sometime.

I have used the original zune before and my god floating point perfomance is bad on it. about 100* slower than ints or doubles.
It would great to have a portable physics library (By portable I mean one that works on portable machines like zunes and windows mobile devices)

Anyway thanks for the great response.

Coordinator
Oct 6, 2009 at 11:53 AM

Glad you liked it.

I would think that the NetCF team is thinking about implementing the AltiVec instruction. The floating point performance area is one of their main concerns (since it is a gaming platform and they mainly use float) and I hope they improve performance using hardware as much as they can.

Longs are 64bit integers and on 32bit machines (or if the application is compiled using 32bit) it requires two operations on each long instead of one (to process it). Depending on the application, the overhead of longs might be a bottleneck compared to what you originally had. However, I do think an application like Farseer Physics Engine could benefit from fixed point math and it might even run faster with 64bit fixed point instead of 32bit floating point.

Working with C# and .net makes it easy to make the application portable. iPhone, Zune (and HD) and similar devices that can run .net should indeed have an easy to use physics engine that performs well. I do have some ideas on how to implement 3.0 so that I will run great on embedded devices. More info on this will come later.

Feb 2, 2012 at 8:02 AM

Hi, I know I am unearthing ancient history with this replay, but I would really like to know if anyone put any effort into fixed math farseer?

tnx

grega_g