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 54struct 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 68extern void ppc_init_func(struct ppc_function *p); 69extern void ppc_release_func(struct ppc_function *p); 70extern uint ppc_num_instructions(const struct ppc_function *p); 71extern void (*ppc_get_func( struct ppc_function *p ))( void ); 72extern void ppc_dump_func(const struct ppc_function *p); 73 74extern void ppc_print_code(struct ppc_function *p, boolean enable); 75extern void ppc_indent(struct ppc_function *p, int spaces); 76extern void ppc_comment(struct ppc_function *p, int rel_indent, const char *s); 77 78extern int ppc_reserve_register(struct ppc_function *p, int reg); 79extern int ppc_allocate_register(struct ppc_function *p); 80extern void ppc_release_register(struct ppc_function *p, int reg); 81extern int ppc_allocate_fp_register(struct ppc_function *p); 82extern void ppc_release_fp_register(struct ppc_function *p, int reg); 83extern int ppc_allocate_vec_register(struct ppc_function *p); 84extern 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 */ 93extern void 94ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB); 95 96/** vector float substract */ 97extern void 98ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB); 99 100/** vector float min */ 101extern void 102ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB); 103 104/** vector float max */ 105extern void 106ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB); 107 108/** vector float mult add: vD = vA * vB + vC */ 109extern void 110ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); 111 112/** vector float negative mult subtract: vD = vA - vB * vC */ 113extern void 114ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); 115 116/** vector float compare greater than */ 117extern void 118ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB); 119 120/** vector float compare greater than or equal to */ 121extern void 122ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB); 123 124/** vector float compare equal */ 125extern void 126ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB); 127 128/** vector float 2^x */ 129extern void 130ppc_vexptefp(struct ppc_function *p, uint vD, uint vB); 131 132/** vector float log2(x) */ 133extern void 134ppc_vlogefp(struct ppc_function *p, uint vD, uint vB); 135 136/** vector float reciprocol */ 137extern void 138ppc_vrefp(struct ppc_function *p, uint vD, uint vB); 139 140/** vector float reciprocol sqrt estimate */ 141extern void 142ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB); 143 144/** vector float round to negative infinity */ 145extern void 146ppc_vrfim(struct ppc_function *p, uint vD, uint vB); 147 148/** vector float round to positive infinity */ 149extern void 150ppc_vrfip(struct ppc_function *p, uint vD, uint vB); 151 152/** vector float round to nearest int */ 153extern void 154ppc_vrfin(struct ppc_function *p, uint vD, uint vB); 155 156/** vector float round to int toward zero */ 157extern void 158ppc_vrfiz(struct ppc_function *p, uint vD, uint vB); 159 160 161/** vector store: store vR at mem[vA+vB] */ 162extern void 163ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB); 164 165/** vector load: vR = mem[vA+vB] */ 166extern void 167ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB); 168 169/** load vector element word: vR = mem_word[vA+vB] */ 170extern void 171ppc_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 */ 181extern void 182ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB); 183 184/** vector and complement */ 185extern void 186ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB); 187 188/** vector or */ 189extern void 190ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB); 191 192/** vector nor */ 193extern void 194ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB); 195 196/** vector xor */ 197extern void 198ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB); 199 200/** Pseudo-instruction: vector move */ 201extern void 202ppc_vmove(struct ppc_function *p, uint vD, uint vA); 203 204/** Set vector register to {0,0,0,0} */ 205extern void 206ppc_vzero(struct ppc_function *p, uint vr); 207 208 209 210/** 211 ** Vector shuffle / select / splat / etc 212 **/ 213 214/** vector permute */ 215extern void 216ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); 217 218/** vector select */ 219extern void 220ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); 221 222/** vector splat byte */ 223extern void 224ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm); 225 226/** vector splat half word */ 227extern void 228ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm); 229 230/** vector splat word */ 231extern void 232ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm); 233 234/** vector splat signed immediate word */ 235extern void 236ppc_vspltisw(struct ppc_function *p, uint vD, int imm); 237 238/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */ 239extern void 240ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB); 241 242 243 244/** 245 ** scalar arithmetic 246 **/ 247 248extern void 249ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb); 250 251extern void 252ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm); 253 254extern void 255ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm); 256 257extern void 258ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb); 259 260extern void 261ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm); 262 263extern void 264ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb); 265 266extern void 267ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm); 268 269extern void 270ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb); 271 272extern void 273ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm); 274 275extern void 276ppc_mr(struct ppc_function *p, uint rt, uint ra); 277 278extern void 279ppc_li(struct ppc_function *p, uint rt, int imm); 280 281extern void 282ppc_lis(struct ppc_function *p, uint rt, int imm); 283 284extern void 285ppc_load_int(struct ppc_function *p, uint rt, int imm); 286 287 288 289/** 290 ** scalar load/store 291 **/ 292 293extern void 294ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d); 295 296extern void 297ppc_stw(struct ppc_function *p, uint rs, uint ra, int d); 298 299extern void 300ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d); 301 302 303 304/** 305 ** Float (non-vector) arithmetic 306 **/ 307 308extern void 309ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb); 310 311extern void 312ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb); 313 314extern void 315ppc_fctiwz(struct ppc_function *p, uint rt, uint ra); 316 317extern void 318ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset); 319 320extern void 321ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb); 322 323extern void 324ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset); 325 326 327 328/** 329 ** branch instructions 330 **/ 331 332extern void 333ppc_blr(struct ppc_function *p); 334 335void 336ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg); 337 338extern void 339ppc_return(struct ppc_function *p); 340 341 342#endif /* RTASM_PPC_H */ 343