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