From 0271c14805271f9e2c12a2c8de39391216117b97 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 3 Mar 2021 23:44:02 -0800 Subject: [PATCH] arch-x86: Factor out duplication in the new RegOp base classes. Instead of having the cross product of dest/src1/src2 and folded int, debug, control, misc, and segment operands, break them up so they can be mixed together in different combinations using "using" declarations. Change-Id: I04357b08bd8a6cd91c2e4df64a2c6cb760bfe90e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42344 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/arch/x86/insts/microregop.hh | 276 ++++++++++--------------------- 1 file changed, 90 insertions(+), 186 deletions(-) diff --git a/src/arch/x86/insts/microregop.hh b/src/arch/x86/insts/microregop.hh index e7bd0538c9..37e9d6f7b3 100644 --- a/src/arch/x86/insts/microregop.hh +++ b/src/arch/x86/insts/microregop.hh @@ -43,217 +43,121 @@ namespace X86ISA { -struct RegOpDest +struct DestOp { using ArgType = InstRegIndex; + const RegIndex dest; + const size_t size; + RegIndex index() const { return dest; } - RegIndex dest; - size_t size; + DestOp(RegIndex _dest, size_t _size) : dest(_dest), size(_size) {} +}; +struct Src1Op +{ + using ArgType = InstRegIndex; + const RegIndex src1; + const size_t size; + RegIndex index() const { return src1; } + + Src1Op(RegIndex _src1, size_t _size) : src1(_src1), size(_size) {} +}; + +struct Src2Op +{ + using ArgType = InstRegIndex; + const RegIndex src2; + const size_t size; + RegIndex index() const { return src2; } + + Src2Op(RegIndex _src2, size_t _size) : src2(_src2), size(_size) {} +}; + +template +struct FoldedOp : public Base +{ template - RegOpDest(InstType *inst, ArgType idx) : - dest(INTREG_FOLDED(idx.index(), inst->foldOBit)), - size(inst->dataSize) + FoldedOp(InstType *inst, typename Base::ArgType idx) : + Base(INTREG_FOLDED(idx.index(), inst->foldOBit), inst->dataSize) {} void print(std::ostream &os) const { - X86StaticInst::printReg(os, RegId(IntRegClass, dest), size); + X86StaticInst::printReg(os, RegId(IntRegClass, this->index()), + this->size); } }; -struct RegOpDbgDest +template +struct CrOp : public Base { - using ArgType = InstRegIndex; - - RegIndex dest; - size_t size; - template - RegOpDbgDest(InstType *inst, ArgType idx) : dest(idx.index()), - size(inst->dataSize) + CrOp(InstType *inst, typename Base::ArgType idx) : Base(idx.index(), 0) {} + + void + print(std::ostream &os) const + { + ccprintf(os, "cr%d", this->index()); + } +}; + +template +struct DbgOp : public Base +{ + template + DbgOp(InstType *inst, typename Base::ArgType idx) : Base(idx.index(), 0) {} + + void + print(std::ostream &os) const + { + ccprintf(os, "dr%d", this->index()); + } + +}; + +template +struct SegOp : public Base +{ + template + SegOp(InstType *inst, typename Base::ArgType idx) : Base(idx.index(), 0) {} + + void + print(std::ostream &os) const + { + X86StaticInst::printSegment(os, this->index()); + } +}; + +template +struct MiscOp : public Base +{ + template + MiscOp(InstType *inst, typename Base::ArgType idx) : + Base(idx.index(), inst->dataSize) {} void print(std::ostream &os) const { - ccprintf(os, "dr%d", dest); + X86StaticInst::printReg(os, RegId(MiscRegClass, this->index()), + this->size); } }; -struct RegOpCrDest -{ - using ArgType = InstRegIndex; +using RegOpDest = FoldedOp; +using RegOpDbgDest = DbgOp; +using RegOpCrDest = CrOp; +using RegOpSegDest = SegOp; +using RegOpMiscDest = MiscOp; - RegIndex dest; - size_t size; +using RegOpSrc1 = FoldedOp; +using RegOpDbgSrc1 = DbgOp; +using RegOpCrSrc1 = CrOp; +using RegOpSegSrc1 = SegOp; +using RegOpMiscSrc1 = MiscOp; - template - RegOpCrDest(InstType *inst, ArgType idx) : dest(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - ccprintf(os, "cr%d", dest); - } -}; - -struct RegOpSegDest -{ - using ArgType = InstRegIndex; - - RegIndex dest; - size_t size; - - template - RegOpSegDest(InstType *inst, ArgType idx) : dest(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printSegment(os, dest); - } -}; - -struct RegOpMiscDest -{ - using ArgType = InstRegIndex; - - RegIndex dest; - size_t size; - - template - RegOpMiscDest(InstType *inst, ArgType idx) : dest(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printReg(os, RegId(MiscRegClass, dest), size); - } -}; - -struct RegOpSrc1 -{ - using ArgType = InstRegIndex; - - RegIndex src1; - size_t size; - - template - RegOpSrc1(InstType *inst, ArgType idx) : - src1(INTREG_FOLDED(idx.index(), inst->foldOBit)), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printReg(os, RegId(IntRegClass, src1), size); - } -}; - -struct RegOpDbgSrc1 -{ - using ArgType = InstRegIndex; - - RegIndex src1; - size_t size; - - template - RegOpDbgSrc1(InstType *inst, ArgType idx) : src1(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - ccprintf(os, "dr%d", src1); - } -}; - -struct RegOpCrSrc1 -{ - using ArgType = InstRegIndex; - - RegIndex src1; - size_t size; - - template - RegOpCrSrc1(InstType *inst, ArgType idx) : src1(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - ccprintf(os, "cr%d", src1); - } -}; - -struct RegOpSegSrc1 -{ - using ArgType = InstRegIndex; - - RegIndex src1; - size_t size; - - template - RegOpSegSrc1(InstType *inst, ArgType idx) : src1(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printSegment(os, src1); - } -}; - -struct RegOpMiscSrc1 -{ - using ArgType = InstRegIndex; - - RegIndex src1; - size_t size; - - template - RegOpMiscSrc1(InstType *inst, ArgType idx) : src1(idx.index()), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printReg(os, RegId(MiscRegClass, src1), size); - } -}; - -struct RegOpSrc2 -{ - using ArgType = InstRegIndex; - - RegIndex src2; - size_t size; - - template - RegOpSrc2(InstType *inst, ArgType idx) : - src2(INTREG_FOLDED(idx.index(), inst->foldOBit)), - size(inst->dataSize) - {} - - void - print(std::ostream &os) const - { - X86StaticInst::printReg(os, RegId(IntRegClass, src2), size); - } -}; +using RegOpSrc2 = FoldedOp; struct RegOpImm8 {