base.isa

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· ISA 代码 · 共 550 行 · 第 1/2 页

ISA
550
字号
//////////////////////////////////////////////////////////////////////// Base class for sparc instructions, and some support functions//output header {{        union CondCodes        {            struct            {                uint8_t c:1;                uint8_t v:1;                uint8_t z:1;                uint8_t n:1;            };            uint32_t bits;        };        enum CondTest        {            Always=0x8,            Never=0x0,            NotEqual=0x9,            Equal=0x1,            Greater=0xA,            LessOrEqual=0x2,            GreaterOrEqual=0xB,            Less=0x3,            GreaterUnsigned=0xC,            LessOrEqualUnsigned=0x4,            CarryClear=0xD,            CarrySet=0x5,            Positive=0xE,            Negative=0x6,            OverflowClear=0xF,            OverflowSet=0x7        };        enum FpCondTest        {            FAlways=0x8,            FNever=0x0,            FUnordered=0x7,            FGreater=0x6,            FUnorderedOrGreater=0x5,            FLess=0x4,            FUnorderedOrLess=0x3,            FLessOrGreater=0x2,            FNotEqual=0x1,            FEqual=0x9,            FUnorderedOrEqual=0xA,            FGreaterOrEqual=0xB,            FUnorderedOrGreaterOrEqual=0xC,            FLessOrEqual=0xD,            FUnorderedOrLessOrEqual=0xE,            FOrdered=0xF        };        extern const char *CondTestAbbrev[];        /**         * Base class for all SPARC static instructions.         */        class SparcStaticInst : public StaticInst        {          protected:            // Constructor.            SparcStaticInst(const char *mnem,                 ExtMachInst _machInst, OpClass __opClass)                    : StaticInst(mnem, _machInst, __opClass)                {                }            std::string generateDisassembly(Addr pc,                const SymbolTable *symtab) const;            void printReg(std::ostream &os, int reg) const;            void printSrcReg(std::ostream &os, int reg) const;            void printDestReg(std::ostream &os, int reg) const;            void printRegArray(std::ostream &os,                const RegIndex indexArray[], int num) const;        };        bool passesFpCondition(uint32_t fcc, uint32_t condition);        bool passesCondition(uint32_t codes, uint32_t condition);        inline int64_t sign_ext(uint64_t data, int origWidth)        {            int shiftAmount = 64 - origWidth;            return (((int64_t)data) << shiftAmount) >> shiftAmount;        }}};output decoder {{        const char *CondTestAbbrev[] =        {            "nev", //Never            "e", //Equal            "le", //Less or Equal            "l", //Less            "leu", //Less or Equal Unsigned            "c", //Carry set            "n", //Negative            "o", //Overflow set            "a", //Always            "ne", //Not Equal            "g", //Greater            "ge", //Greater or Equal            "gu", //Greater Unsigned            "cc", //Carry clear            "p", //Positive            "oc" //Overflow Clear        };}};def template ROrImmDecode {{    {        return (I ? (SparcStaticInst *)(new %(class_name)sImm(machInst))                  : (SparcStaticInst *)(new %(class_name)s(machInst)));    }}};output header {{    union DoubleSingle    {        double d;        uint64_t ui;        uint32_t s[2];        DoubleSingle(double _d) : d(_d)        {}        DoubleSingle(uint64_t _ui) : ui(_ui)        {}        DoubleSingle(uint32_t _s0, uint32_t _s1)        {            s[0] = _s0;            s[1] = _s1;        }    };}};let {{    def filterDoubles(code):        assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE)        for opName in ("Frd", "Frs1", "Frs2", "Frd_N"):            next_pos = 0            operandsREString = (r'''            (?<![\w\.])             # neg. lookbehind assertion: prevent partial matches            ((%s)(?:\.(\w+))?)   # match: operand with optional '.' then suffix            (?![\w\.])             # neg. lookahead assertion: prevent partial matches            ''' % opName)            operandsRE = re.compile(operandsREString, re.MULTILINE|re.VERBOSE)            is_src = False            is_dest = False            extension = None            foundOne = False            while 1:                match = operandsRE.search(code, next_pos)                if not match:                    break                foundOne = True                op = match.groups()                (op_full, op_base, op_ext) = op                is_dest_local = (assignRE.match(code, match.end()) != None)                is_dest = is_dest or is_dest_local                is_src = is_src or not is_dest_local                if extension and extension != op_ext:                    raise Exception, "Inconsistent extensions in double filter."                extension = op_ext                next_pos = match.end()            if foundOne:                # Get rid of any unwanted extension                code = operandsRE.sub(op_base, code)                is_int = False                member = "d"                if extension in ("sb", "ub", "shw", "uhw", "sw", "uw", "sdw", "udw"):                    is_int = True                    member = "ui"                if is_src:                    code = ("%s = DoubleSingle(%s_high, %s_low).%s;" % \                        (opName, opName, opName, member)) + code                if is_dest:                    code += '''                        %s_low = DoubleSingle(%s).s[1];                        %s_high = DoubleSingle(%s).s[0];''' % \                             (opName, opName, opName, opName)                if is_int:                    code = ("uint64_t %s;" % opName) + code                else:                    code = ("double %s;" % opName) + code        return code}};let {{    def splitOutImm(code):        matcher = re.compile(r'Rs(?P<rNum>\d)_or_imm(?P<iNum>\d+)(?P<typeQual>\.\w+)?')        rOrImmMatch = matcher.search(code)        if (rOrImmMatch == None):            return (False, code, '', '', '')        rString = rOrImmMatch.group("rNum")        if (rOrImmMatch.group("typeQual") != None):            rString += rOrImmMatch.group("typeQual")        iString = rOrImmMatch.group("iNum")        orig_code = code        code = matcher.sub('Rs' + rString, orig_code)        imm_code = matcher.sub('imm', orig_code)        return (True, code, imm_code, rString, iString)}};output decoder {{        inline void printMnemonic(std::ostream &os, const char * mnemonic)        {            ccprintf(os, "\t%s   ", mnemonic);        }        void SparcStaticInst::printRegArray(std::ostream &os,            const RegIndex indexArray[], int num) const        {            if(num <= 0)                return;            printReg(os, indexArray[0]);            for(int x = 1; x < num; x++)            {                os << ", ";                printReg(os, indexArray[x]);            }        }        void        SparcStaticInst::printSrcReg(std::ostream &os, int reg) const        {            if(_numSrcRegs > reg)                printReg(os, _srcRegIdx[reg]);        }        void        SparcStaticInst::printDestReg(std::ostream &os, int reg) const        {            if(_numDestRegs > reg)                printReg(os, _destRegIdx[reg]);        }        void        SparcStaticInst::printReg(std::ostream &os, int reg) const        {            const int MaxGlobal = 8;            const int MaxOutput = 16;            const int MaxLocal = 24;            const int MaxInput = 32;            const int MaxMicroReg = 40;            if (reg < FP_Base_DepTag) {                //If we used a register from the next or previous window,                //take out the offset.                while (reg >= MaxMicroReg)                    reg -= MaxMicroReg;                if (reg == FramePointerReg)                    ccprintf(os, "%%fp");                else if (reg == StackPointerReg)                    ccprintf(os, "%%sp");                else if(reg < MaxGlobal)                    ccprintf(os, "%%g%d", reg);                else if(reg < MaxOutput)                    ccprintf(os, "%%o%d", reg - MaxGlobal);                else if(reg < MaxLocal)                    ccprintf(os, "%%l%d", reg - MaxOutput);                else if(reg < MaxInput)                    ccprintf(os, "%%i%d", reg - MaxLocal);                else if(reg < MaxMicroReg)                    ccprintf(os, "%%u%d", reg - MaxInput);                //The fake int regs that are really control regs                else {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?