[Bf-committers] optimising the code

Jean-Luc Peurière bf-committers@blender.org
Sat, 29 May 2004 17:27:41 +0200

Le 29 mai 04, à 01:00, Jean-Luc Peurière a écrit :

> I had the curiosity of using a profiler and code analyser (shark on Os =

> X) on blender application.

> By changing a few lines in *ONE* function I was able to get a 11% 
> speed-up of rendering time !

> * floor --> floorf
> * constant of the correct type (float)
> * spliting 3 variables in int and float versions
> Now I would be interrest to know if theses simple changes have the 
> same drastic effect on other plaforms ?

We had a very interesting discussion about this optimisation thing on 
IRC with Ton, LarstiQ, Jesterking and Desoto.

- It appears that Blender was moved from float to double math for Intel 
support on linux reasons around 2000.
- C99 standard define float math but not all compilers implement it 
- some compilers, while supporting float math have different naming or 
ressort to a special library
- Ton quotes :  we can make a bfloat.h with platform #ifdefs mapping 
float calls to double ones,
                            i wont mind introducing rule that all *f 
calls can be used, but only with a bfloat.h include to allow some 
platforms to patch it
- optimising like this dont infer on portability, and do not have the 
drawback of using platform specific code like SSE, altivec or assembly.
- It still allow to do a reduced set of routines in platform specific 
code like SSE or altivec.

the functions available in C99 are :

float acosf(float)
float asinf(float)
float atanf(float)
float atan2f(float, float)
float cosf(float)
float sinf(float)
float tanf(float)
float coshf(float)
float sinhf(float)
float tanhf(float)
float expf(float)
float frexpf(float, int *)
float ldexpf(float, int )
float logf(float)
float log10f(float)
float modff(float, float *)
float powf(float, float)
float sqrtf(float)
float ceilf(float)
float fabsf(float)
float floorf(float)
float fmodf(float, float)

The first thing to know is what is the status of these functions on 
supported platforms (this must be done for each compiler and version 

I'm then willing to pass some time analysing the code and modifying 
where needed. To do that efficiently, I will need .blend files each 
testing deeply a very reduced set of routines (procedurals func, UV's, 
and all render aspects). the goal is 2' render time on my comp (G4 867 
Mhz) to have enough profiling samples. If someone else could provide 
this, that would help speeding up things.

Jean-luc (lukep)