data types and functions for vector optimization?

Hi,

I am playing around with altivec, and I found it rather difficult to change the radiance code. This is split up into very small functions, and the data types mainly seam to rely on arrays (I looked into mat4 as Georg Mischler once proposed). As the overhead to make a vector from an array is so awful that the speed-up e.g. in the following transformation of the matrix is used up, and changing the basic data types (e.g. from array to union of array and vector) would make me check all the source files for use of these types, I guess the cpp approach of radzilla might be much easier to use. Basically, I would like to do something like replacing the basic types for vectors etc. by altivec vectors, keeping their (public) interface intact and hoping that there is no direct access to the underlying data members. Now I wonder if radzilla code is written in a way that will allow so (no direct access to data members, but only over function calls) and what those more familiar with the code would suggest to start with. In the end, I think this might be a nice start to speed-up some code parts for the more and more popular vector engines that arrive on every platform.

Thanks + CU Lars.

Hi Lars,

radzilla already contains something roughly similar to your description. I started replacing the original vector manipulation macros with a 3-element vector template. BTW, of course there are already vector(template) classes in the standard C++ library (they're called vector and 'valarray' or sth. like that.), but writing something on my own was part of the learning story and also resulted in a much smaller thing, in contrast to the stuff from the standard C++ library which is really blown up, providing tons of functions not needed in our case.
I especially did this to play around with the C++ feature of definable operators, which makes corresponding code much more concise.
With the vector template, typical actions like addition, multiplication with a scalar factot or the dot product can now be simply written as follows:
VEC<float> vec1;
VEC<float> vec2;
float mult;

float dot = vec1 * vec2; // dot product
vec1 = vec2 * mult; // scalar multiplication

and so on..
In fact, these operator definitions are nothing else than usual member functions, but just the calling syntax is different.A great portion of the used vector manipulations now consists of these operator calls, some few however are still written in terms of C++ member functions (e.g.
float d = vec1.normalize();
So taken the case that you can principally use this operator notation also with your altivec classes, this simple selfmade vector template might indeed be a good starting point.

Apart from that, another problem is that I only started implementing this stuff, by far not every classic Radiance vector macro is already replaced with the corresponding vector template . So there is still a lot conversion work to do, also. To get a feeling how this vector template works, have a look at base/vec.h and e.g img/view.C, (e.g. the function viewray(..) ) or the code of the new source partitioning scheme, which also uses the new vector notation. (lite/source.C, source1,source2.C) Occasionally, you will also find the necessary conversions between the new and old version. (To make a vector work with the old macros it needs of course that unwanted direct access to the data members.)

-Carsten

···

--
---------------------------------------------------------

"Der Deckel muß zugehen." (P.Kölsch)

---------------------------------------------------------