Skip to content

Commit

Permalink
fix: CRC instruction operands
Browse files Browse the repository at this point in the history
This fix the decoding the CRC instruction.
None of the operands were decoded.
The dependencies were therefore never queued and satisfied.

Co-authored-by: Bryan Perdrizat <[email protected]>
  • Loading branch information
xusine and branylagaffe committed Sep 27, 2024
1 parent 1d4aef7 commit 7cf84a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions components/Decoder/SemanticActions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ crcAction(SemanticInstruction* anInstruction,
eOperandCode anInputCode,
eOperandCode anInputCode2,
eOperandCode anOutputCode,
std::vector<std::list<InternalDependance>>& rs_deps,
bool is64);
predicated_action
countAction(SemanticInstruction* anInstruction,
Expand Down
27 changes: 12 additions & 15 deletions components/Decoder/SemanticActions/ReverseAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ struct CRCAction : public PredicatedSemanticAction
eOperandCode anInputCode2,
eOperandCode anOutputCode,
bool is64)
: PredicatedSemanticAction(anInstruction, 1, true)
: PredicatedSemanticAction(anInstruction, 2, true)
, theInputCode(anInputCode)
, theInputCode2(anInputCode2)
, theOutputCode(anOutputCode)
, thePoly(aPoly)
, the64(is64)
Expand All @@ -207,28 +208,19 @@ struct CRCAction : public PredicatedSemanticAction

Operand in = theInstruction->operand(theInputCode);
Operand in2 = theInstruction->operand(theInputCode2);
uint32_t acc = (uint32_t)(boost::get<bits>(in));
// bits val = boost::get<bits> (in2);
uint32_t acc = static_cast<uint32_t>(boost::get<uint64_t>(in));

bits tempacc = (bits)((bitReverse(acc)) << (the64 ? 64 : 32));
bits tempval = 0; //(bits)((bitReverse(val)) << 32) ;
bits tempacc = static_cast<bits>(bitReverse(acc) << (the64 ? 64 : 32));
bits tempval = 0;

// Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation;

tempacc ^= tempval;
bits data = tempacc;

// for (int i = data.size() -1; i >= 32; i--){
// if (data[i] == 1){
// data.resize(32 + (i-32));
// data ^= thePoly << (i-32);
// break;
// }
// }

data &= 0xffffffff;

theInstruction->setOperand(theOutputCode, data);
theInstruction->setOperand(theOutputCode, static_cast<uint64_t>(data));
satisfyDependants();
}

void describe(std::ostream& anOstream) const { anOstream << theInstruction->identify() << " CRCAction "; }
Expand Down Expand Up @@ -287,10 +279,15 @@ crcAction(SemanticInstruction* anInstruction,
eOperandCode anInputCode,
eOperandCode anInputCode2,
eOperandCode anOutputCode,
std::vector<std::list<InternalDependance>>& rs_deps,
bool is64)
{
CRCAction* act = new CRCAction(anInstruction, aPoly, anInputCode, anInputCode2, anOutputCode, is64);
anInstruction->addNewComponent(act);
for (uint32_t i = 0; i < rs_deps.size(); ++i) {
rs_deps[i].push_back(act->dependance(i));
}

return predicated_action(act, act->predicate());
}

Expand Down
2 changes: 1 addition & 1 deletion components/Decoder/encodings/DataProcReg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ CRC(archcode const& aFetchedOpcode, uint32_t aCPU, int64_t aSequenceNo)
std::vector<std::list<InternalDependance>> rs_deps(2);
uint32_t poly = crc32c ? 0x1EDC6F41 : 0x04C11DB7;

predicated_action act = crcAction(inst, poly, kOperand1, kOperand2, kResult, sf);
predicated_action act = crcAction(inst, poly, kOperand1, kOperand2, kResult, rs_deps, sf);

readRegister(inst, 1, rn, rs_deps[0], false);
readRegister(inst, 2, rm, rs_deps[1], sf);
Expand Down

0 comments on commit 7cf84a3

Please sign in to comment.