summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/video/rgbsse.c
blob: b4e3701a1878aa6731f11cb35e2d8353cc015485 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// license:BSD-3-Clause
// copyright-holders:Vas Crabb, Ryan Holtz
/***************************************************************************

    rgbsse.c

    SSE optimized RGB utilities.

    WARNING: This code assumes SSE2 or greater capability.

***************************************************************************/

#if defined(__SSE2__) || defined(_MSC_VER)

#include "emu.h"
#include <emmintrin.h>
#include "rgbsse.h"

/***************************************************************************
    HIGHER LEVEL OPERATIONS
***************************************************************************/

void rgbaint_t::blend(const rgbaint_t& other, UINT8 factor)
{
	m_value = _mm_unpacklo_epi16(m_value, other.m_value);
	m_value = _mm_madd_epi16(m_value, *(__m128i *)&rgbsse_statics.scale_table[factor][0]);
	m_value = _mm_srli_epi32(m_value, 8);
}

void rgbaint_t::scale_and_clamp(const rgbaint_t& scale)
{
	mul(scale);
	shr(8);
	min(255);
	max(0);
}

void rgbaint_t::scale_imm_and_clamp(const INT32 scale)
{
	mul_imm(scale);
	shr(8);
	min(255);
	max(0);
}

void rgbaint_t::scale_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other, const rgbaint_t& scale2)
{
	rgbaint_t color2(other);
	color2.mul(scale2);

	mul(scale);
	add(color2);
	shr(8);
	min(255);
	max(0);
}

void rgbaint_t::scale_imm_add_and_clamp(const INT32 scale, const rgbaint_t& other)
{
	mul_imm(scale);
	add(other);
	shr(8);
	min(255);
	max(0);
}

void rgbaint_t::scale_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other)
{
	mul(scale);
	add(other);
	shr(8);
	min(255);
	max(0);
}

#endif // defined(__SSE2__) || defined(_MSC_VER)