Skip to content

Instantly share code, notes, and snippets.

@Kentzo
Created March 13, 2011 17:26
Show Gist options
  • Select an option

  • Save Kentzo/868275 to your computer and use it in GitHub Desktop.

Select an option

Save Kentzo/868275 to your computer and use it in GitHub Desktop.
Right shift for int4
__device__ int4 right_shift_int4(int4 a_value, unsigned int a_num)
{
int x_h = a_value.x >> (a_num % 32);
int x_l = a_value.x << (32 - (a_num %32));
int y_h = a_value.y >> (a_num % 32);
int y_l = a_value.y << (32 - (a_num % 32));
int z_h = a_value.z >> (a_num % 32);
int z_l = a_value.z << (32 - (a_num % 32));
int w_h = a_value.w >> (a_num % 32);
int tmp[8] = {0};
tmp[4] = x_h;
tmp[5] = x_l | y_h;
tmp[6] = y_l | z_h;
tmp[7] = z_l | w_h;
unsigned int offset = a_num / 32;
return make_int4(tmp[4 - offset], tmp[5 - offset], tmp[6 - offset], tmp[7 - offset]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment