Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsTextFragmentSSE2.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
// This file should only be compiled if you're on x86 or x86_64.  Additionally,
8
// you'll need to compile this file with -msse2 if you're using gcc.
9
10
#include <emmintrin.h>
11
#include "nscore.h"
12
#include "nsAlgorithm.h"
13
#include "nsTextFragmentImpl.h"
14
#include <algorithm>
15
16
namespace mozilla {
17
namespace SSE2 {
18
19
static inline bool
20
is_zero (__m128i x)
21
0
{
22
0
  return
23
0
    _mm_movemask_epi8(_mm_cmpeq_epi8(x, _mm_setzero_si128())) == 0xffff;
24
0
}
25
26
int32_t
27
FirstNon8Bit(const char16_t *str, const char16_t *end)
28
0
{
29
0
  const uint32_t numUnicharsPerVector = 8;
30
0
  typedef Non8BitParameters<sizeof(size_t)> p;
31
0
  const size_t mask = p::mask();
32
0
  const uint32_t numUnicharsPerWord = p::numUnicharsPerWord();
33
0
  const int32_t len = end - str;
34
0
  int32_t i = 0;
35
0
36
0
  // Align ourselves to a 16-byte boundary, as required by _mm_load_si128
37
0
  // (i.e. MOVDQA).
38
0
  int32_t alignLen =
39
0
    std::min(len, int32_t(((-NS_PTR_TO_INT32(str)) & 0xf) / sizeof(char16_t)));
40
0
  for (; i < alignLen; i++) {
41
0
    if (str[i] > 255)
42
0
      return i;
43
0
  }
44
0
45
0
  // Check one XMM register (16 bytes) at a time.
46
0
  const int32_t vectWalkEnd = ((len - i) / numUnicharsPerVector) * numUnicharsPerVector;
47
0
  const uint16_t shortMask = 0xff00;
48
0
  __m128i vectmask = _mm_set1_epi16(static_cast<int16_t>(shortMask));
49
0
  for(; i < vectWalkEnd; i += numUnicharsPerVector) {
50
0
    const __m128i vect = *reinterpret_cast<const __m128i*>(str + i);
51
0
    if (!is_zero(_mm_and_si128(vect, vectmask)))
52
0
      return i;
53
0
  }
54
0
55
0
  // Check one word at a time.
56
0
  const int32_t wordWalkEnd = ((len - i) / numUnicharsPerWord) * numUnicharsPerWord;
57
0
  for(; i < wordWalkEnd; i += numUnicharsPerWord) {
58
0
    const size_t word = *reinterpret_cast<const size_t*>(str + i);
59
0
    if (word & mask)
60
0
      return i;
61
0
  }
62
0
63
0
  // Take care of the remainder one character at a time.
64
0
  for (; i < len; i++) {
65
0
    if (str[i] > 255) {
66
0
      return i;
67
0
    }
68
0
  }
69
0
70
0
  return -1;
71
0
}
72
73
} // namespace SSE2
74
} // namespace mozilla