Skip to content

Instantly share code, notes, and snippets.

@Kern--
Created May 20, 2014 19:17
Show Gist options
  • Select an option

  • Save Kern--/11ae7fbf99955f46863b to your computer and use it in GitHub Desktop.

Select an option

Save Kern--/11ae7fbf99955f46863b to your computer and use it in GitHub Desktop.
inline static s32 BITREV(s32 a) {
s32 ret;
asm __volatile__ ("bitrev %0, %1;" : "=r" (ret) : "r"(a));
return ret;
}
inline static s32 CLZ(s32 a) {
s32 ret;
asm __volatile__ ("clz %0, %1" : "=r"(ret) : "r" (a));
return ret;
}
inline static s32 lsbPosition(s32 a) {
return CLZ(BITREV(a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment