I have a situation that I solved in the following way:
//cube_potentials is float8
//level_vec is float8
//shift_vec is int8 and contains (non-overlapping) bit shifts
int8 shifts = (cube_potentials<=level_vec);
int flag_index = 0;\n"
if (shifts.s0) flag_index |= shift_vec.s0;
if (shifts.s1) flag_index |= shift_vec.s1;
if (shifts.s2) flag_index |= shift_vec.s2;
if (shifts.s3) flag_index |= shift_vec.s3;
if (shifts.s4) flag_index |= shift_vec.s4;
if (shifts.s5) flag_index |= shift_vec.s5;
if (shifts.s6) flag_index |= shift_vec.s6;
if (shifts.s7) flag_index |= shift_vec.s7;
It works. The problem is all those if-statements irk me, and I can’t imagine they’re the fastest thing in the world, either. I wanted to solve it like so:
//Method 1
bool8 less = (bool8)(cube_potentials<=level_vec);
int8 shifts = (int8)(less) * shift_vec;
int flag_index = shifts.s0 | shifts.s1 | shifts.s2 | shifts.s3 | shifts.s4 | shifts.s5 | shifts.s6 | shifts.s7;
//Method 2 (more simply)
int8 shifts = ((int8)(cube_potentials<=level_vec)) * shift_vec;
int flag_index = shifts.s0 | shifts.s1 | shifts.s2 | shifts.s3 | shifts.s4 | shifts.s5 | shifts.s6 | shifts.s7;
The problem is that bool8 is a reserved type, not a real one, so method 1 is out. Method 2 doesn’t work correctly, though. I suspect the reason has to do with its first line. The <= is on two floating point vectors, and I don’t know what it returns, but presumably when it is cast to an int8 it isn’t all 0s and 1s.
My question is if there is any way to rewrite the original code in a cleaner, more parallel way?
Thanks,
Try this. It might work: