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
);
66 extern void ppc_release_func(struct ppc_function
*p
);
67 extern uint
ppc_num_instructions(const struct ppc_function
*p
);
68 extern void (*ppc_get_func( struct ppc_function
*p
))( void );
69 extern void ppc_dump_func(const struct ppc_function
*p
);
71 extern int ppc_reserve_register(struct ppc_function
*p
, int reg
);
72 extern int ppc_allocate_register(struct ppc_function
*p
);
73 extern void ppc_release_register(struct ppc_function
*p
, int reg
);
74 extern int ppc_allocate_fp_register(struct ppc_function
*p
);
75 extern void ppc_release_fp_register(struct ppc_function
*p
, int reg
);
76 extern int ppc_allocate_vec_register(struct ppc_function
*p
);
77 extern void ppc_release_vec_register(struct ppc_function
*p
, int reg
);
82 ** float vector arithmetic
85 /** vector float add */
87 ppc_vaddfp(struct ppc_function
*p
,uint vD
, uint vA
, uint vB
);
89 /** vector float substract */
91 ppc_vsubfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
93 /** vector float min */
95 ppc_vminfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
97 /** vector float max */
99 ppc_vmaxfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
101 /** vector float mult add: vD = vA * vB + vC */
103 ppc_vmaddfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
105 /** vector float negative mult subtract: vD = vA - vB * vC */
107 ppc_vnmsubfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
109 /** vector float compare greater than */
111 ppc_vcmpgtfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
113 /** vector float compare greater than or equal to */
115 ppc_vcmpgefpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
117 /** vector float compare equal */
119 ppc_vcmpeqfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
121 /** vector float 2^x */
123 ppc_vexptefp(struct ppc_function
*p
, uint vD
, uint vB
);
125 /** vector float log2(x) */
127 ppc_vlogefp(struct ppc_function
*p
, uint vD
, uint vB
);
129 /** vector float reciprocol */
131 ppc_vrefp(struct ppc_function
*p
, uint vD
, uint vB
);
133 /** vector float reciprocol sqrt estimate */
135 ppc_vrsqrtefp(struct ppc_function
*p
, uint vD
, uint vB
);
137 /** vector float round to negative infinity */
139 ppc_vrfim(struct ppc_function
*p
, uint vD
, uint vB
);
141 /** vector float round to positive infinity */
143 ppc_vrfip(struct ppc_function
*p
, uint vD
, uint vB
);
145 /** vector float round to nearest int */
147 ppc_vrfin(struct ppc_function
*p
, uint vD
, uint vB
);
149 /** vector float round to int toward zero */
151 ppc_vrfiz(struct ppc_function
*p
, uint vD
, uint vB
);
154 /** vector store: store vR at mem[vA+vB] */
156 ppc_stvx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
158 /** vector load: vR = mem[vA+vB] */
160 ppc_lvx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
162 /** load vector element word: vR = mem_word[vA+vB] */
164 ppc_lvewx(struct ppc_function
*p
, uint vR
, uint vA
, uint vB
);
169 ** vector bitwise operations
175 ppc_vand(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
177 /** vector and complement */
179 ppc_vandc(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
183 ppc_vor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
187 ppc_vnor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
191 ppc_vxor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
193 /** Pseudo-instruction: vector move */
195 ppc_vmove(struct ppc_function
*p
, uint vD
, uint vA
);
197 /** Set vector register to {0,0,0,0} */
199 ppc_vzero(struct ppc_function
*p
, uint vr
);
204 ** Vector shuffle / select / splat / etc
207 /** vector permute */
209 ppc_vperm(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
213 ppc_vsel(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
);
215 /** vector splat byte */
217 ppc_vspltb(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
219 /** vector splat half word */
221 ppc_vsplthw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
223 /** vector splat word */
225 ppc_vspltw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
);
227 /** vector splat signed immediate word */
229 ppc_vspltisw(struct ppc_function
*p
, uint vD
, int imm
);
231 /** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
233 ppc_vslw(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
);
242 ppc_add(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
245 ppc_addi(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
248 ppc_addis(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
251 ppc_and(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
254 ppc_andi(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
257 ppc_or(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
260 ppc_ori(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
263 ppc_xor(struct ppc_function
*p
, uint rt
, uint ra
, uint rb
);
266 ppc_xori(struct ppc_function
*p
, uint rt
, uint ra
, int imm
);
269 ppc_mr(struct ppc_function
*p
, uint rt
, uint ra
);
272 ppc_li(struct ppc_function
*p
, uint rt
, int imm
);
275 ppc_lis(struct ppc_function
*p
, uint rt
, int imm
);
278 ppc_load_int(struct ppc_function
*p
, uint rt
, int imm
);
287 ppc_stwu(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
290 ppc_stw(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
293 ppc_lwz(struct ppc_function
*p
, uint rs
, uint ra
, int d
);
298 ** Float (non-vector) arithmetic
302 ppc_fadd(struct ppc_function
*p
, uint frt
, uint fra
, uint frb
);
305 ppc_fsub(struct ppc_function
*p
, uint frt
, uint fra
, uint frb
);
308 ppc_fctiwz(struct ppc_function
*p
, uint rt
, uint ra
);
311 ppc_stfs(struct ppc_function
*p
, uint frs
, uint ra
, int offset
);
314 ppc_stfiwx(struct ppc_function
*p
, uint frs
, uint ra
, uint rb
);
317 ppc_lfs(struct ppc_function
*p
, uint frt
, uint ra
, int offset
);
322 ** branch instructions
326 ppc_blr(struct ppc_function
*p
);
329 ppc_bclr(struct ppc_function
*p
, uint condOp
, uint branchHint
, uint condReg
);
332 ppc_return(struct ppc_function
*p
);
335 #endif /* RTASM_PPC_H */