Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
just paste it into Compiler Explorer, clang 6.0
void fancierRotate2(unsigned int *arr, const bool *control, int count, int rot0, int rot1)
{
for (int i = 0; i < count; ++i)
{
int rot = control[i] ? rot1 : rot0;
arr[i] = (arr[i] << (rot & 31)) | (arr[i] >> (-rot & 31));
}
}
@NTimmons
Copy link

void fancierRotate2(unsigned int *arr, const bool *control, int count, int rot0, int rot1)
{
for (int i = 0; i < count; ++i)
{
int rot = control[i] ? rot1 : rot0;
arr[i] = (arr[i] << (rot & 31)) | (arr[i] >> (-rot & 31));
}
}

static void fanRotate(benchmark::State& state)
{
// Code before the loop is not measured
std::string x = "hello";
unsigned int count = 20;
unsigned int* arr = new unsigned int[count];
bool* control = new bool[count];
int rot0 = 11;
int rot1 = 22;

for (auto _ : state)
{
fancierRotate2(arr, control, count, rot0, rot1);
}
}
BENCHMARK(fanRotate);

^ Google bench code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment