summaryrefslogtreecommitdiff
path: root/src/mesa/x86/rtasm/x86sse.h
blob: 8d48e356479df7608777c296506f793abc673eaf (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
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

#ifndef _X86SSE_H_
#define _X86SSE_H_

#if defined(USE_X86_ASM)

#include "glheader.h"

/* It is up to the caller to ensure that instructions issued are
 * suitable for the host cpu.  There are no checks made in this module
 * for mmx/sse/sse2 support on the cpu.
 */
struct x86_reg {
   GLuint file:3;
   GLuint idx:3;
   GLuint mod:2;		/* mod_REG if this is just a register */
   GLint  disp:24;		/* only +/- 23bits of offset - should be enough... */
};

struct x86_function {
   GLubyte *store;
   GLubyte *csr;
   GLuint stack_offset;
   GLint need_emms;
};

enum x86_reg_file {
   file_REG32,
   file_MMX,
   file_XMM
};

/* Values for mod field of modr/m byte
 */
enum x86_reg_mod {
   mod_INDIRECT,
   mod_DISP8,
   mod_DISP32,
   mod_REG
};

enum x86_reg_name {
   reg_AX,
   reg_CX,
   reg_DX,
   reg_BX,
   reg_SP,
   reg_BP,
   reg_SI,
   reg_DI
};


enum x86_cc {
   cc_O,			/* overflow */
   cc_NO,			/* not overflow */
   cc_NAE,			/* not above or equal / carry */
   cc_AE,			/* above or equal / not carry */
   cc_E,			/* equal / zero */
   cc_NE			/* not equal / not zero */
};

#define cc_Z  cc_E
#define cc_NZ cc_NE

/* Begin/end/retreive function creation:
 */


void x86_init_func( struct x86_function *p );
void x86_release_func( struct x86_function *p );
void (*x86_get_func( struct x86_function *p ))( void );



/* Create and manipulate registers and regmem values:
 */
struct x86_reg x86_make_reg( enum x86_reg_file file,
			     enum x86_reg_name idx );

struct x86_reg x86_make_disp( struct x86_reg reg,
			      GLint disp );

struct x86_reg x86_deref( struct x86_reg reg );

struct x86_reg x86_get_base_reg( struct x86_reg reg );




/* Labels, jumps and fixup:
 */
GLubyte *x86_get_label( struct x86_function *p );

void x86_jcc( struct x86_function *p,
	      enum x86_cc cc,
	      GLubyte *label );

/* Always use a 32bit offset for forward jumps:
 */
GLubyte *x86_jcc_forward( struct x86_function *p,
			  enum x86_cc cc );

/* Fixup offset from forward jump:
 */
void x86_fixup_fwd_jump( struct x86_function *p,
			 GLubyte *fixup );

void x86_push( struct x86_function *p,
	       struct x86_reg reg );

void x86_pop( struct x86_function *p,
	      struct x86_reg reg );

void x86_inc( struct x86_function *p,
	      struct x86_reg reg );

void x86_dec( struct x86_function *p,
	      struct x86_reg reg );

void x86_ret( struct x86_function *p );

void mmx_emms( struct x86_function *p );

void x86_mov( struct x86_function *p,
	      struct x86_reg dst,
	      struct x86_reg src );

void x86_xor( struct x86_function *p,
	      struct x86_reg dst,
	      struct x86_reg src );

void x86_cmp( struct x86_function *p,
	      struct x86_reg dst,
	      struct x86_reg src );

void sse2_movd( struct x86_function *p,
		struct x86_reg dst,
		struct x86_reg src );

void mmx_movd( struct x86_function *p,
	       struct x86_reg dst,
	       struct x86_reg src );

void mmx_movq( struct x86_function *p,
	       struct x86_reg dst,
	       struct x86_reg src );

void sse_movss( struct x86_function *p,
		struct x86_reg dst,
		struct x86_reg src );

void sse_movaps( struct x86_function *p,
		 struct x86_reg dst,
		 struct x86_reg src );

void sse_movups( struct x86_function *p,
		 struct x86_reg dst,
		 struct x86_reg src );

void sse_movhps( struct x86_function *p,
		 struct x86_reg dst,
		 struct x86_reg src );

void sse_movlps( struct x86_function *p,
		 struct x86_reg dst,
		 struct x86_reg src );

/* SSE operations often only have one format, with dest constrained to
 * be a register:
 */
void sse_mulps( struct x86_function *p,
		struct x86_reg dst,
		struct x86_reg src );

void sse_addps( struct x86_function *p,
		struct x86_reg dst,
		struct x86_reg src );

void sse_movhlps( struct x86_function *p,
		  struct x86_reg dst,
		  struct x86_reg src );

void sse_movlhps( struct x86_function *p,
		  struct x86_reg dst,
		  struct x86_reg src );

void sse2_cvtps2dq( struct x86_function *p,
		    struct x86_reg dst,
		    struct x86_reg src );

void sse2_packssdw( struct x86_function *p,
		    struct x86_reg dst,
		    struct x86_reg src );

void sse2_packsswb( struct x86_function *p,
		    struct x86_reg dst,
		    struct x86_reg src );

void sse2_packuswb( struct x86_function *p,
		    struct x86_reg dst,
		    struct x86_reg src );

void sse_cvtps2pi( struct x86_function *p,
		   struct x86_reg dst,
		   struct x86_reg src );

void mmx_packssdw( struct x86_function *p,
		   struct x86_reg dst,
		   struct x86_reg src );

void mmx_packuswb( struct x86_function *p,
		   struct x86_reg dst,
		   struct x86_reg src );


/* Load effective address:
 */
void x86_lea( struct x86_function *p,
	      struct x86_reg dst,
	      struct x86_reg src );

void x86_test( struct x86_function *p,
	       struct x86_reg dst,
	       struct x86_reg src );

/* Perform a reduced swizzle in a single sse instruction:
 */
void sse2_pshufd( struct x86_function *p,
		  struct x86_reg dest,
		  struct x86_reg arg0,
		  GLubyte x,
		  GLubyte y,
		  GLubyte z,
		  GLubyte w );


/* Shufps can also be used to implement a reduced swizzle when dest ==
 * arg0.
 */
void sse_shufps( struct x86_function *p,
		 struct x86_reg dest,
		 struct x86_reg arg0,
		 GLubyte x,
		 GLubyte y,
		 GLubyte z,
		 GLubyte w );


/* Retreive a reference to one of the function arguments, taking into
 * account any push/pop activity:
 */
struct x86_reg x86_fn_arg( struct x86_function *p,
			   GLuint arg );

#endif
#endif