PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Floating/fixed point optimization

Hallo,

To improve the performance of Blender for PocketPC, I am thinking to convert some floating point operations in fixed point.

Of course, I cannot convert everything in Blender. So I will focus on a library making matrix/vector/scalar arithmetic. But I need to keep interfaces in floating point to be sure that there will be no problem with the Blender source code.
I can do for each function:
1) Convert input from floating to fixed point
2) Make the computation in fixed point
3) Convert output back from fixed point to floating point.

Do you think that there will be still an improvement even with these numerous conversions? Or do you think that there is a better approach way to make it?

Thanks for your help,
Salvatore
The conversion from floating to fixed point requires a floating point operation, plus another to convert it back. So unless you are replacing more than two operations you won't see a performance gain.

Dan East
You don't need to use a floating point operation to do the conversion to/from fixed point. It can be done with some shifts, masks, and integer subtraction.

I wrote something to do this over a year ago. If you like I can try to locate the code for you. I came up with this on my own by looking at the IEEE 754 format, but I'm sure it's on the web somewhere.
Thanks!

for the moment, I am just thinking about that... in Blender, there is a library called Moto making all vector, matrix calculation... In 3D, lot of matrix/vector operation are used.

The problem converting it in fixed point is that there can be so many conversion operations that at the end, it is slower... If for each 4*4 matrix, I need 16 + 16 conversion, it can be a lot!

But I have to try and see. Does someone know for example how fast is a fixed point multiplication or division in comparaison with the floating point equivalent? It is 10 times faster? 100 X? 1000 X? Because if it is only 2 or 3X faster, there will probably be no improvemnt...

Thanks Digby, of course I am interested, at least to see your approach.

Salvatore
I would say between 10x and 20x.
This weekend I ran some benchmarks measuring the performance of multiplying a large array of 4D vectors by a 4x4 matrix on a HP RX1955 Pocket PC. The function that I measured looks like this:

void transform(vector4 *pOut, vector4 *pIn, matrix *pM, long vectors)


Using fixed point vectors and a fixed point matrix, it was 12 times faster than using all floating point data and math operations.

In an attempt at using the approach that you would take it was ~2.3 times faster than the all floating point method. (The function accepts floating point vectors and a floating point matrix, but internally it converts the floating point matrix to fixed point (once), and converted each vector to fixed point, performed the four dot products, then converted the result back to floating point, inside the loop)

Using your approach along with bit manipulation float-to-fixed/fixed-to-float conversion routines sped things up slightly so that it was 5 times faster than the all floating point method.

I hope this information helps with your optimization strategy, but I'd strongly advise that you profile this app and determine if mucking around with floating point operations like this would be worth the trouble of having to worry about fixed point overflow/underflow issues.
Thanks Digby for these precious informations.

Given my knowledge and the complexity of the Blender code, it would not be serious that I begin to convert it in Fixed Point. I will have no chance to succeed. The only chance I have is to keep the changes local to 1 or 2 math libraries keeping the interfaces as they are.

Following your tests, it seems that the operations will be 5* faster. That's quite good :=) But then, as you mentioned, I really have to be sure that the fixed point approximation will not make big problems... As soon as I will more time for that, I will just try and see! I will also try to have from the Blender Team more information about the part of the code that really should be optimized.

Thank you for your information,
Salvatore
Salvatore,

have you tried using the Intel compiler instead of Microsoft's? There is a free 30-day eval version you can use if you don't have it. Supposedly its float performance is much better than that of the regular eVC compiler. You can also search this forum.

- HM
hm wrote:have you tried using the Intel compiler instead of Microsoft's? There is a free 30-day eval version you can use if you don't have it. Supposedly its float performance is much better than that of the regular eVC compiler.


It's also a very strange one.

1. Apps, compiled with intel don't work on samsung CPUs. Probably they did it on purpose, but doesn't matter.

2. Although it's pretty fast, it has a very strange unpredictable behavior sometimes. At least my game didn't work entirely proper - some images wasn't loaded, other blits with modulus were incorrect, and such stuff.
Thanks Hans-Martin for this advise. I could give a try later on when I will consider the fixe point optimization. As soon as I will move on the Blender Game Engine (not in the near future), this optimization will be indispensible (I think)

Salvatore