From bf6d6aba3383de6b4d96b99db72dea2a3a73830b Mon Sep 17 00:00:00 2001 From: "rajshekar.k" Date: Sun, 8 Aug 2021 01:32:20 +0530 Subject: [PATCH] bug fixes related to implementation of FMA and LEA instructions --- .../translator/x86/instruction/FMA.java | 20 ++++++++++++++----- src/simulator/generic/Instruction.java | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/simulator/emulatorinterface/translator/x86/instruction/FMA.java b/src/simulator/emulatorinterface/translator/x86/instruction/FMA.java index 6b6c46a..ac137ce 100644 --- a/src/simulator/emulatorinterface/translator/x86/instruction/FMA.java +++ b/src/simulator/emulatorinterface/translator/x86/instruction/FMA.java @@ -25,6 +25,7 @@ package emulatorinterface.translator.x86.instruction; import emulatorinterface.translator.InvalidInstructionException; import emulatorinterface.translator.x86.operand.OperandTranslator; +import emulatorinterface.translator.x86.registers.Registers; import emulatorinterface.translator.x86.registers.TempRegisterNum; import generic.Instruction; import generic.Operand; @@ -66,10 +67,15 @@ public class FMA implements X86StaticInstructionHandler (operand1.isFloatRegisterOperand()) && (operand2 == null || operand2.isImmediateOperand() || operand2.isFloatRegisterOperand() || operand2.isMemoryOperand()) && (operand3 == null || operand3.isImmediateOperand() || operand3.isFloatRegisterOperand() || operand3.isMemoryOperand())) - { - Operand srcOpnd1, srcOpnd2, destOpnd; + { + /* + * FMA type instructions have 3 source operands + * VISA supports only 2 source operands + * introducing an intALU and an intermediate result to get the approximate effect + */ + Operand srcOpnd1, srcOpnd2, srcOpnd3, destOpnd; - srcOpnd1 = operand2; + srcOpnd1 = operand1; if(operand3.isMemoryOperand()) { @@ -79,10 +85,14 @@ public class FMA implements X86StaticInstructionHandler { srcOpnd2 = operand3; } + Operand intermediateResult = Registers.getTempIntReg(tempRegisterNum); + instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(srcOpnd1, srcOpnd2, intermediateResult)); + + srcOpnd3 = operand2; destOpnd = operand1; - instructionArrayList.appendInstruction(Instruction.getFMA(srcOpnd1, srcOpnd2, destOpnd)); + instructionArrayList.appendInstruction(Instruction.getFMA(intermediateResult, srcOpnd3, destOpnd)); } else @@ -90,4 +100,4 @@ public class FMA implements X86StaticInstructionHandler misc.Error.invalidOperation("Scalar FMA ", operand1, operand2, operand3); } } -} \ No newline at end of file +} diff --git a/src/simulator/generic/Instruction.java b/src/simulator/generic/Instruction.java index 06cee3b..aa08f98 100755 --- a/src/simulator/generic/Instruction.java +++ b/src/simulator/generic/Instruction.java @@ -358,7 +358,7 @@ public class Instruction implements Serializable Operand sourceOperand2, Operand destinationOperand) { Instruction ins = CustomObjectPool.getInstructionPool().borrowObject(); - ins.set(OperationType.LEA, sourceOperand1, null, + ins.set(OperationType.LEA, sourceOperand1, sourceOperand2, destinationOperand); return ins; } @@ -566,4 +566,4 @@ public class Instruction implements Serializable destinationOperandMemValue = createAddressForBM(destinationOperandMemValue, bm); branchTargetAddress = createAddressForBM(branchTargetAddress, bm); } -} \ No newline at end of file +}