LCOV - code coverage report
Current view: directory - intl/uconv/src - nsUTF8ToUnicodeSSE2.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 50 50 100.0 %
Date: 2012-06-02 Functions: 1 1 100.0 %

       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           17715 : Convert_ascii_run(const char *&src,
      48                 :                   PRUnichar  *&dst,
      49                 :                   PRInt32      len)
      50                 : {
      51           17715 :   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           92228 :     while ((NS_PTR_TO_UINT32(src) & 15) && len > 0) {
      59           68666 :       if (*src & 0x80U)
      60             300 :         return;
      61           68366 :       *dst++ = (PRUnichar) *src++;
      62           68366 :       len--;
      63                 :     }
      64                 : 
      65           11631 :     zeroes = _mm_setzero_si128();
      66                 : 
      67           11631 :     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           11631 :     if (offset == 0) {
      75          677101 :       while (len > 15) {
      76         1312674 :         in = _mm_load_si128((__m128i *) src);
      77         1312674 :         if (_mm_movemask_epi8(in))
      78             168 :           break;
      79         1312338 :         out1 = _mm_unpacklo_epi8(in, zeroes);
      80         1312338 :         out2 = _mm_unpackhi_epi8(in, zeroes);
      81          656169 :         _mm_stream_si128((__m128i *) dst, out1);
      82          656169 :         _mm_stream_si128((__m128i *) (dst + 8), out2);
      83          656169 :         dst += 16;
      84          656169 :         src += 16;
      85          656169 :         len -= 16;
      86                 :       }
      87            1165 :     } else if (offset == 8) {
      88             696 :       outp1 = (__m128d *) &out1;
      89             696 :       outp2 = (__m128d *) &out2;
      90          113786 :       while (len > 15) {
      91          224982 :         in = _mm_load_si128((__m128i *) src);
      92          224982 :         if (_mm_movemask_epi8(in))
      93              97 :           break;
      94          224788 :         out1 = _mm_unpacklo_epi8(in, zeroes);
      95          224788 :         out2 = _mm_unpackhi_epi8(in, zeroes);
      96          112394 :         _mm_storel_epi64((__m128i *) dst, out1);
      97          112394 :         _mm_storel_epi64((__m128i *) (dst + 8), out2);
      98          112394 :         _mm_storeh_pd((double *) (dst + 4), *outp1);
      99          112394 :         _mm_storeh_pd((double *) (dst + 12), *outp2);
     100          112394 :         src += 16;
     101          112394 :         dst += 16;
     102          112394 :         len -= 16;
     103                 :       }
     104                 :     } else {
     105            3745 :       while (len > 15) {
     106            6460 :         in = _mm_load_si128((__m128i *) src);
     107            6460 :         if (_mm_movemask_epi8(in))
     108             423 :           break;
     109            5614 :         out1 = _mm_unpacklo_epi8(in, zeroes);
     110            5614 :         out2 = _mm_unpackhi_epi8(in, zeroes);
     111            2807 :         _mm_storeu_si128((__m128i *) dst, out1);
     112            2807 :         _mm_storeu_si128((__m128i *) (dst + 8), out2);
     113            2807 :         src += 16;
     114            2807 :         dst += 16;
     115            2807 :         len -= 16;
     116                 :       }
     117                 :     }
     118                 :   }
     119                 : 
     120                 :   // finish off a byte at a time
     121                 : 
     122          165857 :   while (len-- > 0 && (*src & 0x80U) == 0) {
     123          131027 :     *dst++ = (PRUnichar) *src++;
     124                 :   }
     125                 : }
     126                 : 
     127                 : } // namespace SSE2
     128                 : } // namespace mozilla

Generated by: LCOV version 1.7