PDA

View Full Version : qwords and O3-Optimization levels..


bhavanvaishnav
27-Mar-2008, 14:03
Hi,

I was trying out different compiler optimizations and have a few queries regarding the same..
I tried running a simple spulet and checked out the generated assembly..with 03 on..

1> int z=10
printf ("\n %d",z);
this just loads an rValue il $2,10 instead of loading it off the $sp..so this does not require any rotates and shifts..since its an immediate value..

2> so its good to use qwords for scalars (because this eliminates rotates and shifts)..but if O3 does this for me..what advantage do i gain defining them as qwords?..

3>Actually the question here is more general..this might sound bad..but do i prefer qwords for vectors as well..cos i have been going through some of the 'homework 3' code (on the insomniac r&d website) and i could not see any vectors used there..so i assume i can complete SIMD operations defining things as qwords..am i right?..or that code wasnt SIMDized or SIMDizable..

4> And i would really appreciate it if someone explained where i can apply qwords instead of the obvious data types..

5> This website rocks..(n the insomniac one)..

Thanks..

deathkrush
27-Mar-2008, 18:24
1> int z=10
printf ("\n %d",z);
this just loads an rValue il $2,10 instead of loading it off the $sp..so this does not require any rotates and shifts..since its an immediate value..


That's right, at higher optimization levels the compiler will get rid of rotates and shifts as much as possible.


2> so its good to use qwords for scalars (because this eliminates rotates and shifts)..but if O3 does this for me..what advantage do i gain defining them as qwords?..


The advantage is that by defining everything as qword you are forced to use SPU intrinsics, so you'll be writing code at the assembly level. The disadvantage is that you'll be writing code at the assembly level.


3>Actually the question here is more general..this might sound bad..but do i prefer qwords for vectors as well..cos i have been going through some of the 'homework 3' code (on the insomniac r&d website) and i could not see any vectors used there..so i assume i can complete SIMD operations defining things as qwords..am i right?..or that code wasnt SIMDized or SIMDizable..


qword is basically an opaque SIMD vector type. You have to use "si_" intrinsics to manipulate the qword type. Insomniac doesn't like using vector types such as "vector unsigned int" because they think that "spu_" series of intrinsics are too "high level". I disagree and think that "spu_" intrinsics are much more elegant than "si_" intrinsics and they accomplish the same thing, but that's just my opinion.


4> And i would really appreciate it if someone explained where i can apply qwords instead of the obvious data types..


Sure, you just have to know SPU assembly instructions. Each operation on qword has the following form:

qword result = si_ [name of assembly instruction] (operand0, operand1);

For example, to add two qwords that represent 4 unsigned integers, do this:

qword a = (qword)(vector unsigned int){0, 1, 2, 3};
qword b = (qword)(vector unsigned int){4, 5, 6, 7};
qword sum = si_a(a, b);


5> This website rocks..(n the insomniac one)..


I agree.