561e139bce7f219755ea3d4ccf503924ac0851d9
[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 void (*ppc_get_func( struct ppc_function *p ))( void );
68 extern void ppc_dump_func(const struct ppc_function *p);
69
70 extern int ppc_reserve_register(struct ppc_function *p, int reg);
71 extern int ppc_allocate_register(struct ppc_function *p);
72 extern void ppc_release_register(struct ppc_function *p, int reg);
73 extern int ppc_allocate_fp_register(struct ppc_function *p);
74 extern void ppc_release_fp_register(struct ppc_function *p, int reg);
75 extern int ppc_allocate_vec_register(struct ppc_function *p);
76 extern void ppc_release_vec_register(struct ppc_function *p, int reg);
77
78
79
80 /**
81 ** float vector arithmetic
82 **/
83
84 /** vector float add */
85 extern void
86 ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB);
87
88 /** vector float substract */
89 extern void
90 ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB);
91
92 /** vector float min */
93 extern void
94 ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB);
95
96 /** vector float max */
97 extern void
98 ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB);
99
100 /** vector float mult add: vD = vA * vB + vC */
101 extern void
102 ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
103
104 /** vector float negative mult subtract: vD = vA - vB * vC */
105 extern void
106 ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
107
108 /** vector float compare greater than */
109 extern void
110 ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
111
112 /** vector float compare greater than or equal to */
113 extern void
114 ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB);
115
116 /** vector float compare equal */
117 extern void
118 ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
119
120 /** vector float 2^x */
121 extern void
122 ppc_vexptefp(struct ppc_function *p, uint vD, uint vB);
123
124 /** vector float log2(x) */
125 extern void
126 ppc_vlogefp(struct ppc_function *p, uint vD, uint vB);
127
128 /** vector float reciprocol */
129 extern void
130 ppc_vrefp(struct ppc_function *p, uint vD, uint vB);
131
132 /** vector float reciprocol sqrt estimate */
133 extern void
134 ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB);
135
136 /** vector float round to negative infinity */
137 extern void
138 ppc_vrfim(struct ppc_function *p, uint vD, uint vB);
139
140 /** vector float round to positive infinity */
141 extern void
142 ppc_vrfip(struct ppc_function *p, uint vD, uint vB);
143
144 /** vector float round to nearest int */
145 extern void
146 ppc_vrfin(struct ppc_function *p, uint vD, uint vB);
147
148 /** vector float round to int toward zero */
149 extern void
150 ppc_vrfiz(struct ppc_function *p, uint vD, uint vB);
151
152
153 /** vector store: store vR at mem[vA+vB] */
154 extern void
155 ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB);
156
157 /** vector load: vR = mem[vA+vB] */
158 extern void
159 ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB);
160
161 /** load vector element word: vR = mem_word[vA+vB] */
162 extern void
163 ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB);
164
165
166
167 /**
168 ** vector bitwise operations
169 **/
170
171
172 /** vector and */
173 extern void
174 ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB);
175
176 /** vector and complement */
177 extern void
178 ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB);
179
180 /** vector or */
181 extern void
182 ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB);
183
184 /** vector nor */
185 extern void
186 ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB);
187
188 /** vector xor */
189 extern void
190 ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB);
191
192 /** Pseudo-instruction: vector move */
193 extern void
194 ppc_vmove(struct ppc_function *p, uint vD, uint vA);
195
196 /** Set vector register to {0,0,0,0} */
197 extern void
198 ppc_vzero(struct ppc_function *p, uint vr);
199
200
201
202 /**
203 ** Vector shuffle / select / splat / etc
204 **/
205
206 /** vector permute */
207 extern void
208 ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
209
210 /** vector select */
211 extern void
212 ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
213
214 /** vector splat byte */
215 extern void
216 ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm);
217
218 /** vector splat half word */
219 extern void
220 ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm);
221
222 /** vector splat word */
223 extern void
224 ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm);
225
226 /** vector splat signed immediate word */
227 extern void
228 ppc_vspltisw(struct ppc_function *p, uint vD, int imm);
229
230 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
231 extern void
232 ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB);
233
234
235
236 /**
237 ** scalar arithmetic
238 **/
239
240 extern void
241 ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb);
242
243 extern void
244 ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm);
245
246 extern void
247 ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb);
248
249 extern void
250 ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm);
251
252 extern void
253 ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb);
254
255 extern void
256 ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm);
257
258 extern void
259 ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb);
260
261 extern void
262 ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm);
263
264 extern void
265 ppc_mr(struct ppc_function *p, uint rt, uint ra);
266
267 extern void
268 ppc_li(struct ppc_function *p, uint rt, int imm);
269
270 extern void
271 ppc_lis(struct ppc_function *p, uint rt, int imm);
272
273 extern void
274 ppc_load_int(struct ppc_function *p, uint rt, int imm);
275
276
277
278 /**
279 ** scalar load/store
280 **/
281
282 extern void
283 ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d);
284
285 extern void
286 ppc_stw(struct ppc_function *p, uint rs, uint ra, int d);
287
288 extern void
289 ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d);
290
291
292
293 /**
294 ** Float (non-vector) arithmetic
295 **/
296
297 extern void
298 ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb);
299
300 extern void
301 ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb);
302
303 extern void
304 ppc_fctiwz(struct ppc_function *p, uint rt, uint ra);
305
306 extern void
307 ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset);
308
309 extern void
310 ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb);
311
312
313
314 /**
315 ** branch instructions
316 **/
317
318 extern void
319 ppc_blr(struct ppc_function *p);
320
321 void
322 ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg);
323
324 extern void
325 ppc_return(struct ppc_function *p);
326
327
328 #endif /* RTASM_PPC_H */