From 30530ee9acc356ea94466e9d71661068f4787433 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 2 Jan 2013 12:44:49 -0500 Subject: [PATCH] gallium: Remove ppc asm backend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The vs part hasn't been wired up since tgsi_sse2 was disabled in: commit 4eb3225b38ce12cb34ab3d90804c9683bd7b4ed3 Author: José Fonseca Date: Tue Nov 8 00:10:47 2011 +0000 Remove tgsi_sse2. And it would certainly not work correctly in its current state: draw/draw_vs_ppc.c: In function ‘draw_create_vs_ppc’: draw/draw_vs_ppc.c:190:24: warning: assignment from incompatible pointer type [enabled by default] As with the sse2 backend, this should be done in llvm anyway. Reviewed-by: Brian Paul Signed-off-by: Adam Jackson --- src/gallium/auxiliary/Makefile.sources | 3 - src/gallium/auxiliary/draw/draw_vs.h | 5 - src/gallium/auxiliary/draw/draw_vs_ppc.c | 240 ---- src/gallium/auxiliary/rtasm/rtasm_ppc.c | 1077 ----------------- src/gallium/auxiliary/rtasm/rtasm_ppc.h | 342 ------ src/gallium/auxiliary/tgsi/tgsi_ppc.c | 1359 ---------------------- src/gallium/auxiliary/tgsi/tgsi_ppc.h | 51 - 7 files changed, 3077 deletions(-) delete mode 100644 src/gallium/auxiliary/draw/draw_vs_ppc.c delete mode 100644 src/gallium/auxiliary/rtasm/rtasm_ppc.c delete mode 100644 src/gallium/auxiliary/rtasm/rtasm_ppc.h delete mode 100644 src/gallium/auxiliary/tgsi/tgsi_ppc.c delete mode 100644 src/gallium/auxiliary/tgsi/tgsi_ppc.h diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources index e54e9201cba..74c7902ae00 100644 --- a/src/gallium/auxiliary/Makefile.sources +++ b/src/gallium/auxiliary/Makefile.sources @@ -36,7 +36,6 @@ C_SOURCES := \ draw/draw_vertex.c \ draw/draw_vs.c \ draw/draw_vs_exec.c \ - draw/draw_vs_ppc.c \ draw/draw_vs_variant.c \ os/os_misc.c \ os/os_time.c \ @@ -64,7 +63,6 @@ C_SOURCES := \ rbug/rbug_shader.c \ rtasm/rtasm_cpu.c \ rtasm/rtasm_execmem.c \ - rtasm/rtasm_ppc.c \ rtasm/rtasm_x86sse.c \ tgsi/tgsi_build.c \ tgsi/tgsi_dump.c \ @@ -72,7 +70,6 @@ C_SOURCES := \ tgsi/tgsi_info.c \ tgsi/tgsi_iterate.c \ tgsi/tgsi_parse.c \ - tgsi/tgsi_ppc.c \ tgsi/tgsi_sanity.c \ tgsi/tgsi_scan.c \ tgsi/tgsi_strings.c \ diff --git a/src/gallium/auxiliary/draw/draw_vs.h b/src/gallium/auxiliary/draw/draw_vs.h index 8a440911af7..798b004ebd4 100644 --- a/src/gallium/auxiliary/draw/draw_vs.h +++ b/src/gallium/auxiliary/draw/draw_vs.h @@ -159,11 +159,6 @@ struct draw_vertex_shader * draw_create_vs_exec(struct draw_context *draw, const struct pipe_shader_state *templ); -struct draw_vertex_shader * -draw_create_vs_ppc(struct draw_context *draw, - const struct pipe_shader_state *templ); - - struct draw_vs_variant_key; struct draw_vertex_shader; diff --git a/src/gallium/auxiliary/draw/draw_vs_ppc.c b/src/gallium/auxiliary/draw/draw_vs_ppc.c deleted file mode 100644 index 7fb0e0953e2..00000000000 --- a/src/gallium/auxiliary/draw/draw_vs_ppc.c +++ /dev/null @@ -1,240 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - * Brian Paul - */ - -#include "util/u_math.h" -#include "util/u_memory.h" -#include "pipe/p_config.h" - -#include "draw_vs.h" - -#if defined(PIPE_ARCH_PPC) - -#include "pipe/p_shader_tokens.h" - -#include "draw_private.h" -#include "draw_context.h" - -#include "rtasm/rtasm_cpu.h" -#include "rtasm/rtasm_ppc.h" -#include "tgsi/tgsi_ppc.h" -#include "tgsi/tgsi_parse.h" -#include "tgsi/tgsi_exec.h" - - - -typedef void (PIPE_CDECL *codegen_function) (float (*inputs)[4][4], - float (*outputs)[4][4], - float (*temps)[4][4], - float (*immeds)[4], - float (*consts)[4], - const float *builtins); - - -struct draw_ppc_vertex_shader { - struct draw_vertex_shader base; - struct ppc_function ppc_program; - - codegen_function func; -}; - - -static void -vs_ppc_prepare( struct draw_vertex_shader *base, - struct draw_context *draw ) -{ - /* nothing */ -} - - -/** - * Simplified vertex shader interface for the pt paths. Given the - * complexity of code-generating all the above operations together, - * it's time to try doing all the other stuff separately. - */ -static void -vs_ppc_run_linear( struct draw_vertex_shader *base, - const float (*input)[4], - float (*output)[4], - const void *constants[PIPE_MAX_CONSTANT_BUFFERS], - unsigned count, - unsigned input_stride, - unsigned output_stride ) -{ - struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base; - unsigned int i; - -#define MAX_VERTICES 4 - - /* loop over verts */ - for (i = 0; i < count; i += MAX_VERTICES) { - const uint max_vertices = MIN2(MAX_VERTICES, count - i); - PIPE_ALIGN_VAR(16) float inputs_soa[PIPE_MAX_SHADER_INPUTS][4][4]; - PIPE_ALIGN_VAR(16) float outputs_soa[PIPE_MAX_SHADER_OUTPUTS][4][4]; - PIPE_ALIGN_VAR(16) float temps_soa[TGSI_EXEC_NUM_TEMPS][4][4]; - uint attr; - - /* convert (up to) four input verts to SoA format */ - for (attr = 0; attr < base->info.num_inputs; attr++) { - const float *vIn = (const float *) input; - uint vert; - for (vert = 0; vert < max_vertices; vert++) { -#if 0 - if (attr==0) - printf("Input v%d a%d: %f %f %f %f\n", - vert, attr, vIn[0], vIn[1], vIn[2], vIn[3]); -#endif - inputs_soa[attr][0][vert] = vIn[attr * 4 + 0]; - inputs_soa[attr][1][vert] = vIn[attr * 4 + 1]; - inputs_soa[attr][2][vert] = vIn[attr * 4 + 2]; - inputs_soa[attr][3][vert] = vIn[attr * 4 + 3]; - vIn += input_stride / 4; - } - } - - /* run compiled shader - */ - shader->func(inputs_soa, outputs_soa, temps_soa, - (float (*)[4]) shader->base.immediates, - (float (*)[4])constants[0], - ppc_builtin_constants); - - /* convert (up to) four output verts from SoA back to AoS format */ - for (attr = 0; attr < base->info.num_outputs; attr++) { - float *vOut = (float *) output; - uint vert; - for (vert = 0; vert < max_vertices; vert++) { - vOut[attr * 4 + 0] = outputs_soa[attr][0][vert]; - vOut[attr * 4 + 1] = outputs_soa[attr][1][vert]; - vOut[attr * 4 + 2] = outputs_soa[attr][2][vert]; - vOut[attr * 4 + 3] = outputs_soa[attr][3][vert]; -#if 0 - if (attr==0) - printf("Output v%d a%d: %f %f %f %f\n", - vert, attr, vOut[0], vOut[1], vOut[2], vOut[3]); -#endif - vOut += output_stride / 4; - } - } - - /* advance to next group of four input/output verts */ - input = (const float (*)[4])((const char *)input + input_stride * max_vertices); - output = (float (*)[4])((char *)output + output_stride * max_vertices); - } -} - - -static void -vs_ppc_delete( struct draw_vertex_shader *base ) -{ - struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base; - - ppc_release_func( &shader->ppc_program ); - - align_free( (void *) shader->base.immediates ); - - FREE( (void*) shader->base.state.tokens ); - FREE( shader ); -} - - -struct draw_vertex_shader * -draw_create_vs_ppc(struct draw_context *draw, - const struct pipe_shader_state *templ) -{ - struct draw_ppc_vertex_shader *vs; - - vs = CALLOC_STRUCT( draw_ppc_vertex_shader ); - if (vs == NULL) - return NULL; - - /* we make a private copy of the tokens */ - vs->base.state.tokens = tgsi_dup_tokens(templ->tokens); - if (!vs->base.state.tokens) - goto fail; - - tgsi_scan_shader(templ->tokens, &vs->base.info); - - vs->base.draw = draw; - vs->base.create_variant = draw_vs_create_variant_generic; - vs->base.prepare = vs_ppc_prepare; - vs->base.run_linear = vs_ppc_run_linear; - vs->base.delete = vs_ppc_delete; - - vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 * - sizeof(float), 16); - - ppc_init_func( &vs->ppc_program ); - -#if 0 - ppc_print_code(&vs->ppc_program, TRUE); - ppc_indent(&vs->ppc_program, 8); -#endif - - if (!tgsi_emit_ppc( (struct tgsi_token *) vs->base.state.tokens, - &vs->ppc_program, - (float (*)[4]) vs->base.immediates, - TRUE )) - goto fail; - - vs->func = (codegen_function) ppc_get_func( &vs->ppc_program ); - if (!vs->func) { - goto fail; - } - - return &vs->base; - -fail: - /* - debug_error("tgsi_emit_ppc() failed, falling back to interpreter\n"); - */ - - ppc_release_func( &vs->ppc_program ); - - FREE(vs); - return NULL; -} - - - -#else /* PIPE_ARCH_PPC */ - - -struct draw_vertex_shader * -draw_create_vs_ppc( struct draw_context *draw, - const struct pipe_shader_state *templ ) -{ - return (void *) 0; -} - - -#endif /* PIPE_ARCH_PPC */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc.c b/src/gallium/auxiliary/rtasm/rtasm_ppc.c deleted file mode 100644 index 330838d23cf..00000000000 --- a/src/gallium/auxiliary/rtasm/rtasm_ppc.c +++ /dev/null @@ -1,1077 +0,0 @@ -/************************************************************************** - * - * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved. - * Copyright (C) 2009 VMware, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * PPC code generation. - * For reference, see http://www.power.org/resources/reading/PowerISA_V2.05.pdf - * ABI info: http://www.cs.utsa.edu/~whaley/teach/cs6463FHPO/LEC/lec12_ho.pdf - * - * Other PPC refs: - * http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2 - * http://www.ibm.com/developerworks/eserver/library/es-archguide-v2.html - * http://www.freescale.com/files/product/doc/MPCFPE32B.pdf - * - * \author Brian Paul - */ - - -#include -#include "util/u_memory.h" -#include "util/u_debug.h" -#include "rtasm_execmem.h" -#include "rtasm_ppc.h" - - -void -ppc_init_func(struct ppc_function *p) -{ - uint i; - - memset(p, 0, sizeof(*p)); - - p->num_inst = 0; - p->max_inst = 100; /* first guess at buffer size */ - p->store = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE); - p->reg_used = 0x0; - p->fp_used = 0x0; - p->vec_used = 0x0; - - p->print = FALSE; - p->indent = 0; - - /* only allow using gp registers 3..12 for now */ - for (i = 0; i < 3; i++) - ppc_reserve_register(p, i); - for (i = 12; i < PPC_NUM_REGS; i++) - ppc_reserve_register(p, i); -} - - -void -ppc_release_func(struct ppc_function *p) -{ - assert(p->num_inst <= p->max_inst); - if (p->store != NULL) { - rtasm_exec_free(p->store); - } - p->store = NULL; -} - - -uint -ppc_num_instructions(const struct ppc_function *p) -{ - return p->num_inst; -} - - -void (*ppc_get_func(struct ppc_function *p))(void) -{ -#if 0 - DUMP_END(); - if (DISASSEM && p->store) - debug_printf("disassemble %p %p\n", p->store, p->csr); - - if (p->store == p->error_overflow) - return (void (*)(void)) NULL; - else -#endif - return (void (*)(void)) pointer_to_func(p->store); -} - - -void -ppc_dump_func(const struct ppc_function *p) -{ - uint i; - for (i = 0; i < p->num_inst; i++) { - debug_printf("%3u: 0x%08x\n", i, p->store[i]); - } -} - - -void -ppc_print_code(struct ppc_function *p, boolean enable) -{ - p->print = enable; -} - - -void -ppc_indent(struct ppc_function *p, int spaces) -{ - p->indent += spaces; -} - - -static void -indent(const struct ppc_function *p) -{ - int i; - for (i = 0; i < p->indent; i++) { - putchar(' '); - } -} - - -void -ppc_comment(struct ppc_function *p, int rel_indent, const char *s) -{ - if (p->print) { - p->indent += rel_indent; - indent(p); - p->indent -= rel_indent; - printf("# %s\n", s); - } -} - - -/** - * Mark a register as being unavailable. - */ -int -ppc_reserve_register(struct ppc_function *p, int reg) -{ - assert(reg < PPC_NUM_REGS); - p->reg_used |= (1 << reg); - return reg; -} - - -/** - * Allocate a general purpose register. - * \return register index or -1 if none left. - */ -int -ppc_allocate_register(struct ppc_function *p) -{ - unsigned i; - for (i = 0; i < PPC_NUM_REGS; i++) { - const uint32_t mask = 1 << i; - if ((p->reg_used & mask) == 0) { - p->reg_used |= mask; - return i; - } - } - printf("OUT OF PPC registers!\n"); - return -1; -} - - -/** - * Mark the given general purpose register as "unallocated". - */ -void -ppc_release_register(struct ppc_function *p, int reg) -{ - assert(reg < PPC_NUM_REGS); - assert(p->reg_used & (1 << reg)); - p->reg_used &= ~(1 << reg); -} - - -/** - * Allocate a floating point register. - * \return register index or -1 if none left. - */ -int -ppc_allocate_fp_register(struct ppc_function *p) -{ - unsigned i; - for (i = 0; i < PPC_NUM_FP_REGS; i++) { - const uint32_t mask = 1 << i; - if ((p->fp_used & mask) == 0) { - p->fp_used |= mask; - return i; - } - } - printf("OUT OF PPC FP registers!\n"); - return -1; -} - - -/** - * Mark the given floating point register as "unallocated". - */ -void -ppc_release_fp_register(struct ppc_function *p, int reg) -{ - assert(reg < PPC_NUM_FP_REGS); - assert(p->fp_used & (1 << reg)); - p->fp_used &= ~(1 << reg); -} - - -/** - * Allocate a vector register. - * \return register index or -1 if none left. - */ -int -ppc_allocate_vec_register(struct ppc_function *p) -{ - unsigned i; - for (i = 0; i < PPC_NUM_VEC_REGS; i++) { - const uint32_t mask = 1 << i; - if ((p->vec_used & mask) == 0) { - p->vec_used |= mask; - return i; - } - } - printf("OUT OF PPC VEC registers!\n"); - return -1; -} - - -/** - * Mark the given vector register as "unallocated". - */ -void -ppc_release_vec_register(struct ppc_function *p, int reg) -{ - assert(reg < PPC_NUM_VEC_REGS); - assert(p->vec_used & (1 << reg)); - p->vec_used &= ~(1 << reg); -} - - -/** - * Append instruction to instruction buffer. Grow buffer if out of room. - */ -static void -emit_instruction(struct ppc_function *p, uint32_t inst_bits) -{ - if (!p->store) - return; /* out of memory, drop the instruction */ - - if (p->num_inst == p->max_inst) { - /* allocate larger buffer */ - uint32_t *newbuf; - p->max_inst *= 2; /* 2x larger */ - newbuf = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE); - if (newbuf) { - memcpy(newbuf, p->store, p->num_inst * PPC_INST_SIZE); - } - rtasm_exec_free(p->store); - p->store = newbuf; - if (!p->store) { - /* out of memory */ - p->num_inst = 0; - return; - } - } - - p->store[p->num_inst++] = inst_bits; -} - - -union vx_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned vD:5; - unsigned vA:5; - unsigned vB:5; - unsigned op2:11; - } inst; -}; - -static INLINE void -emit_vx(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, - const char *format, boolean transpose) -{ - union vx_inst inst; - inst.inst.op = 4; - inst.inst.vD = vD; - inst.inst.vA = vA; - inst.inst.vB = vB; - inst.inst.op2 = op2; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - if (transpose) - printf(format, vD, vB, vA); - else - printf(format, vD, vA, vB); - } -} - - -union vxr_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned vD:5; - unsigned vA:5; - unsigned vB:5; - unsigned rC:1; - unsigned op2:10; - } inst; -}; - -static INLINE void -emit_vxr(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, - const char *format) -{ - union vxr_inst inst; - inst.inst.op = 4; - inst.inst.vD = vD; - inst.inst.vA = vA; - inst.inst.vB = vB; - inst.inst.rC = 0; - inst.inst.op2 = op2; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - printf(format, vD, vA, vB); - } -} - - -union va_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned vD:5; - unsigned vA:5; - unsigned vB:5; - unsigned vC:5; - unsigned op2:6; - } inst; -}; - -static INLINE void -emit_va(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, uint vC, - const char *format) -{ - union va_inst inst; - inst.inst.op = 4; - inst.inst.vD = vD; - inst.inst.vA = vA; - inst.inst.vB = vB; - inst.inst.vC = vC; - inst.inst.op2 = op2; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - printf(format, vD, vA, vB, vC); - } -} - - -union i_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned li:24; - unsigned aa:1; - unsigned lk:1; - } inst; -}; - -static INLINE void -emit_i(struct ppc_function *p, uint op, uint li, uint aa, uint lk) -{ - union i_inst inst; - inst.inst.op = op; - inst.inst.li = li; - inst.inst.aa = aa; - inst.inst.lk = lk; - emit_instruction(p, inst.bits); -} - - -union xl_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned bo:5; - unsigned bi:5; - unsigned unused:3; - unsigned bh:2; - unsigned op2:10; - unsigned lk:1; - } inst; -}; - -static INLINE void -emit_xl(struct ppc_function *p, uint op, uint bo, uint bi, uint bh, - uint op2, uint lk) -{ - union xl_inst inst; - inst.inst.op = op; - inst.inst.bo = bo; - inst.inst.bi = bi; - inst.inst.unused = 0x0; - inst.inst.bh = bh; - inst.inst.op2 = op2; - inst.inst.lk = lk; - emit_instruction(p, inst.bits); -} - -static INLINE void -dump_xl(const char *name, uint inst) -{ - union xl_inst i; - - i.bits = inst; - debug_printf("%s = 0x%08x\n", name, inst); - debug_printf(" op: %d 0x%x\n", i.inst.op, i.inst.op); - debug_printf(" bo: %d 0x%x\n", i.inst.bo, i.inst.bo); - debug_printf(" bi: %d 0x%x\n", i.inst.bi, i.inst.bi); - debug_printf(" unused: %d 0x%x\n", i.inst.unused, i.inst.unused); - debug_printf(" bh: %d 0x%x\n", i.inst.bh, i.inst.bh); - debug_printf(" op2: %d 0x%x\n", i.inst.op2, i.inst.op2); - debug_printf(" lk: %d 0x%x\n", i.inst.lk, i.inst.lk); -} - - -union x_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned vrs:5; - unsigned ra:5; - unsigned rb:5; - unsigned op2:10; - unsigned unused:1; - } inst; -}; - -static INLINE void -emit_x(struct ppc_function *p, uint op, uint vrs, uint ra, uint rb, uint op2, - const char *format) -{ - union x_inst inst; - inst.inst.op = op; - inst.inst.vrs = vrs; - inst.inst.ra = ra; - inst.inst.rb = rb; - inst.inst.op2 = op2; - inst.inst.unused = 0x0; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - printf(format, vrs, ra, rb); - } -} - - -union d_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned rt:5; - unsigned ra:5; - unsigned si:16; - } inst; -}; - -static INLINE void -emit_d(struct ppc_function *p, uint op, uint rt, uint ra, int si, - const char *format, boolean transpose) -{ - union d_inst inst; - assert(si >= -32768); - assert(si <= 32767); - inst.inst.op = op; - inst.inst.rt = rt; - inst.inst.ra = ra; - inst.inst.si = (unsigned) (si & 0xffff); - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - if (transpose) - printf(format, rt, si, ra); - else - printf(format, rt, ra, si); - } -} - - -union a_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned frt:5; - unsigned fra:5; - unsigned frb:5; - unsigned unused:5; - unsigned op2:5; - unsigned rc:1; - } inst; -}; - -static INLINE void -emit_a(struct ppc_function *p, uint op, uint frt, uint fra, uint frb, uint op2, - uint rc, const char *format) -{ - union a_inst inst; - inst.inst.op = op; - inst.inst.frt = frt; - inst.inst.fra = fra; - inst.inst.frb = frb; - inst.inst.unused = 0x0; - inst.inst.op2 = op2; - inst.inst.rc = rc; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - printf(format, frt, fra, frb); - } -} - - -union xo_inst { - uint32_t bits; - struct { - unsigned op:6; - unsigned rt:5; - unsigned ra:5; - unsigned rb:5; - unsigned oe:1; - unsigned op2:9; - unsigned rc:1; - } inst; -}; - -static INLINE void -emit_xo(struct ppc_function *p, uint op, uint rt, uint ra, uint rb, uint oe, - uint op2, uint rc, const char *format) -{ - union xo_inst inst; - inst.inst.op = op; - inst.inst.rt = rt; - inst.inst.ra = ra; - inst.inst.rb = rb; - inst.inst.oe = oe; - inst.inst.op2 = op2; - inst.inst.rc = rc; - emit_instruction(p, inst.bits); - if (p->print) { - indent(p); - printf(format, rt, ra, rb); - } -} - - - - - -/** - ** float vector arithmetic - **/ - -/** vector float add */ -void -ppc_vaddfp(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 10, vD, vA, vB, "vaddfp\t%u, v%u, v%u\n", FALSE); -} - -/** vector float substract */ -void -ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 74, vD, vA, vB, "vsubfp\tv%u, v%u, v%u\n", FALSE); -} - -/** vector float min */ -void -ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1098, vD, vA, vB, "vminfp\tv%u, v%u, v%u\n", FALSE); -} - -/** vector float max */ -void -ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1034, vD, vA, vB, "vmaxfp\tv%u, v%u, v%u\n", FALSE); -} - -/** vector float mult add: vD = vA * vB + vC */ -void -ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) -{ - /* note arg order */ - emit_va(p, 46, vD, vA, vC, vB, "vmaddfp\tv%u, v%u, v%u, v%u\n"); -} - -/** vector float negative mult subtract: vD = vA - vB * vC */ -void -ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) -{ - /* note arg order */ - emit_va(p, 47, vD, vB, vA, vC, "vnmsubfp\tv%u, v%u, v%u, v%u\n"); -} - -/** vector float compare greater than */ -void -ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vxr(p, 710, vD, vA, vB, "vcmpgtfpx\tv%u, v%u, v%u"); -} - -/** vector float compare greater than or equal to */ -void -ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vxr(p, 454, vD, vA, vB, "vcmpgefpx\tv%u, v%u, v%u"); -} - -/** vector float compare equal */ -void -ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vxr(p, 198, vD, vA, vB, "vcmpeqfpx\tv%u, v%u, v%u"); -} - -/** vector float 2^x */ -void -ppc_vexptefp(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 394, vD, 0, vB, "vexptefp\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float log2(x) */ -void -ppc_vlogefp(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 458, vD, 0, vB, "vlogefp\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float reciprocol */ -void -ppc_vrefp(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 266, vD, 0, vB, "vrefp\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float reciprocol sqrt estimate */ -void -ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 330, vD, 0, vB, "vrsqrtefp\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float round to negative infinity */ -void -ppc_vrfim(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 714, vD, 0, vB, "vrfim\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float round to positive infinity */ -void -ppc_vrfip(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 650, vD, 0, vB, "vrfip\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float round to nearest int */ -void -ppc_vrfin(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 522, vD, 0, vB, "vrfin\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector float round to int toward zero */ -void -ppc_vrfiz(struct ppc_function *p, uint vD, uint vB) -{ - emit_vx(p, 586, vD, 0, vB, "vrfiz\tv%u, 0%u, v%u\n", FALSE); -} - -/** vector store: store vR at mem[rA+rB] */ -void -ppc_stvx(struct ppc_function *p, uint vR, uint rA, uint rB) -{ - emit_x(p, 31, vR, rA, rB, 231, "stvx\tv%u, r%u, r%u\n"); -} - -/** vector load: vR = mem[rA+rB] */ -void -ppc_lvx(struct ppc_function *p, uint vR, uint rA, uint rB) -{ - emit_x(p, 31, vR, rA, rB, 103, "lvx\tv%u, r%u, r%u\n"); -} - -/** load vector element word: vR = mem_word[ra+rb] */ -void -ppc_lvewx(struct ppc_function *p, uint vR, uint rA, uint rB) -{ - emit_x(p, 31, vR, rA, rB, 71, "lvewx\tv%u, r%u, r%u\n"); -} - - - - -/** - ** vector bitwise operations - **/ - -/** vector and */ -void -ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1028, vD, vA, vB, "vand\tv%u, v%u, v%u\n", FALSE); -} - -/** vector and complement */ -void -ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1092, vD, vA, vB, "vandc\tv%u, v%u, v%u\n", FALSE); -} - -/** vector or */ -void -ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1156, vD, vA, vB, "vor\tv%u, v%u, v%u\n", FALSE); -} - -/** vector nor */ -void -ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1284, vD, vA, vB, "vnor\tv%u, v%u, v%u\n", FALSE); -} - -/** vector xor */ -void -ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 1220, vD, vA, vB, "vxor\tv%u, v%u, v%u\n", FALSE); -} - -/** Pseudo-instruction: vector move */ -void -ppc_vmove(struct ppc_function *p, uint vD, uint vA) -{ - boolean print = p->print; - p->print = FALSE; - ppc_vor(p, vD, vA, vA); - if (print) { - indent(p); - printf("vor\tv%u, v%u, v%u \t# v%u = v%u\n", vD, vA, vA, vD, vA); - } - p->print = print; -} - -/** Set vector register to {0,0,0,0} */ -void -ppc_vzero(struct ppc_function *p, uint vr) -{ - boolean print = p->print; - p->print = FALSE; - ppc_vxor(p, vr, vr, vr); - if (print) { - indent(p); - printf("vxor\tv%u, v%u, v%u \t# v%u = {0,0,0,0}\n", vr, vr, vr, vr); - } - p->print = print; -} - - - - -/** - ** Vector shuffle / select / splat / etc - **/ - -/** vector permute */ -void -ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) -{ - emit_va(p, 43, vD, vA, vB, vC, "vperm\tr%u, r%u, r%u, r%u"); -} - -/** vector select */ -void -ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) -{ - emit_va(p, 42, vD, vA, vB, vC, "vsel\tr%u, r%u, r%u, r%u"); -} - -/** vector splat byte */ -void -ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm) -{ - emit_vx(p, 42, vD, imm, vB, "vspltb\tv%u, v%u, %u\n", TRUE); -} - -/** vector splat half word */ -void -ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm) -{ - emit_vx(p, 588, vD, imm, vB, "vsplthw\tv%u, v%u, %u\n", TRUE); -} - -/** vector splat word */ -void -ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm) -{ - emit_vx(p, 652, vD, imm, vB, "vspltw\tv%u, v%u, %u\n", TRUE); -} - -/** vector splat signed immediate word */ -void -ppc_vspltisw(struct ppc_function *p, uint vD, int imm) -{ - assert(imm >= -16); - assert(imm < 15); - emit_vx(p, 908, vD, imm, 0, "vspltisw\tv%u, %d, %u\n", FALSE); -} - -/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */ -void -ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB) -{ - emit_vx(p, 388, vD, vA, vB, "vslw\tv%u, v%u, v%u\n", FALSE); -} - - - - -/** - ** integer arithmetic - **/ - -/** rt = ra + imm */ -void -ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm) -{ - emit_d(p, 14, rt, ra, imm, "addi\tr%u, r%u, %d\n", FALSE); -} - -/** rt = ra + (imm << 16) */ -void -ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm) -{ - emit_d(p, 15, rt, ra, imm, "addis\tr%u, r%u, %d\n", FALSE); -} - -/** rt = ra + rb */ -void -ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb) -{ - emit_xo(p, 31, rt, ra, rb, 0, 266, 0, "add\tr%u, r%u, r%u\n"); -} - -/** rt = ra AND ra */ -void -ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb) -{ - emit_x(p, 31, ra, rt, rb, 28, "and\tr%u, r%u, r%u\n"); /* note argument order */ -} - -/** rt = ra AND imm */ -void -ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm) -{ - /* note argument order */ - emit_d(p, 28, ra, rt, imm, "andi\tr%u, r%u, %d\n", FALSE); -} - -/** rt = ra OR ra */ -void -ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb) -{ - emit_x(p, 31, ra, rt, rb, 444, "or\tr%u, r%u, r%u\n"); /* note argument order */ -} - -/** rt = ra OR imm */ -void -ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm) -{ - /* note argument order */ - emit_d(p, 24, ra, rt, imm, "ori\tr%u, r%u, %d\n", FALSE); -} - -/** rt = ra XOR ra */ -void -ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb) -{ - emit_x(p, 31, ra, rt, rb, 316, "xor\tr%u, r%u, r%u\n"); /* note argument order */ -} - -/** rt = ra XOR imm */ -void -ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm) -{ - /* note argument order */ - emit_d(p, 26, ra, rt, imm, "xori\tr%u, r%u, %d\n", FALSE); -} - -/** pseudo instruction: move: rt = ra */ -void -ppc_mr(struct ppc_function *p, uint rt, uint ra) -{ - ppc_or(p, rt, ra, ra); -} - -/** pseudo instruction: load immediate: rt = imm */ -void -ppc_li(struct ppc_function *p, uint rt, int imm) -{ - boolean print = p->print; - p->print = FALSE; - ppc_addi(p, rt, 0, imm); - if (print) { - indent(p); - printf("addi\tr%u, r0, %d \t# r%u = %d\n", rt, imm, rt, imm); - } - p->print = print; -} - -/** rt = imm << 16 */ -void -ppc_lis(struct ppc_function *p, uint rt, int imm) -{ - ppc_addis(p, rt, 0, imm); -} - -/** rt = imm */ -void -ppc_load_int(struct ppc_function *p, uint rt, int imm) -{ - ppc_lis(p, rt, (imm >> 16)); /* rt = imm >> 16 */ - ppc_ori(p, rt, rt, (imm & 0xffff)); /* rt = rt | (imm & 0xffff) */ -} - - - - -/** - ** integer load/store - **/ - -/** store rs at memory[(ra)+d], - * then update ra = (ra)+d - */ -void -ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d) -{ - emit_d(p, 37, rs, ra, d, "stwu\tr%u, %d(r%u)\n", TRUE); -} - -/** store rs at memory[(ra)+d] */ -void -ppc_stw(struct ppc_function *p, uint rs, uint ra, int d) -{ - emit_d(p, 36, rs, ra, d, "stw\tr%u, %d(r%u)\n", TRUE); -} - -/** Load rt = mem[(ra)+d]; then zero set high 32 bits to zero. */ -void -ppc_lwz(struct ppc_function *p, uint rt, uint ra, int d) -{ - emit_d(p, 32, rt, ra, d, "lwz\tr%u, %d(r%u)\n", TRUE); -} - - - -/** - ** Float (non-vector) arithmetic - **/ - -/** add: frt = fra + frb */ -void -ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb) -{ - emit_a(p, 63, frt, fra, frb, 21, 0, "fadd\tf%u, f%u, f%u\n"); -} - -/** sub: frt = fra - frb */ -void -ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb) -{ - emit_a(p, 63, frt, fra, frb, 20, 0, "fsub\tf%u, f%u, f%u\n"); -} - -/** convert to int: rt = (int) ra */ -void -ppc_fctiwz(struct ppc_function *p, uint rt, uint fra) -{ - emit_x(p, 63, rt, 0, fra, 15, "fctiwz\tr%u, r%u, r%u\n"); -} - -/** store frs at mem[(ra)+offset] */ -void -ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset) -{ - emit_d(p, 52, frs, ra, offset, "stfs\tr%u, %d(r%u)\n", TRUE); -} - -/** store frs at mem[(ra)+(rb)] */ -void -ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb) -{ - emit_x(p, 31, frs, ra, rb, 983, "stfiwx\tr%u, r%u, r%u\n"); -} - -/** load frt = mem[(ra)+offset] */ -void -ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset) -{ - emit_d(p, 48, frt, ra, offset, "stfs\tr%u, %d(r%u)\n", TRUE); -} - - - - - -/** - ** branch instructions - **/ - -/** BLR: Branch to link register (p. 35) */ -void -ppc_blr(struct ppc_function *p) -{ - emit_i(p, 18, 0, 0, 1); - if (p->print) { - indent(p); - printf("blr\n"); - } -} - -/** Branch Conditional to Link Register (p. 36) */ -void -ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg) -{ - emit_xl(p, 19, condOp, condReg, branchHint, 16, 0); - if (p->print) { - indent(p); - printf("bclr\t%u %u %u\n", condOp, branchHint, condReg); - } -} - -/** Pseudo instruction: return from subroutine */ -void -ppc_return(struct ppc_function *p) -{ - ppc_bclr(p, BRANCH_COND_ALWAYS, BRANCH_HINT_SUB_RETURN, 0); -} diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc.h b/src/gallium/auxiliary/rtasm/rtasm_ppc.h deleted file mode 100644 index 93e5f5187de..00000000000 --- a/src/gallium/auxiliary/rtasm/rtasm_ppc.h +++ /dev/null @@ -1,342 +0,0 @@ -/************************************************************************** - * - * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved. - * Copyright (C) 2009 VMware, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * PPC code generation. - * \author Brian Paul - */ - - -#ifndef RTASM_PPC_H -#define RTASM_PPC_H - - -#include "pipe/p_compiler.h" - - -#define PPC_INST_SIZE 4 /**< 4 bytes / instruction */ - -#define PPC_NUM_REGS 32 -#define PPC_NUM_FP_REGS 32 -#define PPC_NUM_VEC_REGS 32 - -/** Stack pointer register */ -#define PPC_REG_SP 1 - -/** Branch conditions */ -#define BRANCH_COND_ALWAYS 0x14 /* binary 1z1zz (z=ignored) */ - -/** Branch hints */ -#define BRANCH_HINT_SUB_RETURN 0x0 /* binary 00 */ - - -struct ppc_function -{ - uint32_t *store; /**< instruction buffer */ - uint num_inst; - uint max_inst; - uint32_t reg_used; /** used/free general-purpose registers bitmask */ - uint32_t fp_used; /** used/free floating point registers bitmask */ - uint32_t vec_used; /** used/free vector registers bitmask */ - int indent; - boolean print; -}; - - - -extern void ppc_init_func(struct ppc_function *p); -extern void ppc_release_func(struct ppc_function *p); -extern uint ppc_num_instructions(const struct ppc_function *p); -extern void (*ppc_get_func( struct ppc_function *p ))( void ); -extern void ppc_dump_func(const struct ppc_function *p); - -extern void ppc_print_code(struct ppc_function *p, boolean enable); -extern void ppc_indent(struct ppc_function *p, int spaces); -extern void ppc_comment(struct ppc_function *p, int rel_indent, const char *s); - -extern int ppc_reserve_register(struct ppc_function *p, int reg); -extern int ppc_allocate_register(struct ppc_function *p); -extern void ppc_release_register(struct ppc_function *p, int reg); -extern int ppc_allocate_fp_register(struct ppc_function *p); -extern void ppc_release_fp_register(struct ppc_function *p, int reg); -extern int ppc_allocate_vec_register(struct ppc_function *p); -extern void ppc_release_vec_register(struct ppc_function *p, int reg); - - - -/** - ** float vector arithmetic - **/ - -/** vector float add */ -extern void -ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB); - -/** vector float substract */ -extern void -ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float min */ -extern void -ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float max */ -extern void -ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float mult add: vD = vA * vB + vC */ -extern void -ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); - -/** vector float negative mult subtract: vD = vA - vB * vC */ -extern void -ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); - -/** vector float compare greater than */ -extern void -ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float compare greater than or equal to */ -extern void -ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float compare equal */ -extern void -ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector float 2^x */ -extern void -ppc_vexptefp(struct ppc_function *p, uint vD, uint vB); - -/** vector float log2(x) */ -extern void -ppc_vlogefp(struct ppc_function *p, uint vD, uint vB); - -/** vector float reciprocol */ -extern void -ppc_vrefp(struct ppc_function *p, uint vD, uint vB); - -/** vector float reciprocol sqrt estimate */ -extern void -ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB); - -/** vector float round to negative infinity */ -extern void -ppc_vrfim(struct ppc_function *p, uint vD, uint vB); - -/** vector float round to positive infinity */ -extern void -ppc_vrfip(struct ppc_function *p, uint vD, uint vB); - -/** vector float round to nearest int */ -extern void -ppc_vrfin(struct ppc_function *p, uint vD, uint vB); - -/** vector float round to int toward zero */ -extern void -ppc_vrfiz(struct ppc_function *p, uint vD, uint vB); - - -/** vector store: store vR at mem[vA+vB] */ -extern void -ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB); - -/** vector load: vR = mem[vA+vB] */ -extern void -ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB); - -/** load vector element word: vR = mem_word[vA+vB] */ -extern void -ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB); - - - -/** - ** vector bitwise operations - **/ - - -/** vector and */ -extern void -ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector and complement */ -extern void -ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector or */ -extern void -ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector nor */ -extern void -ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** vector xor */ -extern void -ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB); - -/** Pseudo-instruction: vector move */ -extern void -ppc_vmove(struct ppc_function *p, uint vD, uint vA); - -/** Set vector register to {0,0,0,0} */ -extern void -ppc_vzero(struct ppc_function *p, uint vr); - - - -/** - ** Vector shuffle / select / splat / etc - **/ - -/** vector permute */ -extern void -ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); - -/** vector select */ -extern void -ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); - -/** vector splat byte */ -extern void -ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm); - -/** vector splat half word */ -extern void -ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm); - -/** vector splat word */ -extern void -ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm); - -/** vector splat signed immediate word */ -extern void -ppc_vspltisw(struct ppc_function *p, uint vD, int imm); - -/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */ -extern void -ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB); - - - -/** - ** scalar arithmetic - **/ - -extern void -ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb); - -extern void -ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm); - -extern void -ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm); - -extern void -ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb); - -extern void -ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm); - -extern void -ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb); - -extern void -ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm); - -extern void -ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb); - -extern void -ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm); - -extern void -ppc_mr(struct ppc_function *p, uint rt, uint ra); - -extern void -ppc_li(struct ppc_function *p, uint rt, int imm); - -extern void -ppc_lis(struct ppc_function *p, uint rt, int imm); - -extern void -ppc_load_int(struct ppc_function *p, uint rt, int imm); - - - -/** - ** scalar load/store - **/ - -extern void -ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d); - -extern void -ppc_stw(struct ppc_function *p, uint rs, uint ra, int d); - -extern void -ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d); - - - -/** - ** Float (non-vector) arithmetic - **/ - -extern void -ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb); - -extern void -ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb); - -extern void -ppc_fctiwz(struct ppc_function *p, uint rt, uint ra); - -extern void -ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset); - -extern void -ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb); - -extern void -ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset); - - - -/** - ** branch instructions - **/ - -extern void -ppc_blr(struct ppc_function *p); - -void -ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg); - -extern void -ppc_return(struct ppc_function *p); - - -#endif /* RTASM_PPC_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_ppc.c b/src/gallium/auxiliary/tgsi/tgsi_ppc.c deleted file mode 100644 index ce728ecee06..00000000000 --- a/src/gallium/auxiliary/tgsi/tgsi_ppc.c +++ /dev/null @@ -1,1359 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * TGSI to PowerPC code generation. - */ - -#include "pipe/p_config.h" - -#if defined(PIPE_ARCH_PPC) - -#include "util/u_debug.h" -#include "pipe/p_shader_tokens.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "util/u_sse.h" -#include "tgsi/tgsi_info.h" -#include "tgsi/tgsi_parse.h" -#include "tgsi/tgsi_util.h" -#include "tgsi_dump.h" -#include "tgsi_exec.h" -#include "tgsi_ppc.h" -#include "rtasm/rtasm_ppc.h" - - -/** - * Since it's pretty much impossible to form PPC vector immediates, load - * them from memory here: - */ -PIPE_ALIGN_VAR(16) const float -ppc_builtin_constants[] = { - 1.0f, -128.0f, 128.0, 0.0 -}; - -/** - * How many TGSI temps should be implemented with real PPC vector registers - * rather than memory. - */ -#define MAX_PPC_TEMPS 3 - - -/** - * Context/state used during code gen. - */ -struct gen_context -{ - struct ppc_function *f; - int inputs_reg; /**< GP register pointing to input params */ - int outputs_reg; /**< GP register pointing to output params */ - int temps_reg; /**< GP register pointing to temporary "registers" */ - int immed_reg; /**< GP register pointing to immediates buffer */ - int const_reg; /**< GP register pointing to constants buffer */ - int builtins_reg; /**< GP register pointint to built-in constants */ - - int offset_reg; /**< used to reduce redundant li instructions */ - int offset_value; - - int one_vec; /**< vector register with {1.0, 1.0, 1.0, 1.0} */ - int bit31_vec; /**< vector register with {1<<31, 1<<31, 1<<31, 1<<31} */ - - /** - * Map TGSI temps to PPC vector temps. - * We have 32 PPC vector regs. Use 16 of them for storing 4 TGSI temps. - * XXX currently only do this for TGSI temps [0..MAX_PPC_TEMPS-1]. - */ - int temps_map[MAX_PPC_TEMPS][4]; - - /** - * Cache of src registers. - * This is used to avoid redundant load instructions. - */ - struct { - struct tgsi_full_src_register src; - uint chan; - uint vec; - } regs[12]; /* 3 src regs, 4 channels */ - uint num_regs; -}; - - -/** - * Initialize code generation context. - */ -static void -init_gen_context(struct gen_context *gen, struct ppc_function *func) -{ - uint i; - - memset(gen, 0, sizeof(*gen)); - gen->f = func; - gen->inputs_reg = ppc_reserve_register(func, 3); /* first function param */ - gen->outputs_reg = ppc_reserve_register(func, 4); /* second function param */ - gen->temps_reg = ppc_reserve_register(func, 5); /* ... */ - gen->immed_reg = ppc_reserve_register(func, 6); - gen->const_reg = ppc_reserve_register(func, 7); - gen->builtins_reg = ppc_reserve_register(func, 8); - gen->one_vec = -1; - gen->bit31_vec = -1; - gen->offset_reg = -1; - gen->offset_value = -9999999; - for (i = 0; i < MAX_PPC_TEMPS; i++) { - gen->temps_map[i][0] = ppc_allocate_vec_register(gen->f); - gen->temps_map[i][1] = ppc_allocate_vec_register(gen->f); - gen->temps_map[i][2] = ppc_allocate_vec_register(gen->f); - gen->temps_map[i][3] = ppc_allocate_vec_register(gen->f); - } -} - - -/** - * Is the given TGSI register stored as a real PPC vector register? - */ -static boolean -is_ppc_vec_temporary(const struct tgsi_full_src_register *reg) -{ - return (reg->Register.File == TGSI_FILE_TEMPORARY && - reg->Register.Index < MAX_PPC_TEMPS); -} - - -/** - * Is the given TGSI register stored as a real PPC vector register? - */ -static boolean -is_ppc_vec_temporary_dst(const struct tgsi_full_dst_register *reg) -{ - return (reg->Register.File == TGSI_FILE_TEMPORARY && - reg->Register.Index < MAX_PPC_TEMPS); -} - - - -/** - * All PPC vector load/store instructions form an effective address - * by adding the contents of two registers. For example: - * lvx v2,r8,r9 # v2 = memory[r8 + r9] - * stvx v2,r8,r9 # memory[r8 + r9] = v2; - * So our lvx/stvx instructions are typically preceded by an 'li' instruction - * to load r9 (above) with an immediate (an offset). - * This code emits that 'li' instruction, but only if the offset value is - * different than the previous 'li'. - * This optimization seems to save about 10% in the instruction count. - * Note that we need to unconditionally emit an 'li' inside basic blocks - * (such as inside loops). - */ -static int -emit_li_offset(struct gen_context *gen, int offset) -{ - if (gen->offset_reg <= 0) { - /* allocate a GP register for storing load/store offset */ - gen->offset_reg = ppc_allocate_register(gen->f); - } - - /* emit new 'li' if offset is changing */ - if (gen->offset_value < 0 || gen->offset_value != offset) { - gen->offset_value = offset; - ppc_li(gen->f, gen->offset_reg, offset); - } - - return gen->offset_reg; -} - - -/** - * Forces subsequent emit_li_offset() calls to emit an 'li'. - * To be called at the top of basic blocks. - */ -static void -reset_li_offset(struct gen_context *gen) -{ - gen->offset_value = -9999999; -} - - - -/** - * Load the given vector register with {value, value, value, value}. - * The value must be in the ppu_builtin_constants[] array. - * We wouldn't need this if there was a simple way to load PPC vector - * registers with immediate values! - */ -static void -load_constant_vec(struct gen_context *gen, int dst_vec, float value) -{ - uint pos; - for (pos = 0; pos < Elements(ppc_builtin_constants); pos++) { - if (ppc_builtin_constants[pos] == value) { - int offset = pos * 4; - int offset_reg = emit_li_offset(gen, offset); - - /* Load 4-byte word into vector register. - * The vector slot depends on the effective address we load from. - * We know that our builtins start at a 16-byte boundary so we - * know that 'swizzle' tells us which vector slot will have the - * loaded word. The other vector slots will be undefined. - */ - ppc_lvewx(gen->f, dst_vec, gen->builtins_reg, offset_reg); - /* splat word[pos % 4] across the vector reg */ - ppc_vspltw(gen->f, dst_vec, dst_vec, pos % 4); - return; - } - } - assert(0 && "Need to add new constant to ppc_builtin_constants array"); -} - - -/** - * Return index of vector register containing {1.0, 1.0, 1.0, 1.0}. - */ -static int -gen_one_vec(struct gen_context *gen) -{ - if (gen->one_vec < 0) { - gen->one_vec = ppc_allocate_vec_register(gen->f); - load_constant_vec(gen, gen->one_vec, 1.0f); - } - return gen->one_vec; -} - -/** - * Return index of vector register containing {1<<31, 1<<31, 1<<31, 1<<31}. - */ -static int -gen_get_bit31_vec(struct gen_context *gen) -{ - if (gen->bit31_vec < 0) { - gen->bit31_vec = ppc_allocate_vec_register(gen->f); - ppc_vspltisw(gen->f, gen->bit31_vec, -1); - ppc_vslw(gen->f, gen->bit31_vec, gen->bit31_vec, gen->bit31_vec); - } - return gen->bit31_vec; -} - - -/** - * Register fetch. Return PPC vector register with result. - */ -static int -emit_fetch(struct gen_context *gen, - const struct tgsi_full_src_register *reg, - const unsigned chan_index) -{ - uint swizzle = tgsi_util_get_full_src_register_swizzle(reg, chan_index); - int dst_vec = -1; - - switch (swizzle) { - case TGSI_SWIZZLE_X: - case TGSI_SWIZZLE_Y: - case TGSI_SWIZZLE_Z: - case TGSI_SWIZZLE_W: - switch (reg->Register.File) { - case TGSI_FILE_INPUT: - { - int offset = (reg->Register.Index * 4 + swizzle) * 16; - int offset_reg = emit_li_offset(gen, offset); - dst_vec = ppc_allocate_vec_register(gen->f); - ppc_lvx(gen->f, dst_vec, gen->inputs_reg, offset_reg); - } - break; - case TGSI_FILE_SYSTEM_VALUE: - assert(!"unhandled system value in tgsi_ppc.c"); - break; - case TGSI_FILE_TEMPORARY: - if (is_ppc_vec_temporary(reg)) { - /* use PPC vec register */ - dst_vec = gen->temps_map[reg->Register.Index][swizzle]; - } - else { - /* use memory-based temp register "file" */ - int offset = (reg->Register.Index * 4 + swizzle) * 16; - int offset_reg = emit_li_offset(gen, offset); - dst_vec = ppc_allocate_vec_register(gen->f); - ppc_lvx(gen->f, dst_vec, gen->temps_reg, offset_reg); - } - break; - case TGSI_FILE_IMMEDIATE: - { - int offset = (reg->Register.Index * 4 + swizzle) * 4; - int offset_reg = emit_li_offset(gen, offset); - dst_vec = ppc_allocate_vec_register(gen->f); - /* Load 4-byte word into vector register. - * The vector slot depends on the effective address we load from. - * We know that our immediates start at a 16-byte boundary so we - * know that 'swizzle' tells us which vector slot will have the - * loaded word. The other vector slots will be undefined. - */ - ppc_lvewx(gen->f, dst_vec, gen->immed_reg, offset_reg); - /* splat word[swizzle] across the vector reg */ - ppc_vspltw(gen->f, dst_vec, dst_vec, swizzle); - } - break; - case TGSI_FILE_CONSTANT: - { - int offset = (reg->Register.Index * 4 + swizzle) * 4; - int offset_reg = emit_li_offset(gen, offset); - dst_vec = ppc_allocate_vec_register(gen->f); - /* Load 4-byte word into vector register. - * The vector slot depends on the effective address we load from. - * We know that our constants start at a 16-byte boundary so we - * know that 'swizzle' tells us which vector slot will have the - * loaded word. The other vector slots will be undefined. - */ - ppc_lvewx(gen->f, dst_vec, gen->const_reg, offset_reg); - /* splat word[swizzle] across the vector reg */ - ppc_vspltw(gen->f, dst_vec, dst_vec, swizzle); - } - break; - default: - assert( 0 ); - } - break; - default: - assert( 0 ); - } - - assert(dst_vec >= 0); - - { - uint sign_op = tgsi_util_get_full_src_register_sign_mode(reg, chan_index); - if (sign_op != TGSI_UTIL_SIGN_KEEP) { - int bit31_vec = gen_get_bit31_vec(gen); - int dst_vec2; - - if (is_ppc_vec_temporary(reg)) { - /* need to use a new temp */ - dst_vec2 = ppc_allocate_vec_register(gen->f); - } - else { - dst_vec2 = dst_vec; - } - - switch (sign_op) { - case TGSI_UTIL_SIGN_CLEAR: - /* vec = vec & ~bit31 */ - ppc_vandc(gen->f, dst_vec2, dst_vec, bit31_vec); - break; - case TGSI_UTIL_SIGN_SET: - /* vec = vec | bit31 */ - ppc_vor(gen->f, dst_vec2, dst_vec, bit31_vec); - break; - case TGSI_UTIL_SIGN_TOGGLE: - /* vec = vec ^ bit31 */ - ppc_vxor(gen->f, dst_vec2, dst_vec, bit31_vec); - break; - default: - assert(0); - } - return dst_vec2; - } - } - - return dst_vec; -} - - - -/** - * Test if two TGSI src registers refer to the same memory location. - * We use this to avoid redundant register loads. - */ -static boolean -equal_src_locs(const struct tgsi_full_src_register *a, uint chan_a, - const struct tgsi_full_src_register *b, uint chan_b) -{ - int swz_a, swz_b; - int sign_a, sign_b; - if (a->Register.File != b->Register.File) - return FALSE; - if (a->Register.Index != b->Register.Index) - return FALSE; - swz_a = tgsi_util_get_full_src_register_swizzle(a, chan_a); - swz_b = tgsi_util_get_full_src_register_swizzle(b, chan_b); - if (swz_a != swz_b) - return FALSE; - sign_a = tgsi_util_get_full_src_register_sign_mode(a, chan_a); - sign_b = tgsi_util_get_full_src_register_sign_mode(b, chan_b); - if (sign_a != sign_b) - return FALSE; - return TRUE; -} - - -/** - * Given a TGSI src register and channel index, return the PPC vector - * register containing the value. We use a cache to prevent re-loading - * the same register multiple times. - * \return index of PPC vector register with the desired src operand - */ -static int -get_src_vec(struct gen_context *gen, - struct tgsi_full_instruction *inst, int src_reg, uint chan) -{ - const const struct tgsi_full_src_register *src = - &inst->Src[src_reg]; - int vec; - uint i; - - /* check the cache */ - for (i = 0; i < gen->num_regs; i++) { - if (equal_src_locs(&gen->regs[i].src, gen->regs[i].chan, src, chan)) { - /* cache hit */ - assert(gen->regs[i].vec >= 0); - return gen->regs[i].vec; - } - } - - /* cache miss: allocate new vec reg and emit fetch/load code */ - vec = emit_fetch(gen, src, chan); - gen->regs[gen->num_regs].src = *src; - gen->regs[gen->num_regs].chan = chan; - gen->regs[gen->num_regs].vec = vec; - gen->num_regs++; - - assert(gen->num_regs <= Elements(gen->regs)); - - assert(vec >= 0); - - return vec; -} - - -/** - * Clear the src operand cache. To be called at the end of each emit function. - */ -static void -release_src_vecs(struct gen_context *gen) -{ - uint i; - for (i = 0; i < gen->num_regs; i++) { - const const struct tgsi_full_src_register src = gen->regs[i].src; - if (!is_ppc_vec_temporary(&src)) { - ppc_release_vec_register(gen->f, gen->regs[i].vec); - } - } - gen->num_regs = 0; -} - - - -static int -get_dst_vec(struct gen_context *gen, - const struct tgsi_full_instruction *inst, - unsigned chan_index) -{ - const struct tgsi_full_dst_register *reg = &inst->Dst[0]; - - if (is_ppc_vec_temporary_dst(reg)) { - int vec = gen->temps_map[reg->Register.Index][chan_index]; - return vec; - } - else { - return ppc_allocate_vec_register(gen->f); - } -} - - -/** - * Register store. Store 'src_vec' at location indicated by 'reg'. - * \param free_vec Should the src_vec be released when done? - */ -static void -emit_store(struct gen_context *gen, - int src_vec, - const struct tgsi_full_instruction *inst, - unsigned chan_index, - boolean free_vec) -{ - const struct tgsi_full_dst_register *reg = &inst->Dst[0]; - - switch (reg->Register.File) { - case TGSI_FILE_OUTPUT: - { - int offset = (reg->Register.Index * 4 + chan_index) * 16; - int offset_reg = emit_li_offset(gen, offset); - ppc_stvx(gen->f, src_vec, gen->outputs_reg, offset_reg); - } - break; - case TGSI_FILE_TEMPORARY: - if (is_ppc_vec_temporary_dst(reg)) { - if (!free_vec) { - int dst_vec = gen->temps_map[reg->Register.Index][chan_index]; - if (dst_vec != src_vec) - ppc_vmove(gen->f, dst_vec, src_vec); - } - free_vec = FALSE; - } - else { - int offset = (reg->Register.Index * 4 + chan_index) * 16; - int offset_reg = emit_li_offset(gen, offset); - ppc_stvx(gen->f, src_vec, gen->temps_reg, offset_reg); - } - break; -#if 0 - case TGSI_FILE_ADDRESS: - emit_addrs( - func, - xmm, - reg->Register.Index, - chan_index ); - break; -#endif - default: - assert( 0 ); - } - -#if 0 - switch( inst->Instruction.Saturate ) { - case TGSI_SAT_NONE: - break; - - case TGSI_SAT_ZERO_ONE: - /* assert( 0 ); */ - break; - - case TGSI_SAT_MINUS_PLUS_ONE: - assert( 0 ); - break; - } -#endif - - if (free_vec) - ppc_release_vec_register(gen->f, src_vec); -} - - -static void -emit_scalar_unaryop(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int v0, v1; - uint chan_index; - - v0 = get_src_vec(gen, inst, 0, TGSI_CHAN_X); - v1 = ppc_allocate_vec_register(gen->f); - - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_RSQ: - /* v1 = 1.0 / sqrt(v0) */ - ppc_vrsqrtefp(gen->f, v1, v0); - break; - case TGSI_OPCODE_RCP: - /* v1 = 1.0 / v0 */ - ppc_vrefp(gen->f, v1, v0); - break; - default: - assert(0); - } - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { - emit_store(gen, v1, inst, chan_index, FALSE); - } - - release_src_vecs(gen); - ppc_release_vec_register(gen->f, v1); -} - - -static void -emit_unaryop(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - uint chan_index; - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan_index) { - int v0 = get_src_vec(gen, inst, 0, chan_index); /* v0 = srcreg[0] */ - int v1 = get_dst_vec(gen, inst, chan_index); - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_ABS: - /* turn off the most significant bit of each vector float word */ - { - int bit31_vec = gen_get_bit31_vec(gen); - ppc_vandc(gen->f, v1, v0, bit31_vec); /* v1 = v0 & ~bit31 */ - } - break; - case TGSI_OPCODE_FLR: - ppc_vrfim(gen->f, v1, v0); /* v1 = floor(v0) */ - break; - case TGSI_OPCODE_FRC: - ppc_vrfim(gen->f, v1, v0); /* tmp = floor(v0) */ - ppc_vsubfp(gen->f, v1, v0, v1); /* v1 = v0 - v1 */ - break; - case TGSI_OPCODE_EX2: - ppc_vexptefp(gen->f, v1, v0); /* v1 = 2^v0 */ - break; - case TGSI_OPCODE_LG2: - /* XXX this may be broken! */ - ppc_vlogefp(gen->f, v1, v0); /* v1 = log2(v0) */ - break; - case TGSI_OPCODE_MOV: - if (v0 != v1) - ppc_vmove(gen->f, v1, v0); - break; - default: - assert(0); - } - emit_store(gen, v1, inst, chan_index, TRUE); /* store v0 */ - } - - release_src_vecs(gen); -} - - -static void -emit_binop(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int zero_vec = -1; - uint chan; - - if (inst->Instruction.Opcode == TGSI_OPCODE_MUL) { - zero_vec = ppc_allocate_vec_register(gen->f); - ppc_vzero(gen->f, zero_vec); - } - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan) { - /* fetch src operands */ - int v0 = get_src_vec(gen, inst, 0, chan); - int v1 = get_src_vec(gen, inst, 1, chan); - int v2 = get_dst_vec(gen, inst, chan); - - /* emit binop */ - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_ADD: - ppc_vaddfp(gen->f, v2, v0, v1); - break; - case TGSI_OPCODE_SUB: - ppc_vsubfp(gen->f, v2, v0, v1); - break; - case TGSI_OPCODE_MUL: - ppc_vmaddfp(gen->f, v2, v0, v1, zero_vec); - break; - case TGSI_OPCODE_MIN: - ppc_vminfp(gen->f, v2, v0, v1); - break; - case TGSI_OPCODE_MAX: - ppc_vmaxfp(gen->f, v2, v0, v1); - break; - default: - assert(0); - } - - /* store v2 */ - emit_store(gen, v2, inst, chan, TRUE); - } - - if (inst->Instruction.Opcode == TGSI_OPCODE_MUL) - ppc_release_vec_register(gen->f, zero_vec); - - release_src_vecs(gen); -} - - -static void -emit_triop(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - uint chan; - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan) { - /* fetch src operands */ - int v0 = get_src_vec(gen, inst, 0, chan); - int v1 = get_src_vec(gen, inst, 1, chan); - int v2 = get_src_vec(gen, inst, 2, chan); - int v3 = get_dst_vec(gen, inst, chan); - - /* emit ALU */ - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_MAD: - ppc_vmaddfp(gen->f, v3, v0, v1, v2); /* v3 = v0 * v1 + v2 */ - break; - case TGSI_OPCODE_LRP: - ppc_vsubfp(gen->f, v3, v1, v2); /* v3 = v1 - v2 */ - ppc_vmaddfp(gen->f, v3, v0, v3, v2); /* v3 = v0 * v3 + v2 */ - break; - default: - assert(0); - } - - /* store v3 */ - emit_store(gen, v3, inst, chan, TRUE); - } - - release_src_vecs(gen); -} - - -/** - * Vector comparisons, resulting in 1.0 or 0.0 values. - */ -static void -emit_inequality(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - uint chan; - int one_vec = gen_one_vec(gen); - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan) { - /* fetch src operands */ - int v0 = get_src_vec(gen, inst, 0, chan); - int v1 = get_src_vec(gen, inst, 1, chan); - int v2 = get_dst_vec(gen, inst, chan); - boolean complement = FALSE; - - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_SNE: - complement = TRUE; - /* fall-through */ - case TGSI_OPCODE_SEQ: - ppc_vcmpeqfpx(gen->f, v2, v0, v1); /* v2 = v0 == v1 ? ~0 : 0 */ - break; - - case TGSI_OPCODE_SGE: - complement = TRUE; - /* fall-through */ - case TGSI_OPCODE_SLT: - ppc_vcmpgtfpx(gen->f, v2, v1, v0); /* v2 = v1 > v0 ? ~0 : 0 */ - break; - - case TGSI_OPCODE_SLE: - complement = TRUE; - /* fall-through */ - case TGSI_OPCODE_SGT: - ppc_vcmpgtfpx(gen->f, v2, v0, v1); /* v2 = v0 > v1 ? ~0 : 0 */ - break; - default: - assert(0); - } - - /* v2 is now {0,0,0,0} or {~0,~0,~0,~0} */ - - if (complement) - ppc_vandc(gen->f, v2, one_vec, v2); /* v2 = one_vec & ~v2 */ - else - ppc_vand(gen->f, v2, one_vec, v2); /* v2 = one_vec & v2 */ - - /* store v2 */ - emit_store(gen, v2, inst, chan, TRUE); - } - - release_src_vecs(gen); -} - - -static void -emit_dotprod(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int v0, v1, v2; - uint chan_index; - - v2 = ppc_allocate_vec_register(gen->f); - - ppc_vzero(gen->f, v2); /* v2 = {0, 0, 0, 0} */ - - v0 = get_src_vec(gen, inst, 0, TGSI_CHAN_X); /* v0 = src0.XXXX */ - v1 = get_src_vec(gen, inst, 1, TGSI_CHAN_X); /* v1 = src1.XXXX */ - ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ - - v0 = get_src_vec(gen, inst, 0, TGSI_CHAN_Y); /* v0 = src0.YYYY */ - v1 = get_src_vec(gen, inst, 1, TGSI_CHAN_Y); /* v1 = src1.YYYY */ - ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ - - v0 = get_src_vec(gen, inst, 0, TGSI_CHAN_Z); /* v0 = src0.ZZZZ */ - v1 = get_src_vec(gen, inst, 1, TGSI_CHAN_Z); /* v1 = src1.ZZZZ */ - ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ - - if (inst->Instruction.Opcode == TGSI_OPCODE_DP4) { - v0 = get_src_vec(gen, inst, 0, TGSI_CHAN_W); /* v0 = src0.WWWW */ - v1 = get_src_vec(gen, inst, 1, TGSI_CHAN_W); /* v1 = src1.WWWW */ - ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ - } - else if (inst->Instruction.Opcode == TGSI_OPCODE_DPH) { - v1 = get_src_vec(gen, inst, 1, TGSI_CHAN_W); /* v1 = src1.WWWW */ - ppc_vaddfp(gen->f, v2, v2, v1); /* v2 = v2 + v1 */ - } - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan_index) { - emit_store(gen, v2, inst, chan_index, FALSE); /* store v2, free v2 later */ - } - - release_src_vecs(gen); - - ppc_release_vec_register(gen->f, v2); -} - - -/** Approximation for vr = pow(va, vb) */ -static void -ppc_vec_pow(struct ppc_function *f, int vr, int va, int vb) -{ - /* pow(a,b) ~= exp2(log2(a) * b) */ - int t_vec = ppc_allocate_vec_register(f); - int zero_vec = ppc_allocate_vec_register(f); - - ppc_vzero(f, zero_vec); - - ppc_vlogefp(f, t_vec, va); /* t = log2(va) */ - ppc_vmaddfp(f, t_vec, t_vec, vb, zero_vec); /* t = t * vb + zero */ - ppc_vexptefp(f, vr, t_vec); /* vr = 2^t */ - - ppc_release_vec_register(f, t_vec); - ppc_release_vec_register(f, zero_vec); -} - - -static void -emit_lit(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int one_vec = gen_one_vec(gen); - - /* Compute X */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X)) { - emit_store(gen, one_vec, inst, TGSI_CHAN_X, FALSE); - } - - /* Compute Y, Z */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y) || - TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - int x_vec; - int zero_vec = ppc_allocate_vec_register(gen->f); - - x_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_X); /* x_vec = src[0].x */ - - ppc_vzero(gen->f, zero_vec); /* zero = {0,0,0,0} */ - ppc_vmaxfp(gen->f, x_vec, x_vec, zero_vec); /* x_vec = max(x_vec, 0) */ - - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y)) { - emit_store(gen, x_vec, inst, TGSI_CHAN_Y, FALSE); - } - - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - int y_vec, w_vec; - int z_vec = ppc_allocate_vec_register(gen->f); - int pow_vec = ppc_allocate_vec_register(gen->f); - int pos_vec = ppc_allocate_vec_register(gen->f); - int p128_vec = ppc_allocate_vec_register(gen->f); - int n128_vec = ppc_allocate_vec_register(gen->f); - - y_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_Y); /* y_vec = src[0].y */ - ppc_vmaxfp(gen->f, y_vec, y_vec, zero_vec); /* y_vec = max(y_vec, 0) */ - - w_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_W); /* w_vec = src[0].w */ - - /* clamp W to [-128, 128] */ - load_constant_vec(gen, p128_vec, 128.0f); - load_constant_vec(gen, n128_vec, -128.0f); - ppc_vmaxfp(gen->f, w_vec, w_vec, n128_vec); /* w = max(w, -128) */ - ppc_vminfp(gen->f, w_vec, w_vec, p128_vec); /* w = min(w, 128) */ - - /* if temp.x > 0 - * z = pow(tmp.y, tmp.w) - * else - * z = 0.0 - */ - ppc_vec_pow(gen->f, pow_vec, y_vec, w_vec); /* pow = pow(y, w) */ - ppc_vcmpgtfpx(gen->f, pos_vec, x_vec, zero_vec); /* pos = x > 0 */ - ppc_vand(gen->f, z_vec, pow_vec, pos_vec); /* z = pow & pos */ - - emit_store(gen, z_vec, inst, TGSI_CHAN_Z, FALSE); - - ppc_release_vec_register(gen->f, z_vec); - ppc_release_vec_register(gen->f, pow_vec); - ppc_release_vec_register(gen->f, pos_vec); - ppc_release_vec_register(gen->f, p128_vec); - ppc_release_vec_register(gen->f, n128_vec); - } - - ppc_release_vec_register(gen->f, zero_vec); - } - - /* Compute W */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_W)) { - emit_store(gen, one_vec, inst, TGSI_CHAN_W, FALSE); - } - - release_src_vecs(gen); -} - - -static void -emit_exp(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - const int one_vec = gen_one_vec(gen); - int src_vec; - - /* get src arg */ - src_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_X); - - /* Compute X = 2^floor(src) */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X)) { - int dst_vec = get_dst_vec(gen, inst, TGSI_CHAN_X); - int tmp_vec = ppc_allocate_vec_register(gen->f); - ppc_vrfim(gen->f, tmp_vec, src_vec); /* tmp = floor(src); */ - ppc_vexptefp(gen->f, dst_vec, tmp_vec); /* dst = 2 ^ tmp */ - emit_store(gen, dst_vec, inst, TGSI_CHAN_X, TRUE); - ppc_release_vec_register(gen->f, tmp_vec); - } - - /* Compute Y = src - floor(src) */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y)) { - int dst_vec = get_dst_vec(gen, inst, TGSI_CHAN_Y); - int tmp_vec = ppc_allocate_vec_register(gen->f); - ppc_vrfim(gen->f, tmp_vec, src_vec); /* tmp = floor(src); */ - ppc_vsubfp(gen->f, dst_vec, src_vec, tmp_vec); /* dst = src - tmp */ - emit_store(gen, dst_vec, inst, TGSI_CHAN_Y, TRUE); - ppc_release_vec_register(gen->f, tmp_vec); - } - - /* Compute Z = RoughApprox2ToX(src) */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - int dst_vec = get_dst_vec(gen, inst, TGSI_CHAN_Z); - ppc_vexptefp(gen->f, dst_vec, src_vec); /* dst = 2 ^ src */ - emit_store(gen, dst_vec, inst, TGSI_CHAN_Z, TRUE); - } - - /* Compute W = 1.0 */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_W)) { - emit_store(gen, one_vec, inst, TGSI_CHAN_W, FALSE); - } - - release_src_vecs(gen); -} - - -static void -emit_log(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - const int bit31_vec = gen_get_bit31_vec(gen); - const int one_vec = gen_one_vec(gen); - int src_vec, abs_vec; - - /* get src arg */ - src_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_X); - - /* compute abs(src) */ - abs_vec = ppc_allocate_vec_register(gen->f); - ppc_vandc(gen->f, abs_vec, src_vec, bit31_vec); /* abs = src & ~bit31 */ - - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X) && - TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y)) { - - /* compute tmp = floor(log2(abs)) */ - int tmp_vec = ppc_allocate_vec_register(gen->f); - ppc_vlogefp(gen->f, tmp_vec, abs_vec); /* tmp = log2(abs) */ - ppc_vrfim(gen->f, tmp_vec, tmp_vec); /* tmp = floor(tmp); */ - - /* Compute X = tmp */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X)) { - emit_store(gen, tmp_vec, inst, TGSI_CHAN_X, FALSE); - } - - /* Compute Y = abs / 2^tmp */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y)) { - const int zero_vec = ppc_allocate_vec_register(gen->f); - ppc_vzero(gen->f, zero_vec); - ppc_vexptefp(gen->f, tmp_vec, tmp_vec); /* tmp = 2 ^ tmp */ - ppc_vrefp(gen->f, tmp_vec, tmp_vec); /* tmp = 1 / tmp */ - /* tmp = abs * tmp + zero */ - ppc_vmaddfp(gen->f, tmp_vec, abs_vec, tmp_vec, zero_vec); - emit_store(gen, tmp_vec, inst, TGSI_CHAN_Y, FALSE); - ppc_release_vec_register(gen->f, zero_vec); - } - - ppc_release_vec_register(gen->f, tmp_vec); - } - - /* Compute Z = RoughApproxLog2(abs) */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - int dst_vec = get_dst_vec(gen, inst, TGSI_CHAN_Z); - ppc_vlogefp(gen->f, dst_vec, abs_vec); /* dst = log2(abs) */ - emit_store(gen, dst_vec, inst, TGSI_CHAN_Z, TRUE); - } - - /* Compute W = 1.0 */ - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_W)) { - emit_store(gen, one_vec, inst, TGSI_CHAN_W, FALSE); - } - - ppc_release_vec_register(gen->f, abs_vec); - release_src_vecs(gen); -} - - -static void -emit_pow(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int s0_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_X); - int s1_vec = get_src_vec(gen, inst, 1, TGSI_CHAN_X); - int pow_vec = ppc_allocate_vec_register(gen->f); - int chan; - - ppc_vec_pow(gen->f, pow_vec, s0_vec, s1_vec); - - TGSI_FOR_EACH_DST0_ENABLED_CHANNEL(inst, chan) { - emit_store(gen, pow_vec, inst, chan, FALSE); - } - - ppc_release_vec_register(gen->f, pow_vec); - - release_src_vecs(gen); -} - - -static void -emit_xpd(struct gen_context *gen, struct tgsi_full_instruction *inst) -{ - int x0_vec, y0_vec, z0_vec; - int x1_vec, y1_vec, z1_vec; - int zero_vec, tmp_vec; - int tmp2_vec; - - zero_vec = ppc_allocate_vec_register(gen->f); - ppc_vzero(gen->f, zero_vec); - - tmp_vec = ppc_allocate_vec_register(gen->f); - tmp2_vec = ppc_allocate_vec_register(gen->f); - - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y) || - TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - x0_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_X); - x1_vec = get_src_vec(gen, inst, 1, TGSI_CHAN_X); - } - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X) || - TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z)) { - y0_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_Y); - y1_vec = get_src_vec(gen, inst, 1, TGSI_CHAN_Y); - } - if (TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X) || - TGSI_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y)) { - z0_vec = get_src_vec(gen, inst, 0, TGSI_CHAN_Z); - z1_vec = get_src_vec(gen, inst, 1, TGSI_CHAN_Z); - } - - TGSI_IF_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_X) { - /* tmp = y0 * z1 */ - ppc_vmaddfp(gen->f, tmp_vec, y0_vec, z1_vec, zero_vec); - /* tmp = tmp - z0 * y1*/ - ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, z0_vec, y1_vec); - emit_store(gen, tmp_vec, inst, TGSI_CHAN_X, FALSE); - } - TGSI_IF_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Y) { - /* tmp = z0 * x1 */ - ppc_vmaddfp(gen->f, tmp_vec, z0_vec, x1_vec, zero_vec); - /* tmp = tmp - x0 * z1 */ - ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, x0_vec, z1_vec); - emit_store(gen, tmp_vec, inst, TGSI_CHAN_Y, FALSE); - } - TGSI_IF_IS_DST0_CHANNEL_ENABLED(inst, TGSI_CHAN_Z) { - /* tmp = x0 * y1 */ - ppc_vmaddfp(gen->f, tmp_vec, x0_vec, y1_vec, zero_vec); - /* tmp = tmp - y0 * x1 */ - ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, y0_vec, x1_vec); - emit_store(gen, tmp_vec, inst, TGSI_CHAN_Z, FALSE); - } - /* W is undefined */ - - ppc_release_vec_register(gen->f, tmp_vec); - ppc_release_vec_register(gen->f, zero_vec); - release_src_vecs(gen); -} - -static int -emit_instruction(struct gen_context *gen, - struct tgsi_full_instruction *inst) -{ - - /* we don't handle saturation/clamping yet */ - if (inst->Instruction.Saturate != TGSI_SAT_NONE) - return 0; - - /* need to use extra temps to fix SOA dependencies : */ - if (tgsi_check_soa_dependencies(inst)) - return FALSE; - - switch (inst->Instruction.Opcode) { - case TGSI_OPCODE_MOV: - case TGSI_OPCODE_ABS: - case TGSI_OPCODE_FLR: - case TGSI_OPCODE_FRC: - case TGSI_OPCODE_EX2: - case TGSI_OPCODE_LG2: - emit_unaryop(gen, inst); - break; - case TGSI_OPCODE_RSQ: - case TGSI_OPCODE_RCP: - emit_scalar_unaryop(gen, inst); - break; - case TGSI_OPCODE_ADD: - case TGSI_OPCODE_SUB: - case TGSI_OPCODE_MUL: - case TGSI_OPCODE_MIN: - case TGSI_OPCODE_MAX: - emit_binop(gen, inst); - break; - case TGSI_OPCODE_SEQ: - case TGSI_OPCODE_SNE: - case TGSI_OPCODE_SLT: - case TGSI_OPCODE_SGT: - case TGSI_OPCODE_SLE: - case TGSI_OPCODE_SGE: - emit_inequality(gen, inst); - break; - case TGSI_OPCODE_MAD: - case TGSI_OPCODE_LRP: - emit_triop(gen, inst); - break; - case TGSI_OPCODE_DP3: - case TGSI_OPCODE_DP4: - case TGSI_OPCODE_DPH: - emit_dotprod(gen, inst); - break; - case TGSI_OPCODE_LIT: - emit_lit(gen, inst); - break; - case TGSI_OPCODE_LOG: - emit_log(gen, inst); - break; - case TGSI_OPCODE_EXP: - emit_exp(gen, inst); - break; - case TGSI_OPCODE_POW: - emit_pow(gen, inst); - break; - case TGSI_OPCODE_XPD: - emit_xpd(gen, inst); - break; - case TGSI_OPCODE_END: - /* normal end */ - return 1; - default: - return 0; - } - return 1; -} - - -static void -emit_declaration( - struct ppc_function *func, - struct tgsi_full_declaration *decl ) -{ - if( decl->Declaration.File == TGSI_FILE_INPUT || - decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE ) { -#if 0 - unsigned first, last, mask; - unsigned i, j; - - first = decl->Range.First; - last = decl->Range.Last; - mask = decl->Declaration.UsageMask; - - for( i = first; i <= last; i++ ) { - for( j = 0; j < NUM_CHANNELS; j++ ) { - if( mask & (1 << j) ) { - switch( decl->Interp.Interpolate ) { - case TGSI_INTERPOLATE_CONSTANT: - emit_coef_a0( func, 0, i, j ); - emit_inputs( func, 0, i, j ); - break; - - case TGSI_INTERPOLATE_LINEAR: - emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); - emit_coef_dadx( func, 1, i, j ); - emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); - emit_coef_dady( func, 3, i, j ); - emit_mul( func, 0, 1 ); /* x * dadx */ - emit_coef_a0( func, 4, i, j ); - emit_mul( func, 2, 3 ); /* y * dady */ - emit_add( func, 0, 4 ); /* x * dadx + a0 */ - emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ - emit_inputs( func, 0, i, j ); - break; - - case TGSI_INTERPOLATE_PERSPECTIVE: - emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); - emit_coef_dadx( func, 1, i, j ); - emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); - emit_coef_dady( func, 3, i, j ); - emit_mul( func, 0, 1 ); /* x * dadx */ - emit_tempf( func, 4, 0, TGSI_SWIZZLE_W ); - emit_coef_a0( func, 5, i, j ); - emit_rcp( func, 4, 4 ); /* 1.0 / w */ - emit_mul( func, 2, 3 ); /* y * dady */ - emit_add( func, 0, 5 ); /* x * dadx + a0 */ - emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ - emit_mul( func, 0, 4 ); /* (x * dadx + y * dady + a0) / w */ - emit_inputs( func, 0, i, j ); - break; - - default: - assert( 0 ); - break; - } - } - } - } -#endif - } -} - - - -static void -emit_prologue(struct ppc_function *func) -{ - /* XXX set up stack frame */ -} - - -static void -emit_epilogue(struct ppc_function *func) -{ - ppc_comment(func, -4, "Epilogue:"); - ppc_return(func); - /* XXX restore prev stack frame */ -#if 0 - debug_printf("PPC: Emitted %u instructions\n", func->num_inst); -#endif -} - - - -/** - * Translate a TGSI vertex/fragment shader to PPC code. - * - * \param tokens the TGSI input shader - * \param func the output PPC code/function - * \param immediates buffer to place immediates, later passed to PPC func - * \return TRUE for success, FALSE if translation failed - */ -boolean -tgsi_emit_ppc(const struct tgsi_token *tokens, - struct ppc_function *func, - float (*immediates)[4], - boolean do_swizzles ) -{ - static int use_ppc_asm = -1; - struct tgsi_parse_context parse; - /*boolean instruction_phase = FALSE;*/ - unsigned ok = 1; - uint num_immediates = 0; - struct gen_context gen; - uint ic = 0; - - if (use_ppc_asm < 0) { - /* If GALLIUM_NOPPC is set, don't use PPC codegen */ - use_ppc_asm = !debug_get_bool_option("GALLIUM_NOPPC", FALSE); - } - if (!use_ppc_asm) - return FALSE; - - if (0) { - debug_printf("\n********* TGSI->PPC ********\n"); - tgsi_dump(tokens, 0); - } - - util_init_math(); - - init_gen_context(&gen, func); - - emit_prologue(func); - - tgsi_parse_init( &parse, tokens ); - - while (!tgsi_parse_end_of_tokens(&parse) && ok) { - tgsi_parse_token(&parse); - - switch (parse.FullToken.Token.Type) { - case TGSI_TOKEN_TYPE_DECLARATION: - if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { - emit_declaration(func, &parse.FullToken.FullDeclaration ); - } - break; - - case TGSI_TOKEN_TYPE_INSTRUCTION: - if (func->print) { - _debug_printf("# "); - ic++; - tgsi_dump_instruction(&parse.FullToken.FullInstruction, ic); - } - - ok = emit_instruction(&gen, &parse.FullToken.FullInstruction); - - if (!ok) { - uint opcode = parse.FullToken.FullInstruction.Instruction.Opcode; - debug_printf("failed to translate tgsi opcode %d (%s) to PPC (%s)\n", - opcode, - tgsi_get_opcode_name(opcode), - parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX ? - "vertex shader" : "fragment shader"); - } - break; - - case TGSI_TOKEN_TYPE_IMMEDIATE: - /* splat each immediate component into a float[4] vector for SoA */ - { - const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; - uint i; - assert(size <= 4); - assert(num_immediates < TGSI_EXEC_NUM_IMMEDIATES); - for (i = 0; i < size; i++) { - immediates[num_immediates][i] = - parse.FullToken.FullImmediate.u[i].Float; - } - num_immediates++; - } - break; - - case TGSI_TOKEN_TYPE_PROPERTY: - break; - - default: - ok = 0; - assert( 0 ); - } - } - - emit_epilogue(func); - - tgsi_parse_free( &parse ); - - if (ppc_num_instructions(func) == 0) { - /* ran out of memory for instructions */ - ok = FALSE; - } - - if (!ok) - debug_printf("TGSI->PPC translation failed\n"); - - return ok; -} - -#else - -void ppc_dummy_func(void); - -void ppc_dummy_func(void) -{ -} - -#endif /* PIPE_ARCH_PPC */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_ppc.h b/src/gallium/auxiliary/tgsi/tgsi_ppc.h deleted file mode 100644 index 829ec075e7f..00000000000 --- a/src/gallium/auxiliary/tgsi/tgsi_ppc.h +++ /dev/null @@ -1,51 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef TGSI_PPC_H -#define TGSI_PPC_H - -#if defined __cplusplus -extern "C" { -#endif - -struct tgsi_token; -struct ppc_function; - -extern const float ppc_builtin_constants[]; - - -boolean -tgsi_emit_ppc(const struct tgsi_token *tokens, - struct ppc_function *function, - float (*immediates)[4], - boolean do_swizzles); - -#if defined __cplusplus -} -#endif - -#endif /* TGSI_PPC_H */ -- 2.30.2