/src/simdutf/include/simdutf/scalar/swap_bytes.h
Line | Count | Source |
1 | | #ifndef SIMDUTF_SWAP_BYTES_H |
2 | | #define SIMDUTF_SWAP_BYTES_H |
3 | | |
4 | | namespace simdutf { |
5 | | namespace scalar { |
6 | | |
7 | | constexpr inline simdutf_warn_unused uint16_t |
8 | 0 | u16_swap_bytes(const uint16_t word) { |
9 | 0 | return uint16_t((word >> 8) | (word << 8)); |
10 | 0 | } |
11 | | |
12 | | constexpr inline simdutf_warn_unused uint32_t |
13 | 0 | u32_swap_bytes(const uint32_t word) { |
14 | 0 | return ((word >> 24) & 0xff) | // move byte 3 to byte 0 |
15 | 0 | ((word << 8) & 0xff0000) | // move byte 1 to byte 2 |
16 | 0 | ((word >> 8) & 0xff00) | // move byte 2 to byte 1 |
17 | 0 | ((word << 24) & 0xff000000); // byte 0 to byte 3 |
18 | 0 | } |
19 | | |
20 | | namespace utf32 { |
21 | | template <endianness big_endian> constexpr uint32_t swap_if_needed(uint32_t c) { |
22 | | return !match_system(big_endian) ? scalar::u32_swap_bytes(c) : c; |
23 | | } |
24 | | } // namespace utf32 |
25 | | |
26 | | namespace utf16 { |
27 | 0 | template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) { |
28 | 0 | return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c; |
29 | 0 | } Unexecuted instantiation: unsigned short simdutf::scalar::utf16::swap_if_needed<(simdutf::endianness)1>(unsigned short) Unexecuted instantiation: unsigned short simdutf::scalar::utf16::swap_if_needed<(simdutf::endianness)0>(unsigned short) |
30 | | } // namespace utf16 |
31 | | |
32 | | } // namespace scalar |
33 | | } // namespace simdutf |
34 | | |
35 | | #endif |