just make it in 4 separate if
afaik that's the only way
btw, in brook+ you need to specifiy output variable explicitly
and there is no return, all basic kernel in brook+ is void
kernel void kronecker_delta(unit i<>, unit j<>, out unit4 k<>
you do the rest
I should have mentioned the pseudo-code I included was a sub-kernel.
kernel uint4 kronecker_delta(uint4 i<>, uint j<>
int4 k_d = sign((int4) i - (int4)j);
return (uint4)(k_d * k_d);
I'm not sure how many instructions sign extends to, but you can try this:
return (uint4)((i != j) & (int4)1);
The first conditional should give each component that is equivalent a -1 and the rest 0. By anding with 1, the -1 becomes a 1 and the zero stays the same. This should be 2 instructions.
that's what I was looking for. I was so focused on the fact that conditionals only operate on the value of the first vector component that I ignored that the boolean operation would operate on all components and set a result for each. Your answer helped me focus on this more powerful approach. Thanks.
BTW, what you wrote doesnlt actually compile, you need to write
return (uint4)(((int4) i != (int4) j) & int4(1,1,1,1));
at least that's what I came up with to get rid of compile errors.