Created
December 6, 2011 23:36
-
-
Save rygorous/1440600 to your computer and use it in GitHub Desktop.
PPC rlwinm/rlwimi equivalent C code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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