9f1e3fcd845496e9df40832da043941864068bf5
[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 */
101 extern void
102 ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
103
104 /** vector float compare greater than */
105 extern void
106 ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
107
108 /** vector float compare greater than or equal to */
109 extern void
110 ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB);
111
112 /** vector float compare equal */
113 extern void
114 ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
115
116 /** vector float 2^x */
117 extern void
118 ppc_vexptefp(struct ppc_function *p, uint vD, uint vB);
119
120 /** vector float log2(x) */
121 extern void
122 ppc_vlogefp(struct ppc_function *p, uint vD, uint vB);
123
124 /** vector float reciprocol */
125 extern void
126 ppc_vrefp(struct ppc_function *p, uint vD, uint vB);
127
128 /** vector float reciprocol sqrt estimate */
129 extern void
130 ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB);
131
132 /** vector float round to negative infinity */
133 extern void
134 ppc_vrfim(struct ppc_function *p, uint vD, uint vB);
135
136 /** vector float round to positive infinity */
137 extern void
138 ppc_vrfip(struct ppc_function *p, uint vD, uint vB);
139
140 /** vector float round to nearest int */
141 extern void
142 ppc_vrfin(struct ppc_function *p, uint vD, uint vB);
143
144 /** vector float round to int toward zero */
145 extern void
146 ppc_vrfiz(struct ppc_function *p, uint vD, uint vB);
147
148
149 /** vector store: store vR at mem[vA+vB] */
150 extern void
151 ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB);
152
153 /** vector load: vR = mem[vA+vB] */
154 extern void
155 ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB);
156
157 /** load vector element word: vR = mem_word[vA+vB] */
158 extern void
159 ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB);
160
161 /** vector load float: vr = splats(imm) */
162 extern void
163 ppc_vload_float(struct ppc_function *p, uint vr, float imm);
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_vecmove(struct ppc_function *p, uint vD, uint vA);
195
196
197 /**
198 ** Vector shuffle / select / splat / etc
199 **/
200
201 /** vector permute */
202 extern void
203 ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
204
205 /** vector select */
206 extern void
207 ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
208
209 /** vector splat byte */
210 extern void
211 ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm);
212
213 /** vector splat half word */
214 extern void
215 ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm);
216
217 /** vector splat word */
218 extern void
219 ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm);
220
221 /** vector splat signed immediate word */
222 extern void
223 ppc_vspltisw(struct ppc_function *p, uint vD, int imm);
224
225 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
226 extern void
227 ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB);
228
229
230
231 /**
232 ** scalar arithmetic
233 **/
234
235 extern void
236 ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb);
237
238 extern void
239 ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm);
240
241 extern void
242 ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb);
243
244 extern void
245 ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm);
246
247 extern void
248 ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb);
249
250 extern void
251 ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm);
252
253 extern void
254 ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb);
255
256 extern void
257 ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm);
258
259 extern void
260 ppc_mr(struct ppc_function *p, uint rt, uint ra);
261
262 extern void
263 ppc_li(struct ppc_function *p, uint rt, int imm);
264
265 extern void
266 ppc_lis(struct ppc_function *p, uint rt, int imm);
267
268 extern void
269 ppc_load_int(struct ppc_function *p, uint rt, int imm);
270
271
272
273 /**
274 ** scalar load/store
275 **/
276
277 extern void
278 ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d);
279
280 extern void
281 ppc_stw(struct ppc_function *p, uint rs, uint ra, int d);
282
283 extern void
284 ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d);
285
286
287
288 /**
289 ** Float (non-vector) arithmetic
290 **/
291
292 extern void
293 ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb);
294
295 extern void
296 ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb);
297
298 extern void
299 ppc_fctiwz(struct ppc_function *p, uint rt, uint ra);
300
301 extern void
302 ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset);
303
304 extern void
305 ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb);
306
307
308
309 /**
310 ** branch instructions
311 **/
312
313 extern void
314 ppc_blr(struct ppc_function *p);
315
316 void
317 ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg);
318
319 extern void
320 ppc_return(struct ppc_function *p);
321
322
323 #endif /* RTASM_PPC_H */