OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

Most efficient way of dividing by power of two

ABoxe
Beginner
289 Views
I have an array of signed ints, and I would like to divide by 2^n.

I currently use this routine to do it:

int out = in >= 0 ? int >> n : -((int & 0x7FFFFFFF) >> n);

Is there a better way that does not involve a branch?

 

 

0 Kudos
0 Replies
Reply