Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
455
third_party/FreeRDP/libfreerdp/codec/sse/nsc_sse2.c
vendored
Normal file
455
third_party/FreeRDP/libfreerdp/codec/sse/nsc_sse2.c
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* NSCodec Library - SSE2 Optimizations
|
||||
*
|
||||
* Copyright 2012 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <winpr/cast.h>
|
||||
#include <winpr/platform.h>
|
||||
#include <freerdp/config.h>
|
||||
|
||||
#include "../nsc_types.h"
|
||||
#include "nsc_sse2.h"
|
||||
|
||||
#include "../../core/simd.h"
|
||||
#include "../../primitives/sse/prim_avxsse.h"
|
||||
|
||||
#if defined(SSE_AVX_INTRINSICS_ENABLED)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <xmmintrin.h>
|
||||
#include <emmintrin.h>
|
||||
|
||||
#include <freerdp/codec/color.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
static inline size_t nsc_encode_next_bgrx32(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12),
|
||||
*(src + 8), *(src + 4), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13),
|
||||
*(src + 9), *(src + 5), *(src + 1));
|
||||
*r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14),
|
||||
*(src + 10), *(src + 6), *(src + 2));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 32;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_bgra32(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12),
|
||||
*(src + 8), *(src + 4), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13),
|
||||
*(src + 9), *(src + 5), *(src + 1));
|
||||
*r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14),
|
||||
*(src + 10), *(src + 6), *(src + 2));
|
||||
*a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15),
|
||||
*(src + 11), *(src + 7), *(src + 3));
|
||||
return 32;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgbx32(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12),
|
||||
*(src + 8), *(src + 4), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13),
|
||||
*(src + 9), *(src + 5), *(src + 1));
|
||||
*b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14),
|
||||
*(src + 10), *(src + 6), *(src + 2));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 32;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgba32(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12),
|
||||
*(src + 8), *(src + 4), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13),
|
||||
*(src + 9), *(src + 5), *(src + 1));
|
||||
*b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14),
|
||||
*(src + 10), *(src + 6), *(src + 2));
|
||||
*a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15),
|
||||
*(src + 11), *(src + 7), *(src + 3));
|
||||
return 32;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_bgr24(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*b_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9),
|
||||
*(src + 6), *(src + 3), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10),
|
||||
*(src + 7), *(src + 4), *(src + 1));
|
||||
*r_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11),
|
||||
*(src + 8), *(src + 5), *(src + 2));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 24;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgb24(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*r_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9),
|
||||
*(src + 6), *(src + 3), *src);
|
||||
*g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10),
|
||||
*(src + 7), *(src + 4), *(src + 1));
|
||||
*b_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11),
|
||||
*(src + 8), *(src + 5), *(src + 2));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 24;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_bgr16(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*b_val = _mm_set_epi16(
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5)));
|
||||
*g_val = _mm_set_epi16(
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)));
|
||||
*r_val = _mm_set_epi16(
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, (((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 16;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgb16(const BYTE* src, __m128i* r_val, __m128i* g_val,
|
||||
__m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*r_val = _mm_set_epi16(WINPR_ASSERTING_INT_CAST(INT16, ((src[15] & 0xF8) | (src[15] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[13] & 0xF8) | (src[13] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[11] & 0xF8) | (src[11] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[9] & 0xF8) | (src[9] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[7] & 0xF8) | (src[7] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[5] & 0xF8) | (src[5] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[3] & 0xF8) | (src[3] >> 5))),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, ((src[1] & 0xF8) | (src[1] >> 5))));
|
||||
*g_val = _mm_set_epi16(
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 15)) & 0x07) << 5) | (((*(src + 14)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 13)) & 0x07) << 5) | (((*(src + 12)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 11)) & 0x07) << 5) | (((*(src + 10)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 9)) & 0x07) << 5) | (((*(src + 8)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 7)) & 0x07) << 5) | (((*(src + 6)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 5)) & 0x07) << 5) | (((*(src + 4)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 3)) & 0x07) << 5) | (((*(src + 2)) & 0xE0) >> 3)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 1)) & 0x07) << 5) | (((*src) & 0xE0) >> 3)));
|
||||
*b_val = _mm_set_epi16(
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 14)) & 0x1F) << 3) | (((*(src + 14)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 12)) & 0x1F) << 3) | (((*(src + 12)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 10)) & 0x1F) << 3) | (((*(src + 10)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 8)) & 0x1F) << 3) | (((*(src + 8)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 6)) & 0x1F) << 3) | (((*(src + 6)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 4)) & 0x1F) << 3) | (((*(src + 4)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16,
|
||||
(((*(src + 2)) & 0x1F) << 3) | (((*(src + 2)) >> 2) & 0x07)),
|
||||
WINPR_ASSERTING_INT_CAST(INT16, (((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07)));
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 16;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_a4(const BYTE* src, const BYTE* palette, __m128i* r_val,
|
||||
__m128i* g_val, __m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
BYTE idx[8] = WINPR_C_ARRAY_INIT;
|
||||
|
||||
for (int shift = 7; shift >= 0; shift--)
|
||||
{
|
||||
idx[shift] = ((*src) >> shift) & 1;
|
||||
idx[shift] |= (((*(src + 1)) >> shift) & 1) << 1;
|
||||
idx[shift] |= (((*(src + 2)) >> shift) & 1) << 2;
|
||||
idx[shift] |= (((*(src + 3)) >> shift) & 1) << 3;
|
||||
idx[shift] *= 3;
|
||||
}
|
||||
|
||||
*r_val = _mm_set_epi16(palette[idx[0]], palette[idx[1]], palette[idx[2]], palette[idx[3]],
|
||||
palette[idx[4]], palette[idx[5]], palette[idx[6]], palette[idx[7]]);
|
||||
*g_val = _mm_set_epi16(palette[idx[0] + 1], palette[idx[1] + 1], palette[idx[2] + 1],
|
||||
palette[idx[3] + 1], palette[idx[4] + 1], palette[idx[5] + 1],
|
||||
palette[idx[6] + 1], palette[idx[7] + 1]);
|
||||
*b_val = _mm_set_epi16(palette[idx[0] + 2], palette[idx[1] + 2], palette[idx[2] + 2],
|
||||
palette[idx[3] + 2], palette[idx[4] + 2], palette[idx[5] + 2],
|
||||
palette[idx[6] + 2], palette[idx[7] + 2]);
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 4;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgb8(const BYTE* src, const BYTE* palette, __m128i* r_val,
|
||||
__m128i* g_val, __m128i* b_val, __m128i* a_val)
|
||||
{
|
||||
*r_val = _mm_set_epi16(palette[(*(src + 7ULL)) * 3ULL], palette[(*(src + 6ULL)) * 3ULL],
|
||||
palette[(*(src + 5ULL)) * 3ULL], palette[(*(src + 4ULL)) * 3ULL],
|
||||
palette[(*(src + 3ULL)) * 3ULL], palette[(*(src + 2ULL)) * 3ULL],
|
||||
palette[(*(src + 1ULL)) * 3ULL], palette[(*src) * 3ULL]);
|
||||
*g_val = _mm_set_epi16(
|
||||
palette[(*(src + 7ULL)) * 3ULL + 1ULL], palette[(*(src + 6ULL)) * 3ULL + 1ULL],
|
||||
palette[(*(src + 5ULL)) * 3ULL + 1ULL], palette[(*(src + 4ULL)) * 3ULL + 1ULL],
|
||||
palette[(*(src + 3ULL)) * 3ULL + 1ULL], palette[(*(src + 2ULL)) * 3ULL + 1ULL],
|
||||
palette[(*(src + 1ULL)) * 3ULL + 1ULL], palette[(*src) * 3ULL + 1ULL]);
|
||||
*b_val = _mm_set_epi16(
|
||||
palette[(*(src + 7ULL)) * 3ULL + 2ULL], palette[(*(src + 6ULL)) * 3ULL + 2ULL],
|
||||
palette[(*(src + 5ULL)) * 3ULL + 2ULL], palette[(*(src + 4ULL)) * 3ULL + 2ULL],
|
||||
palette[(*(src + 3ULL)) * 3ULL + 2ULL], palette[(*(src + 2ULL)) * 3ULL + 2ULL],
|
||||
palette[(*(src + 1ULL)) * 3ULL + 2ULL], palette[(*src) * 3ULL + 2ULL]);
|
||||
*a_val = _mm_set1_epi16(0xFF);
|
||||
return 8;
|
||||
}
|
||||
|
||||
static inline size_t nsc_encode_next_rgba(UINT32 format, const BYTE* src, const BYTE* palette,
|
||||
__m128i* r_val, __m128i* g_val, __m128i* b_val,
|
||||
__m128i* a_val)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PIXEL_FORMAT_BGRX32:
|
||||
return nsc_encode_next_bgrx32(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_BGRA32:
|
||||
return nsc_encode_next_bgra32(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_RGBX32:
|
||||
return nsc_encode_next_rgbx32(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_RGBA32:
|
||||
return nsc_encode_next_rgba32(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_BGR24:
|
||||
return nsc_encode_next_bgr24(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_RGB24:
|
||||
return nsc_encode_next_rgb24(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_BGR16:
|
||||
return nsc_encode_next_bgr16(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_RGB16:
|
||||
return nsc_encode_next_rgb16(src, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_A4:
|
||||
return nsc_encode_next_a4(src, palette, r_val, g_val, b_val, a_val);
|
||||
|
||||
case PIXEL_FORMAT_RGB8:
|
||||
return nsc_encode_next_rgb8(src, palette, r_val, g_val, b_val, a_val);
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, const BYTE* data, UINT32 scanline)
|
||||
{
|
||||
size_t y = 0;
|
||||
|
||||
if (!context || !data || (scanline == 0))
|
||||
return FALSE;
|
||||
|
||||
const UINT16 tempWidth = ROUND_UP_TO(context->width, 8);
|
||||
const UINT16 rw = (context->ChromaSubsamplingLevel > 0 ? tempWidth : context->width);
|
||||
|
||||
const BYTE ccl = WINPR_ASSERTING_INT_CAST(BYTE, context->ColorLossLevel);
|
||||
|
||||
for (; y < context->height; y++)
|
||||
{
|
||||
const BYTE* src = data + (context->height - 1 - y) * scanline;
|
||||
BYTE* yplane = context->priv->PlaneBuffers[0] + y * rw;
|
||||
BYTE* coplane = context->priv->PlaneBuffers[1] + y * rw;
|
||||
BYTE* cgplane = context->priv->PlaneBuffers[2] + y * rw;
|
||||
BYTE* aplane = context->priv->PlaneBuffers[3] + y * context->width;
|
||||
|
||||
for (UINT16 x = 0; x < context->width; x += 8)
|
||||
{
|
||||
__m128i r_val = WINPR_C_ARRAY_INIT;
|
||||
__m128i g_val = WINPR_C_ARRAY_INIT;
|
||||
__m128i b_val = WINPR_C_ARRAY_INIT;
|
||||
__m128i a_val = WINPR_C_ARRAY_INIT;
|
||||
|
||||
const size_t rc = nsc_encode_next_rgba(context->format, src, context->palette, &r_val,
|
||||
&g_val, &b_val, &a_val);
|
||||
src += rc;
|
||||
|
||||
__m128i y_val = _mm_srai_epi16(r_val, 2);
|
||||
y_val = _mm_add_epi16(y_val, _mm_srai_epi16(g_val, 1));
|
||||
y_val = _mm_add_epi16(y_val, _mm_srai_epi16(b_val, 2));
|
||||
__m128i co_val = _mm_sub_epi16(r_val, b_val);
|
||||
co_val = _mm_srai_epi16(co_val, ccl);
|
||||
__m128i cg_val = _mm_sub_epi16(g_val, _mm_srai_epi16(r_val, 1));
|
||||
cg_val = _mm_sub_epi16(cg_val, _mm_srai_epi16(b_val, 1));
|
||||
cg_val = _mm_srai_epi16(cg_val, ccl);
|
||||
y_val = _mm_packus_epi16(y_val, y_val);
|
||||
STORE_SI128(yplane, y_val);
|
||||
co_val = _mm_packs_epi16(co_val, co_val);
|
||||
STORE_SI128(coplane, co_val);
|
||||
cg_val = _mm_packs_epi16(cg_val, cg_val);
|
||||
STORE_SI128(cgplane, cg_val);
|
||||
a_val = _mm_packus_epi16(a_val, a_val);
|
||||
STORE_SI128(aplane, a_val);
|
||||
yplane += 8;
|
||||
coplane += 8;
|
||||
cgplane += 8;
|
||||
aplane += 8;
|
||||
}
|
||||
|
||||
if (context->ChromaSubsamplingLevel > 0 && (context->width % 2) == 1)
|
||||
{
|
||||
context->priv->PlaneBuffers[0][y * rw + context->width] =
|
||||
context->priv->PlaneBuffers[0][y * rw + context->width - 1];
|
||||
context->priv->PlaneBuffers[1][y * rw + context->width] =
|
||||
context->priv->PlaneBuffers[1][y * rw + context->width - 1];
|
||||
context->priv->PlaneBuffers[2][y * rw + context->width] =
|
||||
context->priv->PlaneBuffers[2][y * rw + context->width - 1];
|
||||
}
|
||||
}
|
||||
|
||||
if (context->ChromaSubsamplingLevel > 0 && (y % 2) == 1)
|
||||
{
|
||||
BYTE* yplane = context->priv->PlaneBuffers[0] + y * rw;
|
||||
BYTE* coplane = context->priv->PlaneBuffers[1] + y * rw;
|
||||
BYTE* cgplane = context->priv->PlaneBuffers[2] + y * rw;
|
||||
CopyMemory(yplane, yplane - rw, rw);
|
||||
CopyMemory(coplane, coplane - rw, rw);
|
||||
CopyMemory(cgplane, cgplane - rw, rw);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context)
|
||||
{
|
||||
BYTE* co_dst = nullptr;
|
||||
BYTE* cg_dst = nullptr;
|
||||
INT8* co_src0 = nullptr;
|
||||
INT8* co_src1 = nullptr;
|
||||
INT8* cg_src0 = nullptr;
|
||||
INT8* cg_src1 = nullptr;
|
||||
UINT32 tempWidth = 0;
|
||||
UINT32 tempHeight = 0;
|
||||
__m128i t;
|
||||
__m128i val;
|
||||
__m128i mask = _mm_set1_epi16(0xFF);
|
||||
tempWidth = ROUND_UP_TO(context->width, 8);
|
||||
tempHeight = ROUND_UP_TO(context->height, 2);
|
||||
|
||||
for (size_t y = 0; y < tempHeight >> 1; y++)
|
||||
{
|
||||
co_dst = context->priv->PlaneBuffers[1] + y * (tempWidth >> 1);
|
||||
cg_dst = context->priv->PlaneBuffers[2] + y * (tempWidth >> 1);
|
||||
co_src0 = (INT8*)context->priv->PlaneBuffers[1] + (y << 1) * tempWidth;
|
||||
co_src1 = co_src0 + tempWidth;
|
||||
cg_src0 = (INT8*)context->priv->PlaneBuffers[2] + (y << 1) * tempWidth;
|
||||
cg_src1 = cg_src0 + tempWidth;
|
||||
|
||||
for (UINT32 x = 0; x < tempWidth >> 1; x += 8)
|
||||
{
|
||||
t = LOAD_SI128(co_src0);
|
||||
t = _mm_avg_epu8(t, LOAD_SI128(co_src1));
|
||||
val = _mm_and_si128(_mm_srli_si128(t, 1), mask);
|
||||
val = _mm_avg_epu16(val, _mm_and_si128(t, mask));
|
||||
val = _mm_packus_epi16(val, val);
|
||||
STORE_SI128(co_dst, val);
|
||||
co_dst += 8;
|
||||
co_src0 += 16;
|
||||
co_src1 += 16;
|
||||
t = LOAD_SI128(cg_src0);
|
||||
t = _mm_avg_epu8(t, LOAD_SI128(cg_src1));
|
||||
val = _mm_and_si128(_mm_srli_si128(t, 1), mask);
|
||||
val = _mm_avg_epu16(val, _mm_and_si128(t, mask));
|
||||
val = _mm_packus_epi16(val, val);
|
||||
STORE_SI128(cg_dst, val);
|
||||
cg_dst += 8;
|
||||
cg_src0 += 16;
|
||||
cg_src1 += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL nsc_encode_sse2(NSC_CONTEXT* WINPR_RESTRICT context, const BYTE* WINPR_RESTRICT data,
|
||||
UINT32 scanline)
|
||||
{
|
||||
if (!nsc_encode_argb_to_aycocg_sse2(context, data, scanline))
|
||||
return FALSE;
|
||||
|
||||
if (context->ChromaSubsamplingLevel > 0)
|
||||
nsc_encode_subsampling_sse2(context);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsc_init_sse2_int(NSC_CONTEXT* WINPR_RESTRICT context)
|
||||
{
|
||||
#if defined(SSE_AVX_INTRINSICS_ENABLED)
|
||||
WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations");
|
||||
PROFILER_RENAME(context->priv->prof_nsc_encode, "nsc_encode_sse2")
|
||||
context->encode = nsc_encode_sse2;
|
||||
#else
|
||||
WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE2 intrinsics not available");
|
||||
WINPR_UNUSED(context);
|
||||
#endif
|
||||
}
|
||||
38
third_party/FreeRDP/libfreerdp/codec/sse/nsc_sse2.h
vendored
Normal file
38
third_party/FreeRDP/libfreerdp/codec/sse/nsc_sse2.h
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* NSCodec Library - SSE2 Optimizations
|
||||
*
|
||||
* Copyright 2012 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_LIB_CODEC_NSC_SSE2_H
|
||||
#define FREERDP_LIB_CODEC_NSC_SSE2_H
|
||||
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
#include <freerdp/codec/nsc.h>
|
||||
#include <freerdp/api.h>
|
||||
|
||||
FREERDP_LOCAL void nsc_init_sse2_int(NSC_CONTEXT* WINPR_RESTRICT context);
|
||||
static inline void nsc_init_sse2(NSC_CONTEXT* WINPR_RESTRICT context)
|
||||
{
|
||||
if (!IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) ||
|
||||
!IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
|
||||
return;
|
||||
|
||||
nsc_init_sse2_int(context);
|
||||
}
|
||||
|
||||
#endif /* FREERDP_LIB_CODEC_NSC_SSE2_H */
|
||||
470
third_party/FreeRDP/libfreerdp/codec/sse/rfx_sse2.c
vendored
Normal file
470
third_party/FreeRDP/libfreerdp/codec/sse/rfx_sse2.c
vendored
Normal file
@@ -0,0 +1,470 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* RemoteFX Codec Library - SSE2 Optimizations
|
||||
*
|
||||
* Copyright 2011 Stephen Erisman
|
||||
* Copyright 2011 Norbert Federa <norbert.federa@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <winpr/cast.h>
|
||||
#include <winpr/platform.h>
|
||||
#include <freerdp/config.h>
|
||||
|
||||
#include "../rfx_types.h"
|
||||
#include "rfx_sse2.h"
|
||||
|
||||
#include "../../core/simd.h"
|
||||
#include "../../primitives/sse/prim_avxsse.h"
|
||||
|
||||
#if defined(SSE_AVX_INTRINSICS_ENABLED)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
#include <xmmintrin.h>
|
||||
#include <emmintrin.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __attribute__(...)
|
||||
#endif
|
||||
|
||||
#define CACHE_LINE_BYTES 64
|
||||
|
||||
#ifndef __clang__
|
||||
#define ATTRIBUTES __gnu_inline__, __always_inline__, __artificial__
|
||||
#else
|
||||
#define ATTRIBUTES __gnu_inline__, __always_inline__
|
||||
#endif
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES)) mm_prefetch_buffer(char* WINPR_RESTRICT buffer,
|
||||
size_t num_bytes)
|
||||
{
|
||||
__m128i* buf = (__m128i*)buffer;
|
||||
|
||||
for (size_t i = 0; i < (num_bytes / sizeof(__m128i)); i += (CACHE_LINE_BYTES / sizeof(__m128i)))
|
||||
{
|
||||
_mm_prefetch((char*)(&buf[i]), _MM_HINT_NTA);
|
||||
}
|
||||
}
|
||||
|
||||
/* rfx_decode_ycbcr_to_rgb_sse2 code now resides in the primitives library. */
|
||||
/* rfx_encode_rgb_to_ycbcr_sse2 code now resides in the primitives library. */
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_quantization_decode_block_sse2(INT16* WINPR_RESTRICT buffer, const size_t buffer_size,
|
||||
const UINT32 factor)
|
||||
{
|
||||
__m128i* ptr = (__m128i*)buffer;
|
||||
const __m128i* buf_end = (__m128i*)(buffer + buffer_size);
|
||||
|
||||
if (factor == 0)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
const __m128i la = LOAD_SI128(ptr);
|
||||
const __m128i a = _mm_slli_epi16(la, WINPR_ASSERTING_INT_CAST(int, factor));
|
||||
|
||||
STORE_SI128(ptr, a);
|
||||
ptr++;
|
||||
} while (ptr < buf_end);
|
||||
}
|
||||
|
||||
static void rfx_quantization_decode_sse2(INT16* WINPR_RESTRICT buffer,
|
||||
const UINT32* WINPR_RESTRICT quantVals)
|
||||
{
|
||||
WINPR_ASSERT(buffer);
|
||||
WINPR_ASSERT(quantVals);
|
||||
|
||||
mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16));
|
||||
rfx_quantization_decode_block_sse2(&buffer[0], 1024, quantVals[8] - 1); /* HL1 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[1024], 1024, quantVals[7] - 1); /* LH1 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[2048], 1024, quantVals[9] - 1); /* HH1 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3072], 256, quantVals[5] - 1); /* HL2 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3328], 256, quantVals[4] - 1); /* LH2 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3584], 256, quantVals[6] - 1); /* HH2 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3840], 64, quantVals[2] - 1); /* HL3 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3904], 64, quantVals[1] - 1); /* LH3 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[3968], 64, quantVals[3] - 1); /* HH3 */
|
||||
rfx_quantization_decode_block_sse2(&buffer[4032], 64, quantVals[0] - 1); /* LL3 */
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_quantization_encode_block_sse2(INT16* WINPR_RESTRICT buffer, const unsigned buffer_size,
|
||||
const INT16 factor)
|
||||
{
|
||||
__m128i* ptr = (__m128i*)buffer;
|
||||
const __m128i* buf_end = (const __m128i*)(buffer + buffer_size);
|
||||
|
||||
if (factor == 0)
|
||||
return;
|
||||
|
||||
const __m128i half = _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(INT16, 1 << (factor - 1)));
|
||||
|
||||
do
|
||||
{
|
||||
const __m128i la = LOAD_SI128(ptr);
|
||||
__m128i a = _mm_add_epi16(la, half);
|
||||
a = _mm_srai_epi16(a, factor);
|
||||
STORE_SI128(ptr, a);
|
||||
ptr++;
|
||||
} while (ptr < buf_end);
|
||||
}
|
||||
|
||||
static void rfx_quantization_encode_sse2(INT16* WINPR_RESTRICT buffer,
|
||||
const UINT32* WINPR_RESTRICT quantization_values)
|
||||
{
|
||||
WINPR_ASSERT(buffer);
|
||||
WINPR_ASSERT(quantization_values);
|
||||
for (size_t x = 0; x < 10; x++)
|
||||
{
|
||||
WINPR_ASSERT(quantization_values[x] >= 6);
|
||||
WINPR_ASSERT(quantization_values[x] <= INT16_MAX + 6);
|
||||
}
|
||||
|
||||
mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16));
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[8] - 6)); /* HL1 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 1024, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[7] - 6)); /* LH1 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 2048, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[9] - 6)); /* HH1 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3072, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[5] - 6)); /* HL2 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3328, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[4] - 6)); /* LH2 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3584, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[6] - 6)); /* HH2 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3840, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[2] - 6)); /* HL3 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3904, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[1] - 6)); /* LH3 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 3968, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[3] - 6)); /* HH3 */
|
||||
rfx_quantization_encode_block_sse2(
|
||||
buffer + 4032, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[0] - 6)); /* LL3 */
|
||||
rfx_quantization_encode_block_sse2(buffer, 4096, 5);
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_decode_block_horiz_sse2(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h,
|
||||
INT16* WINPR_RESTRICT dst, size_t subband_width)
|
||||
{
|
||||
INT16* l_ptr = l;
|
||||
INT16* h_ptr = h;
|
||||
INT16* dst_ptr = dst;
|
||||
int first = 0;
|
||||
int last = 0;
|
||||
__m128i dst1;
|
||||
__m128i dst2;
|
||||
|
||||
for (size_t y = 0; y < subband_width; y++)
|
||||
{
|
||||
/* Even coefficients */
|
||||
for (size_t n = 0; n < subband_width; n += 8)
|
||||
{
|
||||
/* dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); */
|
||||
__m128i l_n = LOAD_SI128(l_ptr);
|
||||
__m128i h_n = LOAD_SI128(h_ptr);
|
||||
__m128i h_n_m = LOAD_SI128(h_ptr - 1);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
first = _mm_extract_epi16(h_n_m, 1);
|
||||
h_n_m = _mm_insert_epi16(h_n_m, first, 0);
|
||||
}
|
||||
|
||||
__m128i tmp_n = _mm_add_epi16(h_n, h_n_m);
|
||||
tmp_n = _mm_add_epi16(tmp_n, _mm_set1_epi16(1));
|
||||
tmp_n = _mm_srai_epi16(tmp_n, 1);
|
||||
const __m128i dst_n = _mm_sub_epi16(l_n, tmp_n);
|
||||
STORE_SI128(l_ptr, dst_n);
|
||||
l_ptr += 8;
|
||||
h_ptr += 8;
|
||||
}
|
||||
|
||||
l_ptr -= subband_width;
|
||||
h_ptr -= subband_width;
|
||||
|
||||
/* Odd coefficients */
|
||||
for (size_t n = 0; n < subband_width; n += 8)
|
||||
{
|
||||
/* dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); */
|
||||
__m128i h_n = LOAD_SI128(h_ptr);
|
||||
h_n = _mm_slli_epi16(h_n, 1);
|
||||
__m128i dst_n = LOAD_SI128(l_ptr);
|
||||
__m128i dst_n_p = LOAD_SI128(l_ptr + 1);
|
||||
|
||||
if (n == subband_width - 8)
|
||||
{
|
||||
last = _mm_extract_epi16(dst_n_p, 6);
|
||||
dst_n_p = _mm_insert_epi16(dst_n_p, last, 7);
|
||||
}
|
||||
|
||||
__m128i tmp_n = _mm_add_epi16(dst_n_p, dst_n);
|
||||
tmp_n = _mm_srai_epi16(tmp_n, 1);
|
||||
tmp_n = _mm_add_epi16(tmp_n, h_n);
|
||||
dst1 = _mm_unpacklo_epi16(dst_n, tmp_n);
|
||||
dst2 = _mm_unpackhi_epi16(dst_n, tmp_n);
|
||||
STORE_SI128(dst_ptr, dst1);
|
||||
STORE_SI128(dst_ptr + 8, dst2);
|
||||
l_ptr += 8;
|
||||
h_ptr += 8;
|
||||
dst_ptr += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_decode_block_vert_sse2(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h,
|
||||
INT16* WINPR_RESTRICT dst, size_t subband_width)
|
||||
{
|
||||
INT16* l_ptr = l;
|
||||
INT16* h_ptr = h;
|
||||
INT16* dst_ptr = dst;
|
||||
const size_t total_width = subband_width + subband_width;
|
||||
|
||||
/* Even coefficients */
|
||||
for (size_t n = 0; n < subband_width; n++)
|
||||
{
|
||||
for (size_t x = 0; x < total_width; x += 8)
|
||||
{
|
||||
/* dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); */
|
||||
const __m128i l_n = LOAD_SI128(l_ptr);
|
||||
const __m128i h_n = LOAD_SI128(h_ptr);
|
||||
__m128i tmp_n = _mm_add_epi16(h_n, _mm_set1_epi16(1));
|
||||
|
||||
if (n == 0)
|
||||
tmp_n = _mm_add_epi16(tmp_n, h_n);
|
||||
else
|
||||
{
|
||||
const __m128i h_n_m = LOAD_SI128(h_ptr - total_width);
|
||||
tmp_n = _mm_add_epi16(tmp_n, h_n_m);
|
||||
}
|
||||
|
||||
tmp_n = _mm_srai_epi16(tmp_n, 1);
|
||||
const __m128i dst_n = _mm_sub_epi16(l_n, tmp_n);
|
||||
STORE_SI128(dst_ptr, dst_n);
|
||||
l_ptr += 8;
|
||||
h_ptr += 8;
|
||||
dst_ptr += 8;
|
||||
}
|
||||
|
||||
dst_ptr += total_width;
|
||||
}
|
||||
|
||||
h_ptr = h;
|
||||
dst_ptr = dst + total_width;
|
||||
|
||||
/* Odd coefficients */
|
||||
for (size_t n = 0; n < subband_width; n++)
|
||||
{
|
||||
for (size_t x = 0; x < total_width; x += 8)
|
||||
{
|
||||
/* dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); */
|
||||
__m128i h_n = LOAD_SI128(h_ptr);
|
||||
__m128i dst_n_m = LOAD_SI128(dst_ptr - total_width);
|
||||
h_n = _mm_slli_epi16(h_n, 1);
|
||||
__m128i tmp_n = dst_n_m;
|
||||
|
||||
if (n == subband_width - 1)
|
||||
tmp_n = _mm_add_epi16(tmp_n, dst_n_m);
|
||||
else
|
||||
{
|
||||
const __m128i dst_n_p = LOAD_SI128(dst_ptr + total_width);
|
||||
tmp_n = _mm_add_epi16(tmp_n, dst_n_p);
|
||||
}
|
||||
|
||||
tmp_n = _mm_srai_epi16(tmp_n, 1);
|
||||
const __m128i dst_n = _mm_add_epi16(tmp_n, h_n);
|
||||
STORE_SI128(dst_ptr, dst_n);
|
||||
h_ptr += 8;
|
||||
dst_ptr += 8;
|
||||
}
|
||||
|
||||
dst_ptr += total_width;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_decode_block_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT idwt,
|
||||
size_t subband_width)
|
||||
{
|
||||
mm_prefetch_buffer((char*)idwt, 4ULL * subband_width * sizeof(INT16));
|
||||
/* Inverse DWT in horizontal direction, results in 2 sub-bands in L, H order in tmp buffer idwt.
|
||||
*/
|
||||
/* The 4 sub-bands are stored in HL(0), LH(1), HH(2), LL(3) order. */
|
||||
/* The lower part L uses LL(3) and HL(0). */
|
||||
/* The higher part H uses LH(1) and HH(2). */
|
||||
INT16* ll = buffer + 3ULL * subband_width * subband_width;
|
||||
INT16* hl = buffer;
|
||||
INT16* l_dst = idwt;
|
||||
rfx_dwt_2d_decode_block_horiz_sse2(ll, hl, l_dst, subband_width);
|
||||
INT16* lh = buffer + 1ULL * subband_width * subband_width;
|
||||
INT16* hh = buffer + 2ULL * subband_width * subband_width;
|
||||
INT16* h_dst = idwt + 2ULL * subband_width * subband_width;
|
||||
rfx_dwt_2d_decode_block_horiz_sse2(lh, hh, h_dst, subband_width);
|
||||
/* Inverse DWT in vertical direction, results are stored in original buffer. */
|
||||
rfx_dwt_2d_decode_block_vert_sse2(l_dst, h_dst, buffer, subband_width);
|
||||
}
|
||||
|
||||
static void rfx_dwt_2d_decode_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
|
||||
{
|
||||
WINPR_ASSERT(buffer);
|
||||
WINPR_ASSERT(dwt_buffer);
|
||||
|
||||
mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16));
|
||||
rfx_dwt_2d_decode_block_sse2(&buffer[3840], dwt_buffer, 8);
|
||||
rfx_dwt_2d_decode_block_sse2(&buffer[3072], dwt_buffer, 16);
|
||||
rfx_dwt_2d_decode_block_sse2(&buffer[0], dwt_buffer, 32);
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_encode_block_vert_sse2(INT16* WINPR_RESTRICT src, INT16* WINPR_RESTRICT l,
|
||||
INT16* WINPR_RESTRICT h, size_t subband_width)
|
||||
{
|
||||
const size_t total_width = subband_width << 1;
|
||||
|
||||
for (size_t n = 0; n < subband_width; n++)
|
||||
{
|
||||
for (size_t x = 0; x < total_width; x += 8)
|
||||
{
|
||||
__m128i src_2n = LOAD_SI128(src);
|
||||
__m128i src_2n_1 = LOAD_SI128(src + total_width);
|
||||
__m128i src_2n_2 = src_2n;
|
||||
|
||||
if (n < subband_width - 1)
|
||||
src_2n_2 = LOAD_SI128(src + 2ULL * total_width);
|
||||
|
||||
/* h[n] = (src[2n + 1] - ((src[2n] + src[2n + 2]) >> 1)) >> 1 */
|
||||
__m128i h_n = _mm_add_epi16(src_2n, src_2n_2);
|
||||
h_n = _mm_srai_epi16(h_n, 1);
|
||||
h_n = _mm_sub_epi16(src_2n_1, h_n);
|
||||
h_n = _mm_srai_epi16(h_n, 1);
|
||||
STORE_SI128(h, h_n);
|
||||
|
||||
__m128i h_n_m = h_n;
|
||||
if (n != 0)
|
||||
h_n_m = LOAD_SI128(h - total_width);
|
||||
|
||||
/* l[n] = src[2n] + ((h[n - 1] + h[n]) >> 1) */
|
||||
__m128i l_n = _mm_add_epi16(h_n_m, h_n);
|
||||
l_n = _mm_srai_epi16(l_n, 1);
|
||||
l_n = _mm_add_epi16(l_n, src_2n);
|
||||
STORE_SI128(l, l_n);
|
||||
src += 8;
|
||||
l += 8;
|
||||
h += 8;
|
||||
}
|
||||
|
||||
src += total_width;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_encode_block_horiz_sse2(INT16* WINPR_RESTRICT src, INT16* WINPR_RESTRICT l,
|
||||
INT16* WINPR_RESTRICT h, size_t subband_width)
|
||||
{
|
||||
for (size_t y = 0; y < subband_width; y++)
|
||||
{
|
||||
for (size_t n = 0; n < subband_width; n += 8)
|
||||
{
|
||||
/* The following 3 Set operations consumes more than half of the total DWT processing
|
||||
* time! */
|
||||
const INT16 src16 = (INT16)(((n + 8) == subband_width) ? src[14] : src[16]);
|
||||
__m128i src_2n =
|
||||
_mm_set_epi16(src[14], src[12], src[10], src[8], src[6], src[4], src[2], src[0]);
|
||||
__m128i src_2n_1 =
|
||||
_mm_set_epi16(src[15], src[13], src[11], src[9], src[7], src[5], src[3], src[1]);
|
||||
__m128i src_2n_2 =
|
||||
_mm_set_epi16(src16, src[14], src[12], src[10], src[8], src[6], src[4], src[2]);
|
||||
/* h[n] = (src[2n + 1] - ((src[2n] + src[2n + 2]) >> 1)) >> 1 */
|
||||
__m128i h_n = _mm_add_epi16(src_2n, src_2n_2);
|
||||
h_n = _mm_srai_epi16(h_n, 1);
|
||||
h_n = _mm_sub_epi16(src_2n_1, h_n);
|
||||
h_n = _mm_srai_epi16(h_n, 1);
|
||||
STORE_SI128(h, h_n);
|
||||
__m128i h_n_m = LOAD_SI128(h - 1);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
int first = _mm_extract_epi16(h_n_m, 1);
|
||||
h_n_m = _mm_insert_epi16(h_n_m, first, 0);
|
||||
}
|
||||
|
||||
/* l[n] = src[2n] + ((h[n - 1] + h[n]) >> 1) */
|
||||
__m128i l_n = _mm_add_epi16(h_n_m, h_n);
|
||||
l_n = _mm_srai_epi16(l_n, 1);
|
||||
l_n = _mm_add_epi16(l_n, src_2n);
|
||||
STORE_SI128(l, l_n);
|
||||
src += 16;
|
||||
l += 8;
|
||||
h += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void __attribute__((ATTRIBUTES))
|
||||
rfx_dwt_2d_encode_block_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt,
|
||||
size_t subband_width)
|
||||
{
|
||||
mm_prefetch_buffer((char*)dwt, 4ULL * subband_width * sizeof(INT16));
|
||||
/* DWT in vertical direction, results in 2 sub-bands in L, H order in tmp buffer dwt. */
|
||||
INT16* l_src = dwt;
|
||||
INT16* h_src = dwt + 2ULL * subband_width * subband_width;
|
||||
rfx_dwt_2d_encode_block_vert_sse2(buffer, l_src, h_src, subband_width);
|
||||
/* DWT in horizontal direction, results in 4 sub-bands in HL(0), LH(1), HH(2), LL(3) order,
|
||||
* stored in original buffer. */
|
||||
/* The lower part L generates LL(3) and HL(0). */
|
||||
/* The higher part H generates LH(1) and HH(2). */
|
||||
INT16* ll = buffer + 3ULL * subband_width * subband_width;
|
||||
INT16* hl = buffer;
|
||||
INT16* lh = buffer + 1ULL * subband_width * subband_width;
|
||||
INT16* hh = buffer + 2ULL * subband_width * subband_width;
|
||||
rfx_dwt_2d_encode_block_horiz_sse2(l_src, ll, hl, subband_width);
|
||||
rfx_dwt_2d_encode_block_horiz_sse2(h_src, lh, hh, subband_width);
|
||||
}
|
||||
|
||||
static void rfx_dwt_2d_encode_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer)
|
||||
{
|
||||
WINPR_ASSERT(buffer);
|
||||
WINPR_ASSERT(dwt_buffer);
|
||||
|
||||
mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16));
|
||||
rfx_dwt_2d_encode_block_sse2(buffer, dwt_buffer, 32);
|
||||
rfx_dwt_2d_encode_block_sse2(buffer + 3072, dwt_buffer, 16);
|
||||
rfx_dwt_2d_encode_block_sse2(buffer + 3840, dwt_buffer, 8);
|
||||
}
|
||||
#endif
|
||||
|
||||
void rfx_init_sse2_int(RFX_CONTEXT* WINPR_RESTRICT context)
|
||||
{
|
||||
#if defined(SSE_AVX_INTRINSICS_ENABLED)
|
||||
WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations");
|
||||
PROFILER_RENAME(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode_sse2")
|
||||
PROFILER_RENAME(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode_sse2")
|
||||
PROFILER_RENAME(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode_sse2")
|
||||
PROFILER_RENAME(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode_sse2")
|
||||
context->quantization_decode = rfx_quantization_decode_sse2;
|
||||
context->quantization_encode = rfx_quantization_encode_sse2;
|
||||
context->dwt_2d_decode = rfx_dwt_2d_decode_sse2;
|
||||
context->dwt_2d_encode = rfx_dwt_2d_encode_sse2;
|
||||
#else
|
||||
WINPR_UNUSED(context);
|
||||
WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE2 intrinsics not available");
|
||||
#endif
|
||||
}
|
||||
39
third_party/FreeRDP/libfreerdp/codec/sse/rfx_sse2.h
vendored
Normal file
39
third_party/FreeRDP/libfreerdp/codec/sse/rfx_sse2.h
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* RemoteFX Codec Library - SSE2 Optimizations
|
||||
*
|
||||
* Copyright 2011 Stephen Erisman
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_LIB_CODEC_RFX_SSE2_H
|
||||
#define FREERDP_LIB_CODEC_RFX_SSE2_H
|
||||
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
#include <freerdp/codec/rfx.h>
|
||||
#include <freerdp/api.h>
|
||||
|
||||
FREERDP_LOCAL void rfx_init_sse2_int(RFX_CONTEXT* WINPR_RESTRICT context);
|
||||
|
||||
static inline void rfx_init_sse2(RFX_CONTEXT* WINPR_RESTRICT context)
|
||||
{
|
||||
if (!IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) ||
|
||||
!IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
|
||||
return;
|
||||
|
||||
rfx_init_sse2_int(context);
|
||||
}
|
||||
|
||||
#endif /* FREERDP_LIB_CODEC_RFX_SSE2_H */
|
||||
Reference in New Issue
Block a user