From e5e8127a5d04844b4675ed66a182b9935f9000ce Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 26 Mar 2016 14:02:02 +0100 Subject: [PATCH] Correct MAD instruction encoding --- Manual.md | 2 +- source/picasso_assembler.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Manual.md b/Manual.md index 1c555dd..328e9b4 100644 --- a/Manual.md +++ b/Manual.md @@ -286,7 +286,7 @@ Syntax | Description - In instructions that take one source operand, it is always wide. - In instructions that take two source operands, the first is wide and the second is narrow. - `dph`/`sge`/`slt` have a special form where the first operand is narrow and the second is wide. This usage is detected automatically by `picasso`. - - `mad`, which takes three source operands, has two forms: the first is wide-wide-narrow, and the second is wide-narrow-wide. This is also detected automatically. Additionally, relative addressing is not supported. + - `mad`, which takes three source operands, has two forms: the first is narrow-wide-narrow, and the second is narrow-narrow-wide. This is also detected automatically. Additionally, relative addressing applies to the first source operand (which is narrow) instead of the single wide operand. - `idxReg`: Represents an indexing register to write to using the mova instruction. Can be `a0`, `a1` or `a01` (the latter writes to both `a0` and `a1`). - `iReg`: Represents an integer vector uniform source operand. - `bReg`: Represents a boolean uniform source operand. diff --git a/source/picasso_assembler.cpp b/source/picasso_assembler.cpp index 1c4c766..2461ff2 100644 --- a/source/picasso_assembler.cpp +++ b/source/picasso_assembler.cpp @@ -481,6 +481,10 @@ static inline int ensure_valid_condop(int condop, const char* name) ARG_TO_REG(_reg, _name); \ safe_call(ensure_valid_src_narrow(_reg, _name, 2)) +#define ARG_TO_SRC2_REG2(_reg, _name) \ + ARG_TO_REG2(_reg, _name); \ + safe_call(ensure_valid_src_narrow(_reg, _name, 1)) + #define ARG_TO_IREG(_reg, _name) \ ARG_TO_REG(_reg, _name); \ safe_call(ensure_valid_ireg(_reg, _name)) @@ -835,7 +839,7 @@ DEF_COMMAND(format5) ENSURE_NO_MORE_ARGS(); ARG_TO_DEST_REG(rDest, destName); - ARG_TO_SRC1_REG(rSrc1, src1Name); + ARG_TO_SRC2_REG2(rSrc1, src1Name); ARG_TO_REG(rSrc2, src2Name); ARG_TO_REG(rSrc3, src3Name); @@ -861,9 +865,9 @@ DEF_COMMAND(format5) printf("%s:%02X d%02X, d%02X, d%02X, d%02X (0x%X)\n", cmdName, opcode, rDest, rSrc1, rSrc2, rSrc3, opdesc); #endif if (!inverted) - BUF.push_back(FMT_OPCODE(opcode) | opdesc | (rSrc3<<5) | (rSrc2<<10) | (rSrc1<<17) | (rDest<<24)); + BUF.push_back(FMT_OPCODE(opcode) | opdesc | (rSrc3<<5) | (rSrc2<<10) | (rSrc1<<17) | (rSrc1Idx<<22) | (rDest<<24)); else - BUF.push_back(FMT_OPCODE(opcodei) | opdesc | (rSrc3<<5) | (rSrc2<<12) | (rSrc1<<17) | (rDest<<24)); + BUF.push_back(FMT_OPCODE(opcodei) | opdesc | (rSrc3<<5) | (rSrc2<<12) | (rSrc1<<17) | (rSrc1Idx<<22) | (rDest<<24)); return 0; }