gfx/angle/src/libGLESv2/renderer/ImageSSE2.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include "precompiled.h"
michael@0 2 //
michael@0 3 // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
michael@0 4 // Use of this source code is governed by a BSD-style license that can be
michael@0 5 // found in the LICENSE file.
michael@0 6 //
michael@0 7
michael@0 8 // ImageSSE2.cpp: Implements SSE2-based functions of rx::Image class. It's
michael@0 9 // in a separated file for GCC, which can enable SSE usage only per-file,
michael@0 10 // not for code blocks that use SSE2 explicitly.
michael@0 11
michael@0 12 #include "libGLESv2/Texture.h"
michael@0 13 #include "libGLESv2/renderer/Image.h"
michael@0 14
michael@0 15 namespace rx
michael@0 16 {
michael@0 17
michael@0 18 void Image::loadRGBAUByteDataToBGRASSE2(GLsizei width, GLsizei height,
michael@0 19 int inputPitch, const void *input, size_t outputPitch, void *output)
michael@0 20 {
michael@0 21 const unsigned int *source = NULL;
michael@0 22 unsigned int *dest = NULL;
michael@0 23 __m128i brMask = _mm_set1_epi32(0x00ff00ff);
michael@0 24
michael@0 25 for (int y = 0; y < height; y++)
michael@0 26 {
michael@0 27 source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
michael@0 28 dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
michael@0 29 int x = 0;
michael@0 30
michael@0 31 // Make output writes aligned
michael@0 32 for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 15) != 0) && x < width; x++)
michael@0 33 {
michael@0 34 unsigned int rgba = source[x];
michael@0 35 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
michael@0 36 }
michael@0 37
michael@0 38 for (; x + 3 < width; x += 4)
michael@0 39 {
michael@0 40 __m128i sourceData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&source[x]));
michael@0 41 // Mask out g and a, which don't change
michael@0 42 __m128i gaComponents = _mm_andnot_si128(brMask, sourceData);
michael@0 43 // Mask out b and r
michael@0 44 __m128i brComponents = _mm_and_si128(sourceData, brMask);
michael@0 45 // Swap b and r
michael@0 46 __m128i brSwapped = _mm_shufflehi_epi16(_mm_shufflelo_epi16(brComponents, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
michael@0 47 __m128i result = _mm_or_si128(gaComponents, brSwapped);
michael@0 48 _mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), result);
michael@0 49 }
michael@0 50
michael@0 51 // Perform leftover writes
michael@0 52 for (; x < width; x++)
michael@0 53 {
michael@0 54 unsigned int rgba = source[x];
michael@0 55 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
michael@0 56 }
michael@0 57 }
michael@0 58 }
michael@0 59
michael@0 60 void Image::loadAlphaDataToBGRASSE2(GLsizei width, GLsizei height,
michael@0 61 int inputPitch, const void *input, size_t outputPitch, void *output)
michael@0 62 {
michael@0 63 const unsigned char *source = NULL;
michael@0 64 unsigned int *dest = NULL;
michael@0 65 __m128i zeroWide = _mm_setzero_si128();
michael@0 66
michael@0 67 for (int y = 0; y < height; y++)
michael@0 68 {
michael@0 69 source = static_cast<const unsigned char*>(input) + y * inputPitch;
michael@0 70 dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
michael@0 71
michael@0 72 int x;
michael@0 73 // Make output writes aligned
michael@0 74 for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 0xF) != 0 && x < width); x++)
michael@0 75 {
michael@0 76 dest[x] = static_cast<unsigned int>(source[x]) << 24;
michael@0 77 }
michael@0 78
michael@0 79 for (; x + 7 < width; x += 8)
michael@0 80 {
michael@0 81 __m128i sourceData = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(&source[x]));
michael@0 82 // Interleave each byte to 16bit, make the lower byte to zero
michael@0 83 sourceData = _mm_unpacklo_epi8(zeroWide, sourceData);
michael@0 84 // Interleave each 16bit to 32bit, make the lower 16bit to zero
michael@0 85 __m128i lo = _mm_unpacklo_epi16(zeroWide, sourceData);
michael@0 86 __m128i hi = _mm_unpackhi_epi16(zeroWide, sourceData);
michael@0 87
michael@0 88 _mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), lo);
michael@0 89 _mm_store_si128(reinterpret_cast<__m128i*>(&dest[x + 4]), hi);
michael@0 90 }
michael@0 91
michael@0 92 // Handle the remainder
michael@0 93 for (; x < width; x++)
michael@0 94 {
michael@0 95 dest[x] = static_cast<unsigned int>(source[x]) << 24;
michael@0 96 }
michael@0 97 }
michael@0 98 }
michael@0 99
michael@0 100 }

mercurial