Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```csharp
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint ReverseEndianness(uint value)
- {
- // This takes advantage of the fact that the JIT can detect
- // ROL32 / ROR32 patterns and output the correct intrinsic.
- //
- // Input: value = [ ww xx yy zz ]
- //
- // First line generates : [ zz ww xx yy ]
- // & [ FF 00 FF 00 ]
- // = [ zz 00 xx 00 ]
- //
- // Second line generates: [ xx yy zz ww ]
- // & [ 00 FF 00 FF ]
- // = [ 00 yy 00 ww ]
- //
- // (sum) = [ zz yy xx ww ]
- return (((value >> 8) | (value << 24)) & 0xFF00FF00U)
- + (((value << 8) | (value >> 24)) & 0x00FF00FFU);
- }
- ```
- Generated assembly:
- ```asm
- 00007FFBBB705CA0 mov eax,ecx
- 00007FFBBB705CA2 rol eax,18h
- 00007FFBBB705CA5 and eax,0FF00FF00h
- 00007FFBBB705CAA rol ecx,8
- 00007FFBBB705CAD and ecx,0FF00FFh
- 00007FFBBB705CB3 add eax,ecx
- 00007FFBBB705CB5 ret
- ```
Add Comment
Please, Sign In to add comment