/src/simdutf/src/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 | 204M | u16_swap_bytes(const uint16_t word) { |
9 | 204M | return uint16_t((word >> 8) | (word << 8)); |
10 | 204M | } |
11 | | |
12 | | constexpr inline simdutf_warn_unused uint32_t |
13 | 93.2k | u32_swap_bytes(const uint32_t word) { |
14 | 93.2k | return ((word >> 24) & 0xff) | // move byte 3 to byte 0 |
15 | 93.2k | ((word << 8) & 0xff0000) | // move byte 1 to byte 2 |
16 | 93.2k | ((word >> 8) & 0xff00) | // move byte 2 to byte 1 |
17 | 93.2k | ((word << 24) & 0xff000000); // byte 0 to byte 3 |
18 | 93.2k | } |
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 | 186M | template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) { |
28 | 186M | return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c; |
29 | 186M | } unsigned short simdutf::scalar::utf16::swap_if_needed<(simdutf::endianness)1>(unsigned short) Line | Count | Source | 27 | 86.1M | template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) { | 28 | 86.1M | return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c; | 29 | 86.1M | } |
unsigned short simdutf::scalar::utf16::swap_if_needed<(simdutf::endianness)0>(unsigned short) Line | Count | Source | 27 | 100M | template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) { | 28 | 100M | return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c; | 29 | 100M | } |
|
30 | | } // namespace utf16 |
31 | | |
32 | | } // namespace scalar |
33 | | } // namespace simdutf |
34 | | |
35 | | #endif |