| 1 |
std::pair<const char *, char16_t *> |
| 2 |
lsx_convert_latin1_to_utf16le(const char *buf, size_t len, |
| 3 |
char16_t *utf16_output) { |
| 4 |
const char *end = buf + len; |
| 5 |
|
| 6 |
__m128i zero = __lsx_vldi(0); |
| 7 |
while (buf + 16 <= end) { |
| 8 |
__m128i in8 = __lsx_vld(reinterpret_cast<const uint8_t *>(buf), 0); |
| 9 |
|
| 10 |
__m128i inlow = __lsx_vilvl_b(zero, in8); |
| 11 |
__m128i inhigh = __lsx_vilvh_b(zero, in8); |
| 12 |
__lsx_vst(inlow, reinterpret_cast<uint16_t *>(utf16_output), 0); |
| 13 |
__lsx_vst(inhigh, reinterpret_cast<uint16_t *>(utf16_output), 16); |
| 14 |
|
| 15 |
utf16_output += 16; |
| 16 |
buf += 16; |
| 17 |
} |
| 18 |
|
| 19 |
return std::make_pair(buf, utf16_output); |
| 20 |
} |
| 21 |
|
| 22 |
std::pair<const char *, char16_t *> |
| 23 |
lsx_convert_latin1_to_utf16be(const char *buf, size_t len, |
| 24 |
char16_t *utf16_output) { |
| 25 |
const char *end = buf + len; |
| 26 |
__m128i zero = __lsx_vldi(0); |
| 27 |
while (buf + 16 <= end) { |
| 28 |
__m128i in8 = __lsx_vld(reinterpret_cast<const uint8_t *>(buf), 0); |
| 29 |
|
| 30 |
__m128i inlow = __lsx_vilvl_b(in8, zero); |
| 31 |
__m128i inhigh = __lsx_vilvh_b(in8, zero); |
| 32 |
__lsx_vst(inlow, reinterpret_cast<uint16_t *>(utf16_output), 0); |
| 33 |
__lsx_vst(inhigh, reinterpret_cast<uint16_t *>(utf16_output), 16); |
| 34 |
utf16_output += 16; |
| 35 |
buf += 16; |
| 36 |
} |
| 37 |
|
| 38 |
return std::make_pair(buf, utf16_output); |
| 39 |
} |