cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

afo
Adept I

Extending bit in OpenCL

It is possible to extend a bit in OpenCL?

Hi,

Maybe it is a stupid question, if so, please apologize me.

I have an unsigned int value that can be 0x00000000 or 0x00000001 at run time; could be posible to extend the LSB bit to have 0x00000000 or 0xFFFFFFFF at run time?

Thanks in advance for any insight on this.

best regards,

Alfonso

0 Likes
12 Replies
kbrafford
Adept II

Can you just multiply by 0xFFFFFFFF?

0 Likes

thanks!

I was pretty sure that it was a stupid question, but today is not my most creative day.

best regards,

Alfonso

0 Likes

Since the GPU does 24 bit integer math better than 32 bit integer math (as far as using all of the ALUs), there may be a better way to do that.  Can anyone chime in with something that would work on int4's?

0 Likes

24 bits operations aren't supported now.

The best method for your problem ( and much more flexible ) is to use select function ( which I guess is translated into IL cmov operation ).

result = select( v, 0xFFF...., 0 );

 

 

0 Likes

I thought select looked at the MSB.

0 Likes

According to opencl specs for scalar type select <=> v?a:b

But to tell you the truth the best way is to use something which is compiled into cmov_logical in IL code. It might be select but maybe simply v?0xFFFF...:0x0 would do the work. I'm not sure how efficient opencl compiler is in this regard so someone must check it.

cmov_logical can be assigned to any slot so it's much more efficient than using imul ( only t slot ).

 

0 Likes

I am amazed that noone has said this but...

a = 0x00000001

b = -a

then b = 0xffffffff

 

Malcolm

0 Likes

How is multiplying by -1 different from multiplying by 0xFFFFFFFF?

0 Likes

The difference between those two approaches is that -1 will set all bits for the integer that it is assigned to before the multiplication. 0xFFFFFFFF will only set all bits when it is assigned to an integer that is 32bits or smaller. At a bit level, (int32_t)-1 and 0xFFFFFFFF are equivalent.
0 Likes

So that means that a mult by (-1,-1,-1,-1) will be the correct way to do it once 24 bit int vectors are supported?

0 Likes

kbrafford,
using select would be more efficient on a larger number of compute devices as not all compute devices support 24bit multiply.
0 Likes

Do be careful with select. As alluded to in this thread, the definition of truth for a scalar select is different for the definition for a vector select (because truth is different for scalars and elements of vectors).

0 Likes