Implement XOR (without offsets)
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
6d8b3f0e09
commit
c4a98361b1
|
@ -111,6 +111,35 @@ namespace Instruction {
|
|||
return std::move(i);
|
||||
});
|
||||
|
||||
//XOR P1, P2 = A, P3 = B
|
||||
addOperator("XOR", 3, [](const parseOperatorResult &op, const std::vector<Token> &tokens) -> std::unique_ptr<Instruction> {
|
||||
if(op.offset1 != 0){
|
||||
throw std::runtime_error("XOR cannot use addressing offsets");
|
||||
}
|
||||
auto c = std::make_unique<Container>("XOR op = a + b - (a & b) - (a & b)");
|
||||
|
||||
/*
|
||||
* Non-offset version
|
||||
* AND S1, A, B
|
||||
* ADD S0, A, B
|
||||
* SUB S0, S0, S1
|
||||
* SUB P1, S0, S1
|
||||
*/
|
||||
|
||||
if(tokens.at(2).getType() == Token::Type::Immediate){
|
||||
c->addInstruction(std::make_unique<CalcImm>(Calc::Operation::AND, 0, (uint32_t) MgmtRegisters::std_SCRATCH_1, tokens.at(1).getNumericValue(), tokens.at(2).getNumericValue()), "XOR, s1 = a & b");
|
||||
c->addInstruction(std::make_unique<CalcImm>(Calc::Operation::ADD, 0, (uint32_t) MgmtRegisters::std_SCRATCH_0, tokens.at(1).getNumericValue(), tokens.at(2).getNumericValue()), "XOR, s0 = a + b");
|
||||
}else{
|
||||
c->addInstruction(std::make_unique<Calc>(Calc::Operation::AND, 0, (uint32_t) MgmtRegisters::std_SCRATCH_1, tokens.at(1).getNumericValue(), tokens.at(2).getNumericValue()), "XOR, s1 = a & b");
|
||||
c->addInstruction(std::make_unique<Calc>(Calc::Operation::ADD, 0, (uint32_t) MgmtRegisters::std_SCRATCH_0, tokens.at(1).getNumericValue(), tokens.at(2).getNumericValue()), "XOR, s0 = a + b");
|
||||
}
|
||||
|
||||
c->addInstruction(std::make_unique<Calc>(Calc::Operation::SUB, 0, (uint32_t) MgmtRegisters::std_SCRATCH_0, (uint32_t) MgmtRegisters::std_SCRATCH_0, (uint32_t) MgmtRegisters::std_SCRATCH_1), "XOR, s0 = s0 - s1");
|
||||
c->addInstruction(std::make_unique<Calc>(Calc::Operation::SUB, 0, tokens.at(0).getNumericValue(), (uint32_t) MgmtRegisters::std_SCRATCH_0, (uint32_t) MgmtRegisters::std_SCRATCH_1), "XOR, result = s0 - s1");
|
||||
|
||||
return std::move(c);
|
||||
});
|
||||
|
||||
addOperator("AND", 3, CalcImm::fromAndTokens);
|
||||
|
||||
addOperator("OR", 3, CalcImm::fromOrTokens);
|
||||
|
|
Loading…
Reference in a new issue