Guest User

Untitled

a guest
Jan 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. ```csharp
  2. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3. public static uint ReverseEndianness(uint value)
  4. {
  5. // This takes advantage of the fact that the JIT can detect
  6. // ROL32 / ROR32 patterns and output the correct intrinsic.
  7. //
  8. // Input: value = [ ww xx yy zz ]
  9. //
  10. // First line generates : [ zz ww xx yy ]
  11. // & [ FF 00 FF 00 ]
  12. // = [ zz 00 xx 00 ]
  13. //
  14. // Second line generates: [ xx yy zz ww ]
  15. // & [ 00 FF 00 FF ]
  16. // = [ 00 yy 00 ww ]
  17. //
  18. // (sum) = [ zz yy xx ww ]
  19. return (((value >> 8) | (value << 24)) & 0xFF00FF00U)
  20. + (((value << 8) | (value >> 24)) & 0x00FF00FFU);
  21. }
  22. ```
  23.  
  24. Generated assembly:
  25.  
  26. ```asm
  27. 00007FFBBB705CA0 mov eax,ecx
  28. 00007FFBBB705CA2 rol eax,18h
  29. 00007FFBBB705CA5 and eax,0FF00FF00h
  30. 00007FFBBB705CAA rol ecx,8
  31. 00007FFBBB705CAD and ecx,0FF00FFh
  32. 00007FFBBB705CB3 add eax,ecx
  33. 00007FFBBB705CB5 ret
  34. ```
Add Comment
Please, Sign In to add comment