1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2005 Ben Skeggs. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 7bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 16bf215546Sopenharmony_ci * portions of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22bf215546Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23bf215546Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24bf215546Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "r300_fragprog.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include <stdio.h> 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "r300_reg.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistatic void presub_string(char out[10], unsigned int inst) 35bf215546Sopenharmony_ci{ 36bf215546Sopenharmony_ci switch(inst & 0x600000){ 37bf215546Sopenharmony_ci case R300_ALU_SRCP_1_MINUS_2_SRC0: 38bf215546Sopenharmony_ci sprintf(out, "bias"); 39bf215546Sopenharmony_ci break; 40bf215546Sopenharmony_ci case R300_ALU_SRCP_SRC1_MINUS_SRC0: 41bf215546Sopenharmony_ci sprintf(out, "sub"); 42bf215546Sopenharmony_ci break; 43bf215546Sopenharmony_ci case R300_ALU_SRCP_SRC1_PLUS_SRC0: 44bf215546Sopenharmony_ci sprintf(out, "add"); 45bf215546Sopenharmony_ci break; 46bf215546Sopenharmony_ci case R300_ALU_SRCP_1_MINUS_SRC0: 47bf215546Sopenharmony_ci sprintf(out, "inv "); 48bf215546Sopenharmony_ci break; 49bf215546Sopenharmony_ci } 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cistatic int get_msb(unsigned int bit, unsigned int r400_ext_addr) 53bf215546Sopenharmony_ci{ 54bf215546Sopenharmony_ci return (r400_ext_addr & bit) ? 1 << 5 : 0; 55bf215546Sopenharmony_ci} 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci/* just some random things... */ 58bf215546Sopenharmony_civoid r300FragmentProgramDump(struct radeon_compiler *c, void *user) 59bf215546Sopenharmony_ci{ 60bf215546Sopenharmony_ci struct r300_fragment_program_compiler *compiler = (struct r300_fragment_program_compiler*)c; 61bf215546Sopenharmony_ci struct r300_fragment_program_code *code = &compiler->code->code.r300; 62bf215546Sopenharmony_ci int n, i, j; 63bf215546Sopenharmony_ci static int pc = 0; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci fprintf(stderr, "pc=%d*************************************\n", pc++); 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci fprintf(stderr, "Hardware program\n"); 68bf215546Sopenharmony_ci fprintf(stderr, "----------------\n"); 69bf215546Sopenharmony_ci if (c->is_r400) { 70bf215546Sopenharmony_ci fprintf(stderr, "code_offset_ext: %08x\n", code->r400_code_offset_ext); 71bf215546Sopenharmony_ci } 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci for (n = 0; n <= (code->config & 3); n++) { 74bf215546Sopenharmony_ci uint32_t code_addr = code->code_addr[3 - (code->config & 3) + n]; 75bf215546Sopenharmony_ci unsigned int alu_offset = ((code_addr & R300_ALU_START_MASK) >> R300_ALU_START_SHIFT) + 76bf215546Sopenharmony_ci (((code->r400_code_offset_ext >> (24 - (n * 6))) & 0x7) << 6); 77bf215546Sopenharmony_ci unsigned int alu_end = ((code_addr & R300_ALU_SIZE_MASK) >> R300_ALU_SIZE_SHIFT) + 78bf215546Sopenharmony_ci (((code->r400_code_offset_ext >> (27 - (n * 6))) & 0x7) << 6); 79bf215546Sopenharmony_ci int tex_offset = (code_addr & R300_TEX_START_MASK) >> R300_TEX_START_SHIFT; 80bf215546Sopenharmony_ci int tex_end = (code_addr & R300_TEX_SIZE_MASK) >> R300_TEX_SIZE_SHIFT; 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci fprintf(stderr, "NODE %d: alu_offset: %u, tex_offset: %d, " 83bf215546Sopenharmony_ci "alu_end: %u, tex_end: %d (code_addr: %08x)\n", n, 84bf215546Sopenharmony_ci alu_offset, tex_offset, alu_end, tex_end, code_addr); 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci if (n > 0 || (code->config & R300_PFS_CNTL_FIRST_NODE_HAS_TEX)) { 87bf215546Sopenharmony_ci fprintf(stderr, " TEX:\n"); 88bf215546Sopenharmony_ci for (i = tex_offset; 89bf215546Sopenharmony_ci i <= tex_offset + tex_end; 90bf215546Sopenharmony_ci ++i) { 91bf215546Sopenharmony_ci const char *instr; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci switch ((code->tex. 94bf215546Sopenharmony_ci inst[i] >> R300_TEX_INST_SHIFT) & 95bf215546Sopenharmony_ci 15) { 96bf215546Sopenharmony_ci case R300_TEX_OP_LD: 97bf215546Sopenharmony_ci instr = "TEX"; 98bf215546Sopenharmony_ci break; 99bf215546Sopenharmony_ci case R300_TEX_OP_KIL: 100bf215546Sopenharmony_ci instr = "KIL"; 101bf215546Sopenharmony_ci break; 102bf215546Sopenharmony_ci case R300_TEX_OP_TXP: 103bf215546Sopenharmony_ci instr = "TXP"; 104bf215546Sopenharmony_ci break; 105bf215546Sopenharmony_ci case R300_TEX_OP_TXB: 106bf215546Sopenharmony_ci instr = "TXB"; 107bf215546Sopenharmony_ci break; 108bf215546Sopenharmony_ci default: 109bf215546Sopenharmony_ci instr = "UNKNOWN"; 110bf215546Sopenharmony_ci } 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci fprintf(stderr, 113bf215546Sopenharmony_ci " %s t%i, %c%i, texture[%i] (%08x)\n", 114bf215546Sopenharmony_ci instr, 115bf215546Sopenharmony_ci (code->tex. 116bf215546Sopenharmony_ci inst[i] >> R300_DST_ADDR_SHIFT) & 31, 117bf215546Sopenharmony_ci 't', 118bf215546Sopenharmony_ci (code->tex. 119bf215546Sopenharmony_ci inst[i] >> R300_SRC_ADDR_SHIFT) & 31, 120bf215546Sopenharmony_ci (code->tex. 121bf215546Sopenharmony_ci inst[i] & R300_TEX_ID_MASK) >> 122bf215546Sopenharmony_ci R300_TEX_ID_SHIFT, 123bf215546Sopenharmony_ci code->tex.inst[i]); 124bf215546Sopenharmony_ci } 125bf215546Sopenharmony_ci } 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci for (i = alu_offset; 128bf215546Sopenharmony_ci i <= alu_offset + alu_end; ++i) { 129bf215546Sopenharmony_ci char srcc[4][10], dstc[20]; 130bf215546Sopenharmony_ci char srca[4][10], dsta[20]; 131bf215546Sopenharmony_ci char argc[3][20]; 132bf215546Sopenharmony_ci char arga[3][20]; 133bf215546Sopenharmony_ci char flags[5], tmp[10]; 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci for (j = 0; j < 3; ++j) { 136bf215546Sopenharmony_ci int regc = code->alu.inst[i].rgb_addr >> (j * 6); 137bf215546Sopenharmony_ci int rega = code->alu.inst[i].alpha_addr >> (j * 6); 138bf215546Sopenharmony_ci int msbc = get_msb(R400_ADDR_EXT_RGB_MSB_BIT(j), 139bf215546Sopenharmony_ci code->alu.inst[i].r400_ext_addr); 140bf215546Sopenharmony_ci int msba = get_msb(R400_ADDR_EXT_A_MSB_BIT(j), 141bf215546Sopenharmony_ci code->alu.inst[i].r400_ext_addr); 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci sprintf(srcc[j], "%c%i", 144bf215546Sopenharmony_ci (regc & 32) ? 'c' : 't', (regc & 31) | msbc); 145bf215546Sopenharmony_ci sprintf(srca[j], "%c%i", 146bf215546Sopenharmony_ci (rega & 32) ? 'c' : 't', (rega & 31) | msba); 147bf215546Sopenharmony_ci } 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci dstc[0] = 0; 150bf215546Sopenharmony_ci sprintf(flags, "%s%s%s", 151bf215546Sopenharmony_ci (code->alu.inst[i]. 152bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_REG_X) ? "x" : "", 153bf215546Sopenharmony_ci (code->alu.inst[i]. 154bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_REG_Y) ? "y" : "", 155bf215546Sopenharmony_ci (code->alu.inst[i]. 156bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_REG_Z) ? "z" : ""); 157bf215546Sopenharmony_ci if (flags[0] != 0) { 158bf215546Sopenharmony_ci unsigned int msb = get_msb( 159bf215546Sopenharmony_ci R400_ADDRD_EXT_RGB_MSB_BIT, 160bf215546Sopenharmony_ci code->alu.inst[i].r400_ext_addr); 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci sprintf(dstc, "t%i.%s ", 163bf215546Sopenharmony_ci ((code->alu.inst[i]. 164bf215546Sopenharmony_ci rgb_addr >> R300_ALU_DSTC_SHIFT) 165bf215546Sopenharmony_ci & 31) | msb, 166bf215546Sopenharmony_ci flags); 167bf215546Sopenharmony_ci } 168bf215546Sopenharmony_ci sprintf(flags, "%s%s%s", 169bf215546Sopenharmony_ci (code->alu.inst[i]. 170bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_OUTPUT_X) ? "x" : "", 171bf215546Sopenharmony_ci (code->alu.inst[i]. 172bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_OUTPUT_Y) ? "y" : "", 173bf215546Sopenharmony_ci (code->alu.inst[i]. 174bf215546Sopenharmony_ci rgb_addr & R300_ALU_DSTC_OUTPUT_Z) ? "z" : ""); 175bf215546Sopenharmony_ci if (flags[0] != 0) { 176bf215546Sopenharmony_ci sprintf(tmp, "o%i.%s", 177bf215546Sopenharmony_ci (code->alu.inst[i]. 178bf215546Sopenharmony_ci rgb_addr >> 29) & 3, 179bf215546Sopenharmony_ci flags); 180bf215546Sopenharmony_ci strcat(dstc, tmp); 181bf215546Sopenharmony_ci } 182bf215546Sopenharmony_ci /* Presub */ 183bf215546Sopenharmony_ci presub_string(srcc[3], code->alu.inst[i].rgb_inst); 184bf215546Sopenharmony_ci presub_string(srca[3], code->alu.inst[i].alpha_inst); 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci dsta[0] = 0; 187bf215546Sopenharmony_ci if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_REG) { 188bf215546Sopenharmony_ci unsigned int msb = get_msb( 189bf215546Sopenharmony_ci R400_ADDRD_EXT_A_MSB_BIT, 190bf215546Sopenharmony_ci code->alu.inst[i].r400_ext_addr); 191bf215546Sopenharmony_ci sprintf(dsta, "t%i.w ", 192bf215546Sopenharmony_ci ((code->alu.inst[i]. 193bf215546Sopenharmony_ci alpha_addr >> R300_ALU_DSTA_SHIFT) & 31) 194bf215546Sopenharmony_ci | msb); 195bf215546Sopenharmony_ci } 196bf215546Sopenharmony_ci if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_OUTPUT) { 197bf215546Sopenharmony_ci sprintf(tmp, "o%i.w ", 198bf215546Sopenharmony_ci (code->alu.inst[i]. 199bf215546Sopenharmony_ci alpha_addr >> 25) & 3); 200bf215546Sopenharmony_ci strcat(dsta, tmp); 201bf215546Sopenharmony_ci } 202bf215546Sopenharmony_ci if (code->alu.inst[i].alpha_addr & R300_ALU_DSTA_DEPTH) { 203bf215546Sopenharmony_ci strcat(dsta, "Z"); 204bf215546Sopenharmony_ci } 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci fprintf(stderr, 207bf215546Sopenharmony_ci "%3i: xyz: %3s %3s %3s %5s-> %-20s (%08x)\n" 208bf215546Sopenharmony_ci " w: %3s %3s %3s %5s-> %-20s (%08x)\n", i, 209bf215546Sopenharmony_ci srcc[0], srcc[1], srcc[2], srcc[3], dstc, 210bf215546Sopenharmony_ci code->alu.inst[i].rgb_addr, srca[0], srca[1], 211bf215546Sopenharmony_ci srca[2], srca[3], dsta, 212bf215546Sopenharmony_ci code->alu.inst[i].alpha_addr); 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci for (j = 0; j < 3; ++j) { 215bf215546Sopenharmony_ci int regc = code->alu.inst[i].rgb_inst >> (j * 7); 216bf215546Sopenharmony_ci int rega = code->alu.inst[i].alpha_inst >> (j * 7); 217bf215546Sopenharmony_ci int d; 218bf215546Sopenharmony_ci char buf[20]; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci d = regc & 31; 221bf215546Sopenharmony_ci if (d < 12) { 222bf215546Sopenharmony_ci switch (d % 4) { 223bf215546Sopenharmony_ci case R300_ALU_ARGC_SRC0C_XYZ: 224bf215546Sopenharmony_ci sprintf(buf, "%s.xyz", 225bf215546Sopenharmony_ci srcc[d / 4]); 226bf215546Sopenharmony_ci break; 227bf215546Sopenharmony_ci case R300_ALU_ARGC_SRC0C_XXX: 228bf215546Sopenharmony_ci sprintf(buf, "%s.xxx", 229bf215546Sopenharmony_ci srcc[d / 4]); 230bf215546Sopenharmony_ci break; 231bf215546Sopenharmony_ci case R300_ALU_ARGC_SRC0C_YYY: 232bf215546Sopenharmony_ci sprintf(buf, "%s.yyy", 233bf215546Sopenharmony_ci srcc[d / 4]); 234bf215546Sopenharmony_ci break; 235bf215546Sopenharmony_ci case R300_ALU_ARGC_SRC0C_ZZZ: 236bf215546Sopenharmony_ci sprintf(buf, "%s.zzz", 237bf215546Sopenharmony_ci srcc[d / 4]); 238bf215546Sopenharmony_ci break; 239bf215546Sopenharmony_ci } 240bf215546Sopenharmony_ci } else if (d < 15) { 241bf215546Sopenharmony_ci sprintf(buf, "%s.www", srca[d - 12]); 242bf215546Sopenharmony_ci } else if (d < 20 ) { 243bf215546Sopenharmony_ci switch(d) { 244bf215546Sopenharmony_ci case R300_ALU_ARGC_SRCP_XYZ: 245bf215546Sopenharmony_ci sprintf(buf, "srcp.xyz"); 246bf215546Sopenharmony_ci break; 247bf215546Sopenharmony_ci case R300_ALU_ARGC_SRCP_XXX: 248bf215546Sopenharmony_ci sprintf(buf, "srcp.xxx"); 249bf215546Sopenharmony_ci break; 250bf215546Sopenharmony_ci case R300_ALU_ARGC_SRCP_YYY: 251bf215546Sopenharmony_ci sprintf(buf, "srcp.yyy"); 252bf215546Sopenharmony_ci break; 253bf215546Sopenharmony_ci case R300_ALU_ARGC_SRCP_ZZZ: 254bf215546Sopenharmony_ci sprintf(buf, "srcp.zzz"); 255bf215546Sopenharmony_ci break; 256bf215546Sopenharmony_ci case R300_ALU_ARGC_SRCP_WWW: 257bf215546Sopenharmony_ci sprintf(buf, "srcp.www"); 258bf215546Sopenharmony_ci break; 259bf215546Sopenharmony_ci } 260bf215546Sopenharmony_ci } else if (d == 20) { 261bf215546Sopenharmony_ci sprintf(buf, "0.0"); 262bf215546Sopenharmony_ci } else if (d == 21) { 263bf215546Sopenharmony_ci sprintf(buf, "1.0"); 264bf215546Sopenharmony_ci } else if (d == 22) { 265bf215546Sopenharmony_ci sprintf(buf, "0.5"); 266bf215546Sopenharmony_ci } else if (d >= 23 && d < 32) { 267bf215546Sopenharmony_ci d -= 23; 268bf215546Sopenharmony_ci switch (d / 3) { 269bf215546Sopenharmony_ci case 0: 270bf215546Sopenharmony_ci sprintf(buf, "%s.yzx", 271bf215546Sopenharmony_ci srcc[d % 3]); 272bf215546Sopenharmony_ci break; 273bf215546Sopenharmony_ci case 1: 274bf215546Sopenharmony_ci sprintf(buf, "%s.zxy", 275bf215546Sopenharmony_ci srcc[d % 3]); 276bf215546Sopenharmony_ci break; 277bf215546Sopenharmony_ci case 2: 278bf215546Sopenharmony_ci sprintf(buf, "%s.Wzy", 279bf215546Sopenharmony_ci srcc[d % 3]); 280bf215546Sopenharmony_ci break; 281bf215546Sopenharmony_ci } 282bf215546Sopenharmony_ci } else { 283bf215546Sopenharmony_ci sprintf(buf, "%i", d); 284bf215546Sopenharmony_ci } 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci sprintf(argc[j], "%s%s%s%s", 287bf215546Sopenharmony_ci (regc & 32) ? "-" : "", 288bf215546Sopenharmony_ci (regc & 64) ? "|" : "", 289bf215546Sopenharmony_ci buf, (regc & 64) ? "|" : ""); 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci d = rega & 31; 292bf215546Sopenharmony_ci if (d < 9) { 293bf215546Sopenharmony_ci sprintf(buf, "%s.%c", srcc[d / 3], 294bf215546Sopenharmony_ci 'x' + (char)(d % 3)); 295bf215546Sopenharmony_ci } else if (d < 12) { 296bf215546Sopenharmony_ci sprintf(buf, "%s.w", srca[d - 9]); 297bf215546Sopenharmony_ci } else if (d < 16) { 298bf215546Sopenharmony_ci switch(d) { 299bf215546Sopenharmony_ci case R300_ALU_ARGA_SRCP_X: 300bf215546Sopenharmony_ci sprintf(buf, "srcp.x"); 301bf215546Sopenharmony_ci break; 302bf215546Sopenharmony_ci case R300_ALU_ARGA_SRCP_Y: 303bf215546Sopenharmony_ci sprintf(buf, "srcp.y"); 304bf215546Sopenharmony_ci break; 305bf215546Sopenharmony_ci case R300_ALU_ARGA_SRCP_Z: 306bf215546Sopenharmony_ci sprintf(buf, "srcp.z"); 307bf215546Sopenharmony_ci break; 308bf215546Sopenharmony_ci case R300_ALU_ARGA_SRCP_W: 309bf215546Sopenharmony_ci sprintf(buf, "srcp.w"); 310bf215546Sopenharmony_ci break; 311bf215546Sopenharmony_ci } 312bf215546Sopenharmony_ci } else if (d == 16) { 313bf215546Sopenharmony_ci sprintf(buf, "0.0"); 314bf215546Sopenharmony_ci } else if (d == 17) { 315bf215546Sopenharmony_ci sprintf(buf, "1.0"); 316bf215546Sopenharmony_ci } else if (d == 18) { 317bf215546Sopenharmony_ci sprintf(buf, "0.5"); 318bf215546Sopenharmony_ci } else { 319bf215546Sopenharmony_ci sprintf(buf, "%i", d); 320bf215546Sopenharmony_ci } 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci sprintf(arga[j], "%s%s%s%s", 323bf215546Sopenharmony_ci (rega & 32) ? "-" : "", 324bf215546Sopenharmony_ci (rega & 64) ? "|" : "", 325bf215546Sopenharmony_ci buf, (rega & 64) ? "|" : ""); 326bf215546Sopenharmony_ci } 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci fprintf(stderr, " xyz: %8s %8s %8s op: %08x %s\n" 329bf215546Sopenharmony_ci " w: %8s %8s %8s op: %08x\n", 330bf215546Sopenharmony_ci argc[0], argc[1], argc[2], 331bf215546Sopenharmony_ci code->alu.inst[i].rgb_inst, 332bf215546Sopenharmony_ci code->alu.inst[i].rgb_inst & R300_ALU_INSERT_NOP ? 333bf215546Sopenharmony_ci "NOP" : "", 334bf215546Sopenharmony_ci arga[0], arga[1],arga[2], 335bf215546Sopenharmony_ci code->alu.inst[i].alpha_inst); 336bf215546Sopenharmony_ci } 337bf215546Sopenharmony_ci } 338bf215546Sopenharmony_ci} 339