gallium: use execmem for PPC code, grow instruction buffer as needed
[mesa.git] / src / gallium / auxiliary / rtasm / rtasm_ppc.h
1 /**************************************************************************
2 *
3 * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 **************************************************************************/
23
24 /**
25 * PPC code generation.
26 * \author Brian Paul
27 */
28
29
30 #ifndef RTASM_PPC_H
31 #define RTASM_PPC_H
32
33
34 #include "pipe/p_compiler.h"
35
36
37 #define PPC_INST_SIZE 4 /**< 4 bytes / instruction */
38
39 #define PPC_NUM_REGS 32
40 #define PPC_NUM_FP_REGS 32
41 #define PPC_NUM_VEC_REGS 32
42
43 /** Stack pointer register */
44 #define PPC_REG_SP 1
45
46 /** Branch conditions */
47 #define BRANCH_COND_ALWAYS 0x14 /* binary 1z1zz (z=ignored) */
48
49 /** Branch hints */
50 #define BRANCH_HINT_SUB_RETURN 0x0 /* binary 00 */
51
52
53 struct ppc_function
54 {
55 uint32_t *store; /**< instruction buffer */
56 uint num_inst;
57 uint max_inst;
58 uint32_t reg_used; /** used/free general-purpose registers bitmask */
59 uint32_t fp_used; /** used/free floating point registers bitmask */
60 uint32_t vec_used; /** used/free vector registers bitmask */
61 };
62
63
64
65 extern void ppc_init_func(struct ppc_function *p, unsigned max_inst);
66 extern void ppc_release_func(struct ppc_function *p);
67 extern uint ppc_num_instructions(const struct ppc_function *p);
68 extern void (*ppc_get_func( struct ppc_function *p ))( void );
69 extern void ppc_dump_func(const struct ppc_function *p);
70
71 extern int ppc_reserve_register(struct ppc_function *p, int reg);
72 extern int ppc_allocate_register(struct ppc_function *p);
73 extern void ppc_release_register(struct ppc_function *p, int reg);
74 extern int ppc_allocate_fp_register(struct ppc_function *p);
75 extern void ppc_release_fp_register(struct ppc_function *p, int reg);
76 extern int ppc_allocate_vec_register(struct ppc_function *p);
77 extern void ppc_release_vec_register(struct ppc_function *p, int reg);
78
79
80
81 /**
82 ** float vector arithmetic
83 **/
84
85 /** vector float add */
86 extern void
87 ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB);
88
89 /** vector float substract */
90 extern void
91 ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB);
92
93 /** vector float min */
94 extern void
95 ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB);
96
97 /** vector float max */
98 extern void
99 ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB);
100
101 /** vector float mult add: vD = vA * vB + vC */
102 extern void
103 ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
104
105 /** vector float negative mult subtract: vD = vA - vB * vC */
106 extern void
107 ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
108
109 /** vector float compare greater than */
110 extern void
111 ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
112
113 /** vector float compare greater than or equal to */
114 extern void
115 ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB);
116
117 /** vector float compare equal */
118 extern void
119 ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
120
121 /** vector float 2^x */
122 extern void
123 ppc_vexptefp(struct ppc_function *p, uint vD, uint vB);
124
125 /** vector float log2(x) */
126 extern void
127 ppc_vlogefp(struct ppc_function *p, uint vD, uint vB);
128
129 /** vector float reciprocol */
130 extern void
131 ppc_vrefp(struct ppc_function *p, uint vD, uint vB);
132
133 /** vector float reciprocol sqrt estimate */
134 extern void
135 ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB);
136
137 /** vector float round to negative infinity */
138 extern void
139 ppc_vrfim(struct ppc_function *p, uint vD, uint vB);
140
141 /** vector float round to positive infinity */
142 extern void
143 ppc_vrfip(struct ppc_function *p, uint vD, uint vB);
144
145 /** vector float round to nearest int */
146 extern void
147 ppc_vrfin(struct ppc_function *p, uint vD, uint vB);
148
149 /** vector float round to int toward zero */
150 extern void
151 ppc_vrfiz(struct ppc_function *p, uint vD, uint vB);
152
153
154 /** vector store: store vR at mem[vA+vB] */
155 extern void
156 ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB);
157
158 /** vector load: vR = mem[vA+vB] */
159 extern void
160 ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB);
161
162 /** load vector element word: vR = mem_word[vA+vB] */
163 extern void
164 ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB);
165
166
167
168 /**
169 ** vector bitwise operations
170 **/
171
172
173 /** vector and */
174 extern void
175 ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB);
176
177 /** vector and complement */
178 extern void
179 ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB);
180
181 /** vector or */
182 extern void
183 ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB);
184
185 /** vector nor */
186 extern void
187 ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB);
188
189 /** vector xor */
190 extern void
191 ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB);
192
193 /** Pseudo-instruction: vector move */
194 extern void
195 ppc_vmove(struct ppc_function *p, uint vD, uint vA);
196
197 /** Set vector register to {0,0,0,0} */
198 extern void
199 ppc_vzero(struct ppc_function *p, uint vr);
200
201
202
203 /**
204 ** Vector shuffle / select / splat / etc
205 **/
206
207 /** vector permute */
208 extern void
209 ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
210
211 /** vector select */
212 extern void
213 ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
214
215 /** vector splat byte */
216 extern void
217 ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm);
218
219 /** vector splat half word */
220 extern void
221 ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm);
222
223 /** vector splat word */
224 extern void
225 ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm);
226
227 /** vector splat signed immediate word */
228 extern void
229 ppc_vspltisw(struct ppc_function *p, uint vD, int imm);
230
231 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
232 extern void
233 ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB);
234
235
236
237 /**
238 ** scalar arithmetic
239 **/
240
241 extern void
242 ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb);
243
244 extern void
245 ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm);
246
247 extern void
248 ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb);
249
250 extern void
251 ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm);
252
253 extern void
254 ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb);
255
256 extern void
257 ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm);
258
259 extern void
260 ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb);
261
262 extern void
263 ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm);
264
265 extern void
266 ppc_mr(struct ppc_function *p, uint rt, uint ra);
267
268 extern void
269 ppc_li(struct ppc_function *p, uint rt, int imm);
270
271 extern void
272 ppc_lis(struct ppc_function *p, uint rt, int imm);
273
274 extern void
275 ppc_load_int(struct ppc_function *p, uint rt, int imm);
276
277
278
279 /**
280 ** scalar load/store
281 **/
282
283 extern void
284 ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d);
285
286 extern void
287 ppc_stw(struct ppc_function *p, uint rs, uint ra, int d);
288
289 extern void
290 ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d);
291
292
293
294 /**
295 ** Float (non-vector) arithmetic
296 **/
297
298 extern void
299 ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb);
300
301 extern void
302 ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb);
303
304 extern void
305 ppc_fctiwz(struct ppc_function *p, uint rt, uint ra);
306
307 extern void
308 ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset);
309
310 extern void
311 ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb);
312
313
314
315 /**
316 ** branch instructions
317 **/
318
319 extern void
320 ppc_blr(struct ppc_function *p);
321
322 void
323 ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg);
324
325 extern void
326 ppc_return(struct ppc_function *p);
327
328
329 #endif /* RTASM_PPC_H */