Skip to content

Commit

Permalink
- add addtional "methods"
Browse files Browse the repository at this point in the history
- fix parsing
  • Loading branch information
Mike Wiedenbauer committed Nov 5, 2020
1 parent f70eab2 commit 817dfa5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions tools/cgcomp/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>

#ifdef WIN32
#include <memory.h>
Expand Down
22 changes: 20 additions & 2 deletions tools/cgcomp/source/compilerfp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void CCompilerFP::Compile(CParser *pParser)
case OPCODE_FRC:
emit_insn(insn,NVFX_FP_OP_OPCODE_FRC);
break;
case OPCODE_KIL_NV:
case OPCODE_KIL:
emit_insn(insn,NVFX_FP_OP_OPCODE_KIL);
break;
case OPCODE_LG2:
Expand Down Expand Up @@ -213,9 +213,18 @@ void CCompilerFP::Compile(CParser *pParser)
case OPCODE_NRM3:
emit_insn(insn,NVFX_FP_OP_OPCODE_NRM);
break;
case OPCODE_PK4B:
emit_insn(insn,NVFX_FP_OP_OPCODE_PK4B);
break;
case OPCODE_PK4UB:
emit_insn(insn,NVFX_FP_OP_OPCODE_PK4UB);
break;
case OPCODE_PK2H:
emit_insn(insn,NVFX_FP_OP_OPCODE_PK2H);
break;
case OPCODE_PK2US:
emit_insn(insn,NVFX_FP_OP_OPCODE_PK2US);
break;
case OPCODE_POW:
emit_pow(insn);
break;
Expand Down Expand Up @@ -261,9 +270,18 @@ void CCompilerFP::Compile(CParser *pParser)
case OPCODE_TXP:
emit_tex(insn,NVFX_FP_OP_OPCODE_TXP);
break;
case OPCODE_UP4B:
emit_insn(insn,NVFX_FP_OP_OPCODE_UP4B);
break;
case OPCODE_UP4UB:
emit_insn(insn,NVFX_FP_OP_OPCODE_UP4UB);
break;
case OPCODE_UP2H:
emit_insn(insn,NVFX_FP_OP_OPCODE_UP2H);
break;
case OPCODE_UP2US:
emit_insn(insn,NVFX_FP_OP_OPCODE_UP2US);
break;
case OPCODE_BGNLOOP:
emit_loop(insn);
break;
Expand Down Expand Up @@ -441,7 +459,7 @@ void CCompilerFP::emit_src(struct nvfx_insn *insn,s32 pos,bool *have_const)
sr |= NVFX_FP_REG_NEGATE;

if(src->abs)
hw[1] |= src_abs_flag(pos);
sr |= src_abs_flag(pos);

sr |= ((src->swz[0] << NVFX_FP_REG_SWZ_X_SHIFT) |
(src->swz[1] << NVFX_FP_REG_SWZ_Y_SHIFT) |
Expand Down
8 changes: 6 additions & 2 deletions tools/cgcomp/source/fpparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct _opcode
{ "FLR", OPCODE_FLR, INPUT_1V, OUTPUT_V, _R | _H | _X | _C | _S },
{ "FRC", OPCODE_FRC, INPUT_1V, OUTPUT_V, _R | _H | _X | _C | _S },
{ "IF", OPCODE_IF, INPUT_CC, OUTPUT_NONE, 0 },
{ "KIL", OPCODE_KIL_NV, INPUT_CC, OUTPUT_NONE, 0 },
{ "KIL", OPCODE_KIL, INPUT_CC, OUTPUT_NONE, 0 },
{ "LG2", OPCODE_LG2, INPUT_1S, OUTPUT_S, _R | _H | _C | _S },
{ "LIT", OPCODE_LIT, INPUT_1V, OUTPUT_V, _R | _H | _C | _S },
{ "LOOP", OPCODE_BGNLOOP, INPUT_1V, OUTPUT_NONE, 0 },
Expand Down Expand Up @@ -259,7 +259,6 @@ void CFPParser::ParseInstruction(struct nvfx_insn *insn,opcode *opc,const char *
insn->precision = opc->suffixes&(_R|_H|_X);
insn->sat = ((opc->suffixes&_S) ? TRUE : FALSE);
insn->cc_update = ((opc->suffixes&_C) ? TRUE : FALSE);
insn->disable_pc = IsPCDisablingInstruction(insn);

if(opc->outputs==OUTPUT_S || opc->outputs==OUTPUT_V) {
ParseMaskedDstReg(token,insn);
Expand Down Expand Up @@ -316,8 +315,13 @@ void CFPParser::ParseInstruction(struct nvfx_insn *insn,opcode *opc,const char *
token = SkipSpaces(strtok(NULL,","));
ParseTextureTarget(token,&insn->tex_target);
} else if(opc->inputs==INPUT_CC) {
if (*token == '(') token++;
ParseCond(token,insn);
}

// finally check for insns disabling perspective correction interpolation
// only at this point we know everyhting about the insn to decide.
insn->disable_pc = IsPCDisablingInstruction(insn);
}

opcode CFPParser::FindOpcode(const char *mnemonic)
Expand Down
11 changes: 6 additions & 5 deletions tools/cgcomp/source/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const char* CParser::ParseCond(const char *token,struct nvfx_insn *insn)
{
token = ConvertCond(token,insn);
if(token[0]=='.') {
s32 k = 0;
u32 k = 0;

token++;

Expand All @@ -257,10 +257,11 @@ const char* CParser::ParseCond(const char *token,struct nvfx_insn *insn)
insn->cc_swz[k] = NVFX_SWZ_W;
}
if(k && k<4) {
u8 lastswz = insn->cc_swz[k - 1];
while(k<4) {
insn->cc_swz[k] = lastswz;
k++;
u32 cnt = k;
u8 lastswz = insn->cc_swz[cnt - 1];
while(cnt<4) {
insn->cc_swz[cnt] = lastswz;
cnt++;
}
}
token += k;
Expand Down

0 comments on commit 817dfa5

Please sign in to comment.