Created
March 20, 2019 04:18
-
-
Save uchan-nos/b6c18a25fd0d1593989fa41ffad7e7d7 to your computer and use it in GitHub Desktop.
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
| #include <cstdint> | |
| template <class T> | |
| T ConvEndian(T orig) { | |
| T result{}; | |
| for (int i = 0; i < sizeof(T); ++i) { | |
| result <<= 8; | |
| result |= orig & 0xff; | |
| orig >>= 8; | |
| } | |
| return result; | |
| } | |
| uint16_t f(uint16_t value) { | |
| // 最適化されて rol 命令になる | |
| return ConvEndian(value); | |
| } | |
| uint32_t f(uint32_t value) { | |
| // 最適化されて bswap 命令になる | |
| return ConvEndian(value); | |
| } | |
| uint64_t f(uint64_t value) { | |
| // 最適化されて bswap 命令になる | |
| return ConvEndian(value); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment