1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla Foundation code.
15 : *
16 : * The Initial Developer of the Original Code is the Mozilla Foundation.
17 : *
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : // This file should only be compiled if you're on x86 or x86_64. Additionally,
38 : // you'll need to compile this file with -msse2 if you're using gcc.
39 :
40 : #include <emmintrin.h>
41 : #include "nscore.h"
42 :
43 : namespace mozilla {
44 : namespace SSE2 {
45 :
46 : void
47 17420 : Convert_ascii_run(const char *&src,
48 : PRUnichar *&dst,
49 : PRInt32 len)
50 : {
51 17420 : if (len > 15) {
52 : __m128i in, out1, out2;
53 : __m128d *outp1, *outp2;
54 : __m128i zeroes;
55 : PRUint32 offset;
56 :
57 : // align input to 16 bytes
58 89961 : while ((NS_PTR_TO_UINT32(src) & 15) && len > 0) {
59 66962 : if (*src & 0x80U)
60 275 : return;
61 66687 : *dst++ = (PRUnichar) *src++;
62 66687 : len--;
63 : }
64 :
65 11362 : zeroes = _mm_setzero_si128();
66 :
67 11362 : offset = NS_PTR_TO_UINT32(dst) & 15;
68 :
69 : // Note: all these inner loops have to break, not return; we need
70 : // to let the single-char loop below catch any leftover
71 : // byte-at-a-time ASCII chars, since this function must consume
72 : // all available ASCII chars before it returns
73 :
74 11362 : if (offset == 0) {
75 673096 : while (len > 15) {
76 1304990 : in = _mm_load_si128((__m128i *) src);
77 1304990 : if (_mm_movemask_epi8(in))
78 115 : break;
79 1304760 : out1 = _mm_unpacklo_epi8(in, zeroes);
80 1304760 : out2 = _mm_unpackhi_epi8(in, zeroes);
81 652380 : _mm_stream_si128((__m128i *) dst, out1);
82 652380 : _mm_stream_si128((__m128i *) (dst + 8), out2);
83 652380 : dst += 16;
84 652380 : src += 16;
85 652380 : len -= 16;
86 : }
87 1004 : } else if (offset == 8) {
88 649 : outp1 = (__m128d *) &out1;
89 649 : outp2 = (__m128d *) &out2;
90 112975 : while (len > 15) {
91 223462 : in = _mm_load_si128((__m128i *) src);
92 223462 : if (_mm_movemask_epi8(in))
93 54 : break;
94 223354 : out1 = _mm_unpacklo_epi8(in, zeroes);
95 223354 : out2 = _mm_unpackhi_epi8(in, zeroes);
96 111677 : _mm_storel_epi64((__m128i *) dst, out1);
97 111677 : _mm_storel_epi64((__m128i *) (dst + 8), out2);
98 111677 : _mm_storeh_pd((double *) (dst + 4), *outp1);
99 111677 : _mm_storeh_pd((double *) (dst + 12), *outp2);
100 111677 : src += 16;
101 111677 : dst += 16;
102 111677 : len -= 16;
103 : }
104 : } else {
105 2104 : while (len > 15) {
106 3420 : in = _mm_load_si128((__m128i *) src);
107 3420 : if (_mm_movemask_epi8(in))
108 316 : break;
109 2788 : out1 = _mm_unpacklo_epi8(in, zeroes);
110 2788 : out2 = _mm_unpackhi_epi8(in, zeroes);
111 1394 : _mm_storeu_si128((__m128i *) dst, out1);
112 1394 : _mm_storeu_si128((__m128i *) (dst + 8), out2);
113 1394 : src += 16;
114 1394 : dst += 16;
115 1394 : len -= 16;
116 : }
117 : }
118 : }
119 :
120 : // finish off a byte at a time
121 :
122 163242 : while (len-- > 0 && (*src & 0x80U) == 0) {
123 128952 : *dst++ = (PRUnichar) *src++;
124 : }
125 : }
126 :
127 : } // namespace SSE2
128 : } // namespace mozilla
|