Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created December 6, 2011 23:36
Show Gist options
  • Save rygorous/1440600 to your computer and use it in GitHub Desktop.
Save rygorous/1440600 to your computer and use it in GitHub Desktop.
PPC rlwinm/rlwimi equivalent C code
static inline U32 ppcmask(U32 mb, U32 me)
{
U32 maskmb = ~0u >> mb;
U32 maskme = ~0u << (31 - me);
return (mb <= me) ? maskmb & maskme : maskmb | maskme;
}
static inline U32 rotl32(U32 x, U32 amount)
{
return (x << amount) | (x >> ((32 - amount) & 31));
}
static inline U32 __rlwinm(U32 rs, U32 sh, U32 mb, U32 me)
{
return rotl32(rs, sh) & ppcmask(mb, me);
}
static inline U32 __rlwimi(U32 ra, U32 rs, U32 sh, U32 mb, U32 me)
{
U32 mask = ppcmask(mb, me);
return (ra & ~mask) | (rotl32(rs, sh) & mask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment