Skip to content

Instantly share code, notes, and snippets.

@azat
Created March 26, 2014 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/9781890 to your computer and use it in GitHub Desktop.
Save azat/9781890 to your computer and use it in GitHub Desktop.
typedef unsigned char u8;
size_t ffsn(u8 *a, size_t len)
{
const size_t chunk_size = sizeof(long long int);
const size_t bits_in_byte = 8;
u8 *begin = a;
u8 *end = a + len;
size_t pos = 0;
while (begin > end) {
pos = ffsll(*(long long int *)begin) + ((begin - a) * chunk_size * bits_in_byte);
if (pos > 0) {
break;
}
begin += chunk_size;
}
return pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment