aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpu_unai/gpu_inner_blend.h
blob: ce439d3bf766a5267ed25f57663fd98b760efa6c (plain)
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
/***************************************************************************
*   Copyright (C) 2010 PCSX4ALL Team                                      *
*   Copyright (C) 2010 Unai                                               *
*                                                                         *
*   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 of the License, 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 this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
***************************************************************************/

#ifndef _OP_BLEND_H_
#define _OP_BLEND_H_

//  GPU Blending operations functions

#ifdef __arm__
#define gpuBlending00(uSrc,uDst) \
{ \
	asm ("and  %[src], %[src], %[msk]\n" \
	     "and  %[dst], %[dst], %[msk]\n" \
	     "add  %[src], %[dst], %[src]\n" \
	     "mov  %[src], %[src], lsr #1\n" \
	 : [src] "=&r" (uSrc), [dst] "=&r" (uDst) : "0" (uSrc), "1" (uDst), [msk] "r" (uMsk)); \
}
#else
#define gpuBlending00(uSrc,uDst) \
{ \
	uSrc = (((uDst & uMsk) + (uSrc & uMsk)) >> 1); \
}
#endif

//	1.0 x Back + 1.0 x Forward
#ifdef __arm__
#define gpuBlending01(uSrc,uDst) \
{ \
	u32 st,dt,out; \
	asm ("and    %[dt],  %[dst],   #0x7C00\n" \
	     "and    %[st],  %[src],   #0x7C00\n" \
	     "add    %[out], %[dt],    %[st]  \n" \
	     "cmp    %[out], #0x7C00          \n" \
	     "movhi  %[out], #0x7C00          \n" \
	     "and    %[dt],  %[dst],   #0x03E0\n" \
	     "and    %[st],  %[src],   #0x03E0\n" \
	     "add    %[dt],  %[dt],    %[st]  \n" \
	     "cmp    %[dt],  #0x03E0          \n" \
	     "movhi  %[dt],  #0x03E0          \n" \
	     "orr    %[out], %[out],   %[dt]  \n" \
	     "and    %[dt],  %[dst],   #0x001F\n" \
	     "and    %[st],  %[src],   #0x001F\n" \
	     "add    %[dt],  %[dt],    %[st]  \n" \
	     "cmp    %[dt],  #0x001F          \n" \
	     "movhi  %[dt],  #0x001F          \n" \
	     "orr    %[src], %[out],  %[dt]  \n" \
	 : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
	 : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
}
#else
#define gpuBlending01(uSrc,uDst) \
{ \
	u16 rr, gg, bb; \
	bb = (uDst & 0x7C00) + (uSrc & 0x7C00);   if (bb > 0x7C00)  bb = 0x7C00; \
	gg = (uDst & 0x03E0) + (uSrc & 0x03E0);   if (gg > 0x03E0)  gg = 0x03E0;  bb |= gg; \
	rr = (uDst & 0x001F) + (uSrc & 0x001F);   if (rr > 0x001F)  rr = 0x001F;  bb |= rr; \
	uSrc = bb; \
}
#endif

//	1.0 x Back - 1.0 x Forward	*/
#ifdef __arm__
#define gpuBlending02(uSrc,uDst) \
{ \
	u32 st,dt,out; \
	asm ("and    %[dt],  %[dst],   #0x7C00\n" \
	     "and    %[st],  %[src],   #0x7C00\n" \
	     "subs   %[out], %[dt],    %[st]  \n" \
	     "movmi  %[out], #0x0000          \n" \
	     "and    %[dt],  %[dst],   #0x03E0\n" \
	     "and    %[st],  %[src],   #0x03E0\n" \
	     "subs   %[dt],  %[dt],    %[st]  \n" \
	     "orrpl  %[out], %[out],   %[dt]  \n" \
	     "and    %[dt],  %[dst],   #0x001F\n" \
	     "and    %[st],  %[src],   #0x001F\n" \
	     "subs   %[dt],  %[dt],    %[st]  \n" \
	     "orrpl  %[out], %[out],   %[dt]  \n" \
	     "mov    %[src], %[out]           \n" \
	 : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
	 : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
}

int btest(int s, int d)
{
	gpuBlending02(s, d);
	return s;
}
#else
#define gpuBlending02(uSrc,uDst) \
{ \
	s32 rr, gg, bb; \
	bb = (uDst & 0x7C00) - (uSrc & 0x7C00);   if (bb < 0)  bb  =  0; \
	gg = (uDst & 0x03E0) - (uSrc & 0x03E0);   if (gg > 0)  bb |= gg; \
	rr = (uDst & 0x001F) - (uSrc & 0x001F);   if (rr > 0)  bb |= rr; \
	uSrc = bb; \
}
#endif

//	1.0 x Back + 0.25 x Forward	*/
#ifdef __arm__
#define gpuBlending03(uSrc,uDst) \
{ \
	u32 st,dt,out; \
	asm ("mov    %[src], %[src],   lsr #2 \n" \
	     "and    %[dt],  %[dst],   #0x7C00\n" \
	     "and    %[st],  %[src],   #0x1C00\n" \
	     "add    %[out], %[dt],    %[st]  \n" \
	     "cmp    %[out], #0x7C00          \n" \
	     "movhi  %[out], #0x7C00          \n" \
	     "and    %[dt],  %[dst],   #0x03E0\n" \
	     "and    %[st],  %[src],   #0x00E0\n" \
	     "add    %[dt],  %[dt],    %[st]  \n" \
	     "cmp    %[dt],  #0x03E0          \n" \
	     "movhi  %[dt],  #0x03E0          \n" \
	     "orr    %[out], %[out],   %[dt]  \n" \
	     "and    %[dt],  %[dst],   #0x001F\n" \
	     "and    %[st],  %[src],   #0x0007\n" \
	     "add    %[dt],  %[dt],    %[st]  \n" \
	     "cmp    %[dt],  #0x001F          \n" \
	     "movhi  %[dt],  #0x001F          \n" \
	     "orr    %[src], %[out],   %[dt]  \n" \
	 : [src] "=r" (uSrc), [st] "=&r" (st), [dt] "=&r" (dt), [out] "=&r" (out) \
	 : [dst] "r" (uDst), "0" (uSrc) : "cc"); \
}
#else
#define gpuBlending03(uSrc,uDst) \
{ \
	u16 rr, gg, bb; \
	uSrc >>= 2; \
	bb = (uDst & 0x7C00) + (uSrc & 0x1C00);   if (bb > 0x7C00)  bb = 0x7C00; \
	gg = (uDst & 0x03E0) + (uSrc & 0x00E0);   if (gg > 0x03E0)  gg = 0x03E0;  bb |= gg; \
	rr = (uDst & 0x001F) + (uSrc & 0x0007);   if (rr > 0x001F)  rr = 0x001F;  bb |= rr; \
	uSrc = bb; \
}
#endif

#endif  //_OP_BLEND_H_