1 /**************************************************************************
3 * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved.
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
23 **************************************************************************/
26 * PPC code generation.
35 #include "pipe/p_compiler.h"
38 #define PPC_INST_SIZE 4 /**< 4 bytes / instruction */
40 #define PPC_NUM_REGS 32
41 #define PPC_NUM_FP_REGS 32
42 #define PPC_NUM_VEC_REGS 32
44 /** Stack pointer register */
47 /** Branch conditions */
48 #define BRANCH_COND_ALWAYS 0x14 /* binary 1z1zz (z=ignored) */
51 #define BRANCH_HINT_SUB_RETURN 0x0 /* binary 00 */
56 uint32_t *store; /**< instruction buffer */
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 */
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);
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);
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);
89 ** float vector arithmetic
92 /** vector float add */
94 ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB);
96 /** vector float substract */
98 ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB);
100 /** vector float min */
102 ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB);
104 /** vector float max */
106 ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB);
108 /** vector float mult add: vD = vA * vB + vC */
110 ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
112 /** vector float negative mult subtract: vD = vA - vB * vC */
114 ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
116 /** vector float compare greater than */
118 ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
120 /** vector float compare greater than or equal to */
122 ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB);
124 /** vector float compare equal */
126 ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB);
128 /** vector float 2^x */
130 ppc_vexptefp(struct ppc_function *p, uint vD, uint vB);
132 /** vector float log2(x) */
134 ppc_vlogefp(struct ppc_function *p, uint vD, uint vB);
136 /** vector float reciprocol */
138 ppc_vrefp(struct ppc_function *p, uint vD, uint vB);
140 /** vector float reciprocol sqrt estimate */
142 ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB);
144 /** vector float round to negative infinity */
146 ppc_vrfim(struct ppc_function *p, uint vD, uint vB);
148 /** vector float round to positive infinity */
150 ppc_vrfip(struct ppc_function *p, uint vD, uint vB);
152 /** vector float round to nearest int */
154 ppc_vrfin(struct ppc_function *p, uint vD, uint vB);
156 /** vector float round to int toward zero */
158 ppc_vrfiz(struct ppc_function *p, uint vD, uint vB);
161 /** vector store: store vR at mem[vA+vB] */
163 ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB);
165 /** vector load: vR = mem[vA+vB] */
167 ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB);
169 /** load vector element word: vR = mem_word[vA+vB] */
171 ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB);
176 ** vector bitwise operations
182 ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB);
184 /** vector and complement */
186 ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB);
190 ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB);
194 ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB);
198 ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB);
200 /** Pseudo-instruction: vector move */
202 ppc_vmove(struct ppc_function *p, uint vD, uint vA);
204 /** Set vector register to {0,0,0,0} */
206 ppc_vzero(struct ppc_function *p, uint vr);
211 ** Vector shuffle / select / splat / etc
214 /** vector permute */
216 ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
220 ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);
222 /** vector splat byte */
224 ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm);
226 /** vector splat half word */
228 ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm);
230 /** vector splat word */
232 ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm);
234 /** vector splat signed immediate word */
236 ppc_vspltisw(struct ppc_function *p, uint vD, int imm);
238 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
240 ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB);
249 ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb);
252 ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm);
255 ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm);
258 ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb);
261 ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm);
264 ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb);
267 ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm);
270 ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb);
273 ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm);
276 ppc_mr(struct ppc_function *p, uint rt, uint ra);
279 ppc_li(struct ppc_function *p, uint rt, int imm);
282 ppc_lis(struct ppc_function *p, uint rt, int imm);
285 ppc_load_int(struct ppc_function *p, uint rt, int imm);
294 ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d);
297 ppc_stw(struct ppc_function *p, uint rs, uint ra, int d);
300 ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d);
305 ** Float (non-vector) arithmetic
309 ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb);
312 ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb);
315 ppc_fctiwz(struct ppc_function *p, uint rt, uint ra);
318 ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset);
321 ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb);
324 ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset);
329 ** branch instructions
333 ppc_blr(struct ppc_function *p);
336 ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg);
339 ppc_return(struct ppc_function *p);
342 #endif /* RTASM_PPC_H */