Summary:
Previously some of this code had undefined behavior because it was performing
signed shifts that could overflow into the sign bit, as the result could not be
represented in a signed `int`. This caused failures when built with UBSAN.
This updates the code to consistently use the built-in `_byteswap_*` functions
when compiling with Microsoft Visual Studio and the `__builtin_bswap*` when
compiling with gcc or clang.
Reviewed By: quark-zju
Differential Revision: D7008197
fbshipit-source-id: adbe22032f05a35468195922ee00ccc3ff5efff9