simdutf 8.0.0
Unicode at GB/s.
Loading...
Searching...
No Matches
swap_bytes.h
1#ifndef SIMDUTF_SWAP_BYTES_H
2#define SIMDUTF_SWAP_BYTES_H
3
4namespace simdutf {
5namespace scalar {
6
7constexpr inline simdutf_warn_unused uint16_t
8u16_swap_bytes(const uint16_t word) {
9 return uint16_t((word >> 8) | (word << 8));
10}
11
12constexpr inline simdutf_warn_unused uint32_t
13u32_swap_bytes(const uint32_t word) {
14 return ((word >> 24) & 0xff) | // move byte 3 to byte 0
15 ((word << 8) & 0xff0000) | // move byte 1 to byte 2
16 ((word >> 8) & 0xff00) | // move byte 2 to byte 1
17 ((word << 24) & 0xff000000); // byte 0 to byte 3
18}
19
20namespace utf32 {
21template <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
26namespace utf16 {
27template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
28 return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
29}
30} // namespace utf16
31
32} // namespace scalar
33} // namespace simdutf
34
35#endif