gecko-dev/intl/uconv/nsUTF8ToUnicodeSSE2.cpp
Birunthan Mohanathas 70553064dd Bug 1038537 - Part 7: Flatten intl/uconv/src/ directory. r=smontagu
--HG--
rename : intl/uconv/src/8859-1.uf => intl/uconv/8859-1.uf
rename : intl/uconv/src/8859-1.ut => intl/uconv/8859-1.ut
rename : intl/uconv/src/cp1252.uf => intl/uconv/cp1252.uf
rename : intl/uconv/src/cp1252.ut => intl/uconv/cp1252.ut
rename : intl/uconv/src/macroman.uf => intl/uconv/macroman.uf
rename : intl/uconv/src/macroman.ut => intl/uconv/macroman.ut
rename : intl/uconv/src/nsCP1252ToUnicode.cpp => intl/uconv/nsCP1252ToUnicode.cpp
rename : intl/uconv/src/nsCP1252ToUnicode.h => intl/uconv/nsCP1252ToUnicode.h
rename : intl/uconv/src/nsConverterInputStream.cpp => intl/uconv/nsConverterInputStream.cpp
rename : intl/uconv/src/nsConverterInputStream.h => intl/uconv/nsConverterInputStream.h
rename : intl/uconv/src/nsConverterOutputStream.cpp => intl/uconv/nsConverterOutputStream.cpp
rename : intl/uconv/src/nsConverterOutputStream.h => intl/uconv/nsConverterOutputStream.h
rename : intl/uconv/src/nsISO88591ToUnicode.cpp => intl/uconv/nsISO88591ToUnicode.cpp
rename : intl/uconv/src/nsISO88591ToUnicode.h => intl/uconv/nsISO88591ToUnicode.h
rename : intl/uconv/src/nsMacRomanToUnicode.cpp => intl/uconv/nsMacRomanToUnicode.cpp
rename : intl/uconv/src/nsMacRomanToUnicode.h => intl/uconv/nsMacRomanToUnicode.h
rename : intl/uconv/src/nsReplacementToUnicode.cpp => intl/uconv/nsReplacementToUnicode.cpp
rename : intl/uconv/src/nsReplacementToUnicode.h => intl/uconv/nsReplacementToUnicode.h
rename : intl/uconv/src/nsScriptableUConv.cpp => intl/uconv/nsScriptableUConv.cpp
rename : intl/uconv/src/nsScriptableUConv.h => intl/uconv/nsScriptableUConv.h
rename : intl/uconv/src/nsTextToSubURI.cpp => intl/uconv/nsTextToSubURI.cpp
rename : intl/uconv/src/nsTextToSubURI.h => intl/uconv/nsTextToSubURI.h
rename : intl/uconv/src/nsUConvModule.cpp => intl/uconv/nsUConvModule.cpp
rename : intl/uconv/src/nsUTF8ConverterService.cpp => intl/uconv/nsUTF8ConverterService.cpp
rename : intl/uconv/src/nsUTF8ConverterService.h => intl/uconv/nsUTF8ConverterService.h
rename : intl/uconv/src/nsUTF8ToUnicode.cpp => intl/uconv/nsUTF8ToUnicode.cpp
rename : intl/uconv/src/nsUTF8ToUnicode.h => intl/uconv/nsUTF8ToUnicode.h
rename : intl/uconv/src/nsUTF8ToUnicodeSSE2.cpp => intl/uconv/nsUTF8ToUnicodeSSE2.cpp
rename : intl/uconv/src/nsUnicodeToCP1252.cpp => intl/uconv/nsUnicodeToCP1252.cpp
rename : intl/uconv/src/nsUnicodeToCP1252.h => intl/uconv/nsUnicodeToCP1252.h
rename : intl/uconv/src/nsUnicodeToISO88591.cpp => intl/uconv/nsUnicodeToISO88591.cpp
rename : intl/uconv/src/nsUnicodeToISO88591.h => intl/uconv/nsUnicodeToISO88591.h
rename : intl/uconv/src/nsUnicodeToMacRoman.cpp => intl/uconv/nsUnicodeToMacRoman.cpp
rename : intl/uconv/src/nsUnicodeToMacRoman.h => intl/uconv/nsUnicodeToMacRoman.h
rename : intl/uconv/src/nsUnicodeToUTF8.cpp => intl/uconv/nsUnicodeToUTF8.cpp
rename : intl/uconv/src/nsUnicodeToUTF8.h => intl/uconv/nsUnicodeToUTF8.h
2014-07-24 10:56:39 -07:00

97 lines
2.7 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This file should only be compiled if you're on x86 or x86_64. Additionally,
// you'll need to compile this file with -msse2 if you're using gcc.
#include <emmintrin.h>
#include "nscore.h"
namespace mozilla {
namespace SSE2 {
void
Convert_ascii_run(const char *&src,
char16_t *&dst,
int32_t len)
{
if (len > 15) {
__m128i in, out1, out2;
__m128d *outp1, *outp2;
__m128i zeroes;
uint32_t offset;
// align input to 16 bytes
while ((NS_PTR_TO_UINT32(src) & 15) && len > 0) {
if (*src & 0x80U)
return;
*dst++ = (char16_t) *src++;
len--;
}
zeroes = _mm_setzero_si128();
offset = NS_PTR_TO_UINT32(dst) & 15;
// Note: all these inner loops have to break, not return; we need
// to let the single-char loop below catch any leftover
// byte-at-a-time ASCII chars, since this function must consume
// all available ASCII chars before it returns
if (offset == 0) {
while (len > 15) {
in = _mm_load_si128((__m128i *) src);
if (_mm_movemask_epi8(in))
break;
out1 = _mm_unpacklo_epi8(in, zeroes);
out2 = _mm_unpackhi_epi8(in, zeroes);
_mm_stream_si128((__m128i *) dst, out1);
_mm_stream_si128((__m128i *) (dst + 8), out2);
dst += 16;
src += 16;
len -= 16;
}
} else if (offset == 8) {
outp1 = (__m128d *) &out1;
outp2 = (__m128d *) &out2;
while (len > 15) {
in = _mm_load_si128((__m128i *) src);
if (_mm_movemask_epi8(in))
break;
out1 = _mm_unpacklo_epi8(in, zeroes);
out2 = _mm_unpackhi_epi8(in, zeroes);
_mm_storel_epi64((__m128i *) dst, out1);
_mm_storel_epi64((__m128i *) (dst + 8), out2);
_mm_storeh_pd((double *) (dst + 4), *outp1);
_mm_storeh_pd((double *) (dst + 12), *outp2);
src += 16;
dst += 16;
len -= 16;
}
} else {
while (len > 15) {
in = _mm_load_si128((__m128i *) src);
if (_mm_movemask_epi8(in))
break;
out1 = _mm_unpacklo_epi8(in, zeroes);
out2 = _mm_unpackhi_epi8(in, zeroes);
_mm_storeu_si128((__m128i *) dst, out1);
_mm_storeu_si128((__m128i *) (dst + 8), out2);
src += 16;
dst += 16;
len -= 16;
}
}
}
// finish off a byte at a time
while (len-- > 0 && (*src & 0x80U) == 0) {
*dst++ = (char16_t) *src++;
}
}
} // namespace SSE2
} // namespace mozilla