561e139bce7f219755ea3d4ccf503924ac0851d9
1 /**************************************************************************
3 * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
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.
22 **************************************************************************/
25 * PPC code generation.
34 #include "pipe/p_compiler.h"
37 #define PPC_INST_SIZE 4 /**< 4 bytes / instruction */
39 #define PPC_NUM_REGS 32
40 #define PPC_NUM_FP_REGS 32
41 #define PPC_NUM_VEC_REGS 32
43 /** Stack pointer register */
46 /** Branch conditions */
47 #define BRANCH_COND_ALWAYS 0x14 /* binary 1z1zz (z=ignored) */
50 #define BRANCH_HINT_SUB_RETURN 0x0 /* binary 00 */
55 uint32_t *store
; /**< instruction buffer */
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 */
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
);
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
);
81 ** float vector arithmetic
84 /** vector float add */
86 ppc_vaddfp(struct ppc_function
*p
,uint vD
, uint vA
, uint vB
);
88 /** vector float substract */
90 ppc_vsubfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
92 /** vector float min */
94 ppc_vminfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
96 /** vector float max */
98 ppc_vmaxfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
100 /** vector float mult add: vD = vA * vB + vC */
102 ppc_vmaddfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
104 /** vector float negative mult subtract: vD = vA - vB * vC */
106 ppc_vnmsubfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
108 /** vector float compare greater than */
110 ppc_vcmpgtfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
112 /** vector float compare greater than or equal to */
114 ppc_vcmpgefpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
116 /** vector float compare equal */
118 ppc_vcmpeqfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
120 /** vector float 2^x */
122 ppc_vexptefp(struct ppc_function
*p
, uint vD
, uint vB
);
124 /** vector float log2(x) */
126 ppc_vlogefp(struct ppc_function
*p
, uint vD
, uint vB
);
128 /** vector float reciprocol */
130 ppc_vrefp(struct ppc_function
*p
, uint vD
, uint vB
);
132 /** vector float reciprocol sqrt estimate */
134 ppc_vrsqrtefp(struct ppc_function
*p
, uint vD
, uint vB
);
136 /** vector float round to negative infinity */
138 ppc_vrfim(struct ppc_function
*p
, uint vD
, uint vB
);
140 /** vector float round to positive infinity */
142 ppc_vrfip(struct ppc_function
*p
, uint vD
, uint vB
);
144 /** vector float round to nearest int */
146 ppc_vrfin(struct ppc_function
*p
, uint vD
, uint vB
);
148 /** vector float round to int toward zero */
150 ppc_vrfiz(struct ppc_function
*p
, uint vD
, uint vB
);
153 /** vector store: store vR at mem[vA+vB] */
155 ppc_stvx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
157 /** vector load: vR = mem[vA+vB] */
159 ppc_lvx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
161 /** load vector element word: vR = mem_word[vA+vB] */
163 ppc_lvewx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
168 ** vector bitwise operations
174 ppc_vand(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
176 /** vector and complement */
178 ppc_vandc(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
182 ppc_vor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
186 ppc_vnor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
190 ppc_vxor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
192 /** Pseudo-instruction: vector move */
194 ppc_vmove(struct ppc_function
*p
, uint vD
, uint vA
);
196 /** Set vector register to {0,0,0,0} */
198 ppc_vzero(struct ppc_function
*p
, uint vr
);
203 ** Vector shuffle / select / splat / etc
206 /** vector permute */
208 ppc_vperm(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
212 ppc_vsel(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
214 /** vector splat byte */
216 ppc_vspltb(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
218 /** vector splat half word */
220 ppc_vsplthw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
222 /** vector splat word */
224 ppc_vspltw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
226 /** vector splat signed immediate word */
228 ppc_vspltisw(struct ppc_function
*p
, uint vD
, int imm
);
230 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
232 ppc_vslw(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
241 ppc_add(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
244 ppc_addi(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
247 ppc_and(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
250 ppc_andi(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
253 ppc_or(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
256 ppc_ori(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
259 ppc_xor(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
262 ppc_xori(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
265 ppc_mr(struct ppc_function
*p
, uint rt
, uint ra
);
268 ppc_li(struct ppc_function
*p
, uint rt
, int imm
);
271 ppc_lis(struct ppc_function
*p
, uint rt
, int imm
);
274 ppc_load_int(struct ppc_function
*p
, uint rt
, int imm
);
283 ppc_stwu(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
286 ppc_stw(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
289 ppc_lwz(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
294 ** Float (non-vector) arithmetic
298 ppc_fadd(struct ppc_function
*p
, uint frt
, uint fra
, uint frb
);
301 ppc_fsub(struct ppc_function
*p
, uint frt
, uint fra
, uint frb
);
304 ppc_fctiwz(struct ppc_function
*p
, uint rt
, uint ra
);
307 ppc_stfs(struct ppc_function
*p
, uint frs
, uint ra
, int offset
);
310 ppc_stfiwx(struct ppc_function
*p
, uint frs
, uint ra
, uint rb
);
315 ** branch instructions
319 ppc_blr(struct ppc_function
*p
);
322 ppc_bclr(struct ppc_function
*p
, uint condOp
, uint branchHint
, uint condReg
);
325 ppc_return(struct ppc_function
*p
);
328 #endif /* RTASM_PPC_H */