www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - objects and vectorization

Hi

Yesterday I where thinking on how to expand vectorization to objects 
and structs.
 
I think that the fundamental problem with get optimal performance 
in this calculations is the way objects and struct is ordered in memory.

Take this struct 
struct foo
{ 
  float one, two, three, four, five;
}

An array of this is ordered in memory as
|one|two|three|four|five|
|one|two|three|four|five|
...

So to make a vectorized calculation on the struct 
which only use field one and four.

The program can do two things
1) swap in the whole structure into the cache make the calculation
and swap it out again. This wast cache space for field two, three and five.

2) Only swap in the fields one and four, but the it will use time make all
lot of small copies.

So, maybe it could be an advantage to store arrays of struct and objetcs
as:

|one|one|one| ...
|two|two|two| ...
|three|three| ...
|four|four| ...
|five|five| ...

In this way the processor could get the exact data it needs very fast.

So, maybe one should be able to vectorize an array of structs/objects like:

vectorize foo[5000] foovec;


Disclaimer: I don't know anything about writing machine code on the 
new processes. So, this posting might be very far from reality.




 
Jul 08 2005