File: GSDrawScanlineCodeGenerator.cpp

package info (click to toggle)
pcsx2 1.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,172 kB
  • ctags: 40,348
  • sloc: cpp: 232,892; ansic: 22,912; asm: 2,273; lisp: 1,346; sh: 561; perl: 253; makefile: 113; xml: 69
file content (357 lines) | stat: -rw-r--r-- 6,884 bytes parent folder | download | duplicates (5)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 *	Copyright (C) 2007-2009 Gabest
 *	http://www.gabest.org
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA USA.
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#include "stdafx.h"
#include "GSDrawScanlineCodeGenerator.h"

#if _M_SSE >= 0x501

__aligned(const uint8, 8) GSDrawScanlineCodeGenerator::m_test[16][8] =
{
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
	{0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00},
	{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00},
	{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00},
	{0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};

const GSVector8 GSDrawScanlineCodeGenerator::m_log2_coef[4] = 
{
	GSVector8(0.204446009836232697516f),
	GSVector8(-1.04913055217340124191f),
	GSVector8(2.28330284476918490682f),
	GSVector8(1.0f),
};

#else

const GSVector4i GSDrawScanlineCodeGenerator::m_test[8] =
{
	GSVector4i::zero(),
	GSVector4i(0xffffffff, 0x00000000, 0x00000000, 0x00000000),
	GSVector4i(0xffffffff, 0xffffffff, 0x00000000, 0x00000000),
	GSVector4i(0xffffffff, 0xffffffff, 0xffffffff, 0x00000000),
	GSVector4i(0x00000000, 0xffffffff, 0xffffffff, 0xffffffff),
	GSVector4i(0x00000000, 0x00000000, 0xffffffff, 0xffffffff),
	GSVector4i(0x00000000, 0x00000000, 0x00000000, 0xffffffff),
	GSVector4i::zero(),
};

const GSVector4 GSDrawScanlineCodeGenerator::m_log2_coef[4] = 
{
	GSVector4(0.204446009836232697516f),
	GSVector4(-1.04913055217340124191f),
	GSVector4(2.28330284476918490682f),
	GSVector4(1.0f),
};

#endif

GSDrawScanlineCodeGenerator::GSDrawScanlineCodeGenerator(void* param, uint64 key, void* code, size_t maxsize)
	: GSCodeGenerator(code, maxsize)
	, m_local(*(GSScanlineLocalData*)param)
{
	m_sel.key = key;

	Generate();
}

#if _M_SSE >= 0x501

void GSDrawScanlineCodeGenerator::modulate16(const Ymm& a, const Operand& f, int shift)
{
	if(shift == 0)
	{
		vpmulhrsw(a, f);
	}
	else
	{
		vpsllw(a, (uint8)(shift + 1));
		vpmulhw(a, f);
	}
}

void GSDrawScanlineCodeGenerator::lerp16(const Ymm& a, const Ymm& b, const Ymm& f, int shift)
{
	vpsubw(a, b);
	modulate16(a, f, shift);
	vpaddw(a, b);
}

void GSDrawScanlineCodeGenerator::lerp16_4(const Ymm& a, const Ymm& b, const Ymm& f)
{
	vpsubw(a, b);
	vpmullw(a, f);
	vpsraw(a, 4);
	vpaddw(a, b);
}

void GSDrawScanlineCodeGenerator::mix16(const Ymm& a, const Ymm& b, const Ymm& temp)
{
	vpblendw(a, b, 0xaa);
}

void GSDrawScanlineCodeGenerator::clamp16(const Ymm& a, const Ymm& temp)
{
	vpackuswb(a, a);
	vpermq(a, a, _MM_SHUFFLE(3, 1, 2, 0)); // this sucks
	vpmovzxbw(a, a);
}

void GSDrawScanlineCodeGenerator::alltrue()
{
	vpmovmskb(eax, ymm7);
	cmp(eax, 0xffffffff);
	je("step", T_NEAR);
}

void GSDrawScanlineCodeGenerator::blend(const Ymm& a, const Ymm& b, const Ymm& mask)
{
	vpand(b, mask);
	vpandn(mask, a);
	vpor(a, b, mask);
}

void GSDrawScanlineCodeGenerator::blendr(const Ymm& b, const Ymm& a, const Ymm& mask)
{
	vpand(b, mask);
	vpandn(mask, a);
	vpor(b, mask);
}

void GSDrawScanlineCodeGenerator::blend8(const Ymm& a, const Ymm& b)
{
	vpblendvb(a, a, b, xmm0);
}

void GSDrawScanlineCodeGenerator::blend8r(const Ymm& b, const Ymm& a)
{
	vpblendvb(b, a, b, xmm0);
}

#else

void GSDrawScanlineCodeGenerator::modulate16(const Xmm& a, const Operand& f, int shift)
{
	#if _M_SSE >= 0x500

	if(shift == 0)
	{
		vpmulhrsw(a, f);
	}
	else
	{
		vpsllw(a, shift + 1);
		vpmulhw(a, f);
	}

	#else

	if(shift == 0 && m_cpu.has(util::Cpu::tSSSE3))
	{
		pmulhrsw(a, f);
	}
	else
	{
		psllw(a, shift + 1);
		pmulhw(a, f);
	}

	#endif
}

void GSDrawScanlineCodeGenerator::lerp16(const Xmm& a, const Xmm& b, const Xmm& f, int shift)
{
	#if _M_SSE >= 0x500

	vpsubw(a, b);
	modulate16(a, f, shift);
	vpaddw(a, b);

	#else

	psubw(a, b);
	modulate16(a, f, shift);
	paddw(a, b);

	#endif
}

void GSDrawScanlineCodeGenerator::lerp16_4(const Xmm& a, const Xmm& b, const Xmm& f)
{
	#if _M_SSE >= 0x500

	vpsubw(a, b);
	vpmullw(a, f);
	vpsraw(a, 4);
	vpaddw(a, b);

	#else

	psubw(a, b);
	pmullw(a, f);
	psraw(a, 4);
	paddw(a, b);

	#endif
}

void GSDrawScanlineCodeGenerator::mix16(const Xmm& a, const Xmm& b, const Xmm& temp)
{
	#if _M_SSE >= 0x500

	vpblendw(a, b, 0xaa);
	
	#elif _M_SSE >= 0x401

	pblendw(a, b, 0xaa);

	#else

	pcmpeqd(temp, temp);
	psrld(temp, 16);
	pand(a, temp);
	pandn(temp, b);
	por(a, temp);
	
	#endif
}

void GSDrawScanlineCodeGenerator::clamp16(const Xmm& a, const Xmm& temp)
{
	#if _M_SSE >= 0x500
	
	vpackuswb(a, a);
	vpmovzxbw(a, a);

	#elif _M_SSE >= 0x401

	packuswb(a, a);
	pmovzxbw(a, a);

	#else

	packuswb(a, a);
	pxor(temp, temp);
	punpcklbw(a, temp);

	#endif
}

void GSDrawScanlineCodeGenerator::alltrue()
{
	#if _M_SSE >= 0x500
	
	vpmovmskb(eax, xmm7);
	cmp(eax, 0xffff);
	je("step", T_NEAR);

	#else

	pmovmskb(eax, xmm7);
	cmp(eax, 0xffff);
	je("step", T_NEAR);

	#endif
}

void GSDrawScanlineCodeGenerator::blend(const Xmm& a, const Xmm& b, const Xmm& mask)
{
	#if _M_SSE >= 0x500

	vpand(b, mask);
	vpandn(mask, a);
	vpor(a, b, mask);

	#else

	pand(b, mask);
	pandn(mask, a);
	por(b, mask);
	movdqa(a, b);

	#endif
}

void GSDrawScanlineCodeGenerator::blendr(const Xmm& b, const Xmm& a, const Xmm& mask)
{
	#if _M_SSE >= 0x500

	vpand(b, mask);
	vpandn(mask, a);
	vpor(b, mask);

	#else

	pand(b, mask);
	pandn(mask, a);
	por(b, mask);

	#endif
}

void GSDrawScanlineCodeGenerator::blend8(const Xmm& a, const Xmm& b)
{
	#if _M_SSE >= 0x500
	
	vpblendvb(a, a, b, xmm0);

	#elif _M_SSE >= 0x401
	
	pblendvb(a, b);

	#else

	blend(a, b, xmm0);

	#endif
}

void GSDrawScanlineCodeGenerator::blend8r(const Xmm& b, const Xmm& a)
{
	#if _M_SSE >= 0x500
	
	vpblendvb(b, a, b, xmm0);

	#elif _M_SSE >= 0x401

	pblendvb(a, b);
	movdqa(b, a);

	#else

	blendr(b, a, xmm0);

	#endif
}

#endif