Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.21.0) Implement ARM64Trg1Src2ZeroInstruction #62

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions compiler/aarch64/codegen/ARM64BinaryEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,10 @@ uint8_t *TR::ARM64Trg1ZeroSrc1Instruction::generateBinaryEncoding()
{
uint8_t *instructionStart = cg()->getBinaryBufferCursor();
uint8_t *cursor = instructionStart;
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);
cursor = getOpCode().copyBinaryToBuffer(instructionStart);
insertTargetRegister(toARM64Cursor(cursor));
insertSource1Register(toARM64Cursor(cursor));
zeroReg->setRegisterFieldRN(toARM64Cursor(cursor));
insertZeroRegister(toARM64Cursor(cursor));
cursor += ARM64_INSTRUCTION_LENGTH;
setBinaryLength(ARM64_INSTRUCTION_LENGTH);
setBinaryEncoding(instructionStart);
Expand All @@ -490,10 +489,8 @@ uint8_t *TR::ARM64ZeroSrc1ImmInstruction::generateBinaryEncoding()
{
uint8_t *instructionStart = cg()->getBinaryBufferCursor();
uint8_t *cursor = instructionStart;
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);

cursor = getOpCode().copyBinaryToBuffer(instructionStart);
zeroReg->setRegisterFieldRD(toARM64Cursor(cursor));
insertZeroRegister(toARM64Cursor(cursor));
insertSource1Register(toARM64Cursor(cursor));
insertImmediateField(toARM64Cursor(cursor));
insertNbit(toARM64Cursor(cursor));
Expand Down Expand Up @@ -562,6 +559,21 @@ uint8_t *TR::ARM64Trg1Src2ExtendedInstruction::generateBinaryEncoding()
return cursor;
}

uint8_t *TR::ARM64Trg1Src2ZeroInstruction::generateBinaryEncoding()
{
uint8_t *instructionStart = cg()->getBinaryBufferCursor();
uint8_t *cursor = instructionStart;
cursor = getOpCode().copyBinaryToBuffer(instructionStart);
insertTargetRegister(toARM64Cursor(cursor));
insertSource1Register(toARM64Cursor(cursor));
insertSource2Register(toARM64Cursor(cursor));
insertZeroRegister(toARM64Cursor(cursor));
cursor += ARM64_INSTRUCTION_LENGTH;
setBinaryLength(ARM64_INSTRUCTION_LENGTH);
setBinaryEncoding(instructionStart);
return cursor;
}

uint8_t *TR::ARM64Trg1Src3Instruction::generateBinaryEncoding()
{
uint8_t *instructionStart = cg()->getBinaryBufferCursor();
Expand Down Expand Up @@ -702,10 +714,8 @@ uint8_t *TR::ARM64ZeroSrc2Instruction::generateBinaryEncoding()
{
uint8_t *instructionStart = cg()->getBinaryBufferCursor();
uint8_t *cursor = instructionStart;
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);

cursor = getOpCode().copyBinaryToBuffer(instructionStart);
zeroReg->setRegisterFieldRD(toARM64Cursor(cursor));
insertZeroRegister(toARM64Cursor(cursor));
insertSource1Register(toARM64Cursor(cursor));
insertSource2Register(toARM64Cursor(cursor));
cursor += ARM64_INSTRUCTION_LENGTH;
Expand Down
42 changes: 25 additions & 17 deletions compiler/aarch64/codegen/ARM64Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ TR_Debug::print(TR::FILE *pOutFile, TR::Instruction *instr)
case OMR::Instruction::IsTrg1Src2Extended:
print(pOutFile, (TR::ARM64Trg1Src2ExtendedInstruction *)instr);
break;
case OMR::Instruction::IsTrg1Src2Zero:
print(pOutFile, (TR::ARM64Trg1Src2ZeroInstruction *)instr);
break;
case OMR::Instruction::IsTrg1Src3:
print(pOutFile, (TR::ARM64Trg1Src3Instruction *)instr);
break;
Expand Down Expand Up @@ -1200,23 +1203,8 @@ TR_Debug::print(TR::FILE *pOutFile, TR::ARM64Trg1Src2Instruction *instr)
{
printPrefix(pOutFile, instr);
TR::InstOpCode::Mnemonic op = instr->getOpCodeValue();
bool isCmp = false;
if (op == TR::InstOpCode::subsx || op == TR::InstOpCode::subsw)
{
TR::Register *r = instr->getTargetRegister();
if (r && r->getRealRegister()
&& toRealRegister(r)->getRegisterNumber() == TR::RealRegister::xzr)
{
// cmp alias
isCmp = true;
trfprintf(pOutFile, "cmp%c \t", (op == TR::InstOpCode::subsx) ? 'x' : 'w');
}
}
if (!isCmp)
{
trfprintf(pOutFile, "%s \t", getOpCodeName(&instr->getOpCode()));
print(pOutFile, instr->getTargetRegister(), TR_WordReg); trfprintf(pOutFile, ", ");
}
trfprintf(pOutFile, "%s \t", getOpCodeName(&instr->getOpCode()));
print(pOutFile, instr->getTargetRegister(), TR_WordReg); trfprintf(pOutFile, ", ");
print(pOutFile, instr->getSource1Register(), TR_WordReg); trfprintf(pOutFile, ", ");
print(pOutFile, instr->getSource2Register(), TR_WordReg);

Expand Down Expand Up @@ -1299,6 +1287,26 @@ TR_Debug::print(TR::FILE *pOutFile, TR::ARM64Trg1Src2ExtendedInstruction *instr)
trfflush(_comp->getOutFile());
}

void
TR_Debug::print(TR::FILE *pOutFile, TR::ARM64Trg1Src2ZeroInstruction *instr)
{
printPrefix(pOutFile, instr);
TR::InstOpCode::Mnemonic op = instr->getOpCodeValue();
if (op == TR::InstOpCode::maddx || op == TR::InstOpCode::maddw)
{
// mul alias
trfprintf(pOutFile, "mul%c \t", (op == TR::InstOpCode::maddx) ? 'x' : 'w');
}
else
{
trfprintf(pOutFile, "%s \t", getOpCodeName(&instr->getOpCode()));
}
print(pOutFile, instr->getTargetRegister(), TR_WordReg); trfprintf(pOutFile, ", ");
print(pOutFile, instr->getSource1Register(), TR_WordReg); trfprintf(pOutFile, ", ");
print(pOutFile, instr->getSource2Register(), TR_WordReg);
trfflush(_comp->getOutFile());
}

void
TR_Debug::print(TR::FILE *pOutFile, TR::ARM64Trg1Src3Instruction *instr)
{
Expand Down
105 changes: 102 additions & 3 deletions compiler/aarch64/codegen/ARM64Instruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ class ARM64Trg1Src1Instruction : public ARM64Trg1Instruction

/*
* This class is designated to be used for alias instruction such as movw, movx, negw, negx
*/
*/
class ARM64Trg1ZeroSrc1Instruction : public ARM64Trg1Src1Instruction
{
public:
Expand Down Expand Up @@ -1629,6 +1629,16 @@ class ARM64Trg1ZeroSrc1Instruction : public ARM64Trg1Src1Instruction
source1->setRegisterFieldRM(instruction);
}

/**
* @brief Sets zero register in binary encoding
* @param[in] instruction : instruction cursor
*/
void insertZeroRegister(uint32_t *instruction)
{
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);
zeroReg->setRegisterFieldRN(instruction);
}

/**
* @brief Generates binary encoding of the instruction
* @return instruction cursor
Expand Down Expand Up @@ -2305,6 +2315,75 @@ class ARM64Trg1Src2ExtendedInstruction : public ARM64Trg1Src2Instruction
virtual uint8_t *generateBinaryEncoding();
};

/*
* This class is designated to be used for alias instruction such as mulw, mulx
*/
class ARM64Trg1Src2ZeroInstruction : public ARM64Trg1Src2Instruction
{
public:

/*
* @brief Constructor
* @param[in] op : instruction opcode
* @param[in] node : node
* @param[in] treg : target register
* @param[in] s1reg : source register 1
* @param[in] s2reg : source register 2
* @param[in] cg : CodeGenerator
*/
ARM64Trg1Src2ZeroInstruction( TR::InstOpCode::Mnemonic op,
TR::Node *node,
TR::Register *treg,
TR::Register *s1reg,
TR::Register *s2reg,
TR::CodeGenerator *cg)
: ARM64Trg1Src2Instruction(op, node, treg, s1reg, s2reg, cg)
{
}

/*
* @brief Constructor
* @param[in] op : instruction opcode
* @param[in] node : node
* @param[in] treg : target register
* @param[in] s1reg : source register 1
* @param[in] s2reg : source register 2
* @param[in] precedingInstruction : preceding instruction
* @param[in] cg : CodeGenerator
*/
ARM64Trg1Src2ZeroInstruction( TR::InstOpCode::Mnemonic op,
TR::Node *node,
TR::Register *treg,
TR::Register *s1reg,
TR::Register *s2reg,
TR::Instruction *precedingInstruction, TR::CodeGenerator *cg)
: ARM64Trg1Src2Instruction(op, node, treg, s1reg, s2reg, precedingInstruction, cg)
{
}

/**
* @brief Gets instruction kind
* @return instruction kind
*/
virtual Kind getKind() { return IsTrg1Src2Zero; }

/**
* @brief Sets zero register in binary encoding
* @param[in] instruction : instruction cursor
*/
void insertZeroRegister(uint32_t *instruction)
{
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);
zeroReg->setRegisterFieldRA(instruction);
}

/**
* @brief Generates binary encoding of the instruction
* @return instruction cursor
*/
virtual uint8_t *generateBinaryEncoding();
};

class ARM64Trg1Src3Instruction : public ARM64Trg1Src2Instruction
{
TR::Register *_source3Register;
Expand Down Expand Up @@ -3171,7 +3250,7 @@ class ARM64Src1Instruction : public TR::Instruction

/*
* This class is designated to be used for alias instruction such as cmpimmw, cmpimmx, tstimmw, tstimmx
*/
*/
class ARM64ZeroSrc1ImmInstruction : public ARM64Src1Instruction
{
uint32_t _source1Immediate;
Expand Down Expand Up @@ -3268,9 +3347,19 @@ class ARM64ZeroSrc1ImmInstruction : public ARM64Src1Instruction
* @brief Sets the N bit (bit 22)
* @param[in] n : N bit value
* @return N bit value
*/
*/
bool setNbit(bool n) { return (_Nbit = n);}

/**
* @brief Sets zero register in binary encoding
* @param[in] instruction : instruction cursor
*/
void insertZeroRegister(uint32_t *instruction)
{
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);
zeroReg->setRegisterFieldRD(instruction);
}

/**
* @brief Sets immediate field in binary encoding
* @param[in] instruction : instruction cursor
Expand Down Expand Up @@ -3462,6 +3551,16 @@ class ARM64ZeroSrc2Instruction : public ARM64Src2Instruction
*/
virtual Kind getKind() { return IsZeroSrc2; }

/**
* @brief Sets zero register in binary encoding
* @param[in] instruction : instruction cursor
*/
void insertZeroRegister(uint32_t *instruction)
{
TR::RealRegister *zeroReg = cg()->machine()->getRealRegister(TR::RealRegister::xzr);
zeroReg->setRegisterFieldRD(instruction);
}

/**
* @brief Generates binary encoding of the instruction
* @return instruction cursor
Expand Down
16 changes: 3 additions & 13 deletions compiler/aarch64/codegen/GenerateInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,9 @@ TR::Instruction *generateMulInstruction(TR::CodeGenerator *cg, TR::Node *node,
bool is64bit = node->getDataType().isInt64();
TR::InstOpCode::Mnemonic op = is64bit ? TR::InstOpCode::maddx : TR::InstOpCode::maddw;

/* Use xzr as the third source register */
TR::Register *zeroReg = cg->allocateRegister();
TR::RegisterDependencyConditions *cond = new (cg->trHeapMemory()) TR::RegisterDependencyConditions(1, 1, cg->trMemory());
TR::addDependency(cond, zeroReg, TR::RealRegister::xzr, TR_GPR, cg);

TR::Instruction *instr =
(preced) ?
new (cg->trHeapMemory()) TR::ARM64Trg1Src3Instruction(op, node, treg, s1reg, s2reg, zeroReg, cond, preced, cg) :
new (cg->trHeapMemory()) TR::ARM64Trg1Src3Instruction(op, node, treg, s1reg, s2reg, zeroReg, cond, cg);

cg->stopUsingRegister(zeroReg);

return instr;
if (preced)
return new (cg->trHeapMemory()) TR::ARM64Trg1Src2ZeroInstruction(op, node, treg, s1reg, s2reg, preced, cg);
return new (cg->trHeapMemory()) TR::ARM64Trg1Src2ZeroInstruction(op, node, treg, s1reg, s2reg, cg);
}

TR::Instruction *generateCSetInstruction(TR::CodeGenerator *cg, TR::Node *node,
Expand Down
1 change: 1 addition & 0 deletions compiler/aarch64/codegen/OMRInstructionKindEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
IsCondTrg1Src2,
IsTrg1Src2Shifted,
IsTrg1Src2Extended,
IsTrg1Src2Zero,
IsTrg1Src3,
IsTrg1Mem,
IsTrg1MemSrc1,
Expand Down
2 changes: 2 additions & 0 deletions compiler/ras/Debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ namespace TR { class ARM64Trg1Src2Instruction; }
namespace TR { class ARM64CondTrg1Src2Instruction; }
namespace TR { class ARM64Trg1Src2ShiftedInstruction; }
namespace TR { class ARM64Trg1Src2ExtendedInstruction; }
namespace TR { class ARM64Trg1Src2ZeroInstruction; }
namespace TR { class ARM64Trg1Src3Instruction; }
namespace TR { class ARM64Trg1MemInstruction; }
namespace TR { class ARM64MemInstruction; }
Expand Down Expand Up @@ -1125,6 +1126,7 @@ class TR_Debug
void print(TR::FILE *, TR::ARM64CondTrg1Src2Instruction *);
void print(TR::FILE *, TR::ARM64Trg1Src2ShiftedInstruction *);
void print(TR::FILE *, TR::ARM64Trg1Src2ExtendedInstruction *);
void print(TR::FILE *, TR::ARM64Trg1Src2ZeroInstruction *);
void print(TR::FILE *, TR::ARM64Trg1Src3Instruction *);
void print(TR::FILE *, TR::ARM64Trg1MemInstruction *);
void print(TR::FILE *, TR::ARM64MemInstruction *);
Expand Down