limmop.isa revision 9764
111901Sjason@lowepower.com// Copyright (c) 2007 The Hewlett-Packard Development Company
211901Sjason@lowepower.com// All rights reserved.
311901Sjason@lowepower.com//
411901Sjason@lowepower.com// The license below extends only to copyright in the software and shall
511901Sjason@lowepower.com// not be construed as granting a license to any other intellectual
611901Sjason@lowepower.com// property including but not limited to intellectual property relating
711901Sjason@lowepower.com// to a hardware implementation of the functionality of the software
811901Sjason@lowepower.com// licensed hereunder.  You may use the software subject to the license
911901Sjason@lowepower.com// terms below provided that you ensure that this notice is replicated
1011901Sjason@lowepower.com// unmodified and in its entirety in all distributions of the software,
1111901Sjason@lowepower.com// modified or unmodified, in source code or in binary form.
1211901Sjason@lowepower.com//
1311901Sjason@lowepower.com// Redistribution and use in source and binary forms, with or without
1411901Sjason@lowepower.com// modification, are permitted provided that the following conditions are
1511901Sjason@lowepower.com// met: redistributions of source code must retain the above copyright
1611901Sjason@lowepower.com// notice, this list of conditions and the following disclaimer;
1711901Sjason@lowepower.com// redistributions in binary form must reproduce the above copyright
1811901Sjason@lowepower.com// notice, this list of conditions and the following disclaimer in the
1911901Sjason@lowepower.com// documentation and/or other materials provided with the distribution;
2011901Sjason@lowepower.com// neither the name of the copyright holders nor the names of its
2111901Sjason@lowepower.com// contributors may be used to endorse or promote products derived from
2211901Sjason@lowepower.com// this software without specific prior written permission.
2311901Sjason@lowepower.com//
2411901Sjason@lowepower.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2511901Sjason@lowepower.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2611901Sjason@lowepower.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2711901Sjason@lowepower.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2811901Sjason@lowepower.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2911901Sjason@lowepower.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3011901Sjason@lowepower.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3111901Sjason@lowepower.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3211901Sjason@lowepower.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3311901Sjason@lowepower.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3411901Sjason@lowepower.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3511901Sjason@lowepower.com//
3611901Sjason@lowepower.com// Authors: Gabe Black
3711901Sjason@lowepower.com
3811901Sjason@lowepower.com//////////////////////////////////////////////////////////////////////////
3911901Sjason@lowepower.com//
4011901Sjason@lowepower.com// LIMMOp Microop templates
4111901Sjason@lowepower.com//
4211901Sjason@lowepower.com//////////////////////////////////////////////////////////////////////////
4311901Sjason@lowepower.com
4411901Sjason@lowepower.comdef template MicroLimmOpExecute {{
4511901Sjason@lowepower.com        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
4611901Sjason@lowepower.com                Trace::InstRecord *traceData) const
4711901Sjason@lowepower.com        {
4811901Sjason@lowepower.com            %(op_decl)s;
4911901Sjason@lowepower.com            %(op_rd)s;
5011901Sjason@lowepower.com            %(code)s;
5111901Sjason@lowepower.com            %(op_wb)s;
5211901Sjason@lowepower.com            return NoFault;
5311901Sjason@lowepower.com        }
5411901Sjason@lowepower.com}};
5511901Sjason@lowepower.com
5611901Sjason@lowepower.comdef template MicroLimmOpDeclare {{
5711901Sjason@lowepower.com    class %(class_name)s : public X86ISA::X86MicroopBase
5811901Sjason@lowepower.com    {
5911901Sjason@lowepower.com      protected:
6011901Sjason@lowepower.com        const RegIndex dest;
6111901Sjason@lowepower.com        const uint64_t imm;
6211901Sjason@lowepower.com        const uint8_t dataSize;
6311901Sjason@lowepower.com        RegIndex foldOBit;
6411901Sjason@lowepower.com
6511901Sjason@lowepower.com        std::string generateDisassembly(Addr pc,
6611901Sjason@lowepower.com            const SymbolTable *symtab) const;
6711901Sjason@lowepower.com
6811901Sjason@lowepower.com      public:
6911901Sjason@lowepower.com        %(class_name)s(ExtMachInst _machInst,
7011901Sjason@lowepower.com                const char * instMnem,
7111901Sjason@lowepower.com                uint64_t setFlags, InstRegIndex _dest,
7211901Sjason@lowepower.com                uint64_t _imm, uint8_t _dataSize);
7311901Sjason@lowepower.com
7411901Sjason@lowepower.com        %(BasicExecDeclare)s
7511901Sjason@lowepower.com    };
7611901Sjason@lowepower.com}};
7711901Sjason@lowepower.com
7811901Sjason@lowepower.comdef template MicroLimmOpDisassembly {{
7911901Sjason@lowepower.com    std::string %(class_name)s::generateDisassembly(Addr pc,
8011901Sjason@lowepower.com            const SymbolTable *symtab) const
8111901Sjason@lowepower.com    {
8212562Ssiddhesh.poyarekar@gmail.com        std::stringstream response;
8312562Ssiddhesh.poyarekar@gmail.com
8412562Ssiddhesh.poyarekar@gmail.com        printMnemonic(response, instMnem, mnemonic);
8511901Sjason@lowepower.com        printDestReg(response, 0, dataSize);
8611901Sjason@lowepower.com        response << ", ";
8711901Sjason@lowepower.com        ccprintf(response, "%#x", imm);
8811901Sjason@lowepower.com        return response.str();
8911901Sjason@lowepower.com    }
9011901Sjason@lowepower.com}};
9111901Sjason@lowepower.com
9211901Sjason@lowepower.comdef template MicroLimmOpConstructor {{
9311901Sjason@lowepower.com    inline %(class_name)s::%(class_name)s(
9411901Sjason@lowepower.com            ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
9511901Sjason@lowepower.com            InstRegIndex _dest, uint64_t _imm, uint8_t _dataSize) :
9611901Sjason@lowepower.com        %(base_class)s(machInst, "%(mnemonic)s", instMnem,
9711901Sjason@lowepower.com                setFlags, %(op_class)s),
9811901Sjason@lowepower.com                dest(_dest.idx), imm(_imm), dataSize(_dataSize)
9911901Sjason@lowepower.com    {
10011901Sjason@lowepower.com        foldOBit = (dataSize == 1 && !machInst.rex.present) ? 1 << 6 : 0;
10111901Sjason@lowepower.com        %(constructor)s;
10211901Sjason@lowepower.com    }
10311901Sjason@lowepower.com}};
10411901Sjason@lowepower.com
10511901Sjason@lowepower.comlet {{
10611901Sjason@lowepower.com    class LimmOp(X86Microop):
10711901Sjason@lowepower.com        def __init__(self, dest, imm, dataSize="env.dataSize"):
10811901Sjason@lowepower.com            self.className = "Limm"
10911901Sjason@lowepower.com            self.mnemonic = "limm"
11011901Sjason@lowepower.com            self.dest = dest
11111901Sjason@lowepower.com            if isinstance(imm, (int, long)):
11211901Sjason@lowepower.com                imm = "ULL(%d)" % imm
11311901Sjason@lowepower.com            self.imm = imm
11411901Sjason@lowepower.com            self.dataSize = dataSize
11511901Sjason@lowepower.com
11611901Sjason@lowepower.com        def getAllocator(self, microFlags):
11711901Sjason@lowepower.com            allocString = '''
11811977Sjason@lowepower.com                (%(dataSize)s >= 4) ?
11911977Sjason@lowepower.com                    (StaticInstPtr)(new %(class_name)sBig(machInst,
12011977Sjason@lowepower.com                        macrocodeBlock, %(flags)s, %(dest)s, %(imm)s,
12111977Sjason@lowepower.com                        %(dataSize)s)) :
12211901Sjason@lowepower.com                    (StaticInstPtr)(new %(class_name)s(machInst,
12311901Sjason@lowepower.com                        macrocodeBlock, %(flags)s, %(dest)s, %(imm)s,
12411901Sjason@lowepower.com                        %(dataSize)s))
12511901Sjason@lowepower.com            '''
12611901Sjason@lowepower.com            allocator = allocString % {
12711901Sjason@lowepower.com                "class_name" : self.className,
12811901Sjason@lowepower.com                "mnemonic" : self.mnemonic,
12911901Sjason@lowepower.com                "flags" : self.microFlagsText(microFlags),
13011901Sjason@lowepower.com                "dest" : self.dest, "imm" : self.imm,
13111901Sjason@lowepower.com                "dataSize" : self.dataSize}
13211901Sjason@lowepower.com            return allocator
13311901Sjason@lowepower.com
13411901Sjason@lowepower.com    microopClasses["limm"] = LimmOp
13511901Sjason@lowepower.com
13611901Sjason@lowepower.com    class LfpimmOp(X86Microop):
13711901Sjason@lowepower.com        def __init__(self, dest, imm, dataSize="env.dataSize"):
13811901Sjason@lowepower.com            self.className = "Lfpimm"
13911901Sjason@lowepower.com            self.mnemonic = "lfpimm"
14011901Sjason@lowepower.com            self.dest = dest
14111901Sjason@lowepower.com            if isinstance(imm, (int, long)):
14211901Sjason@lowepower.com                imm = "ULL(%d)" % imm
14311901Sjason@lowepower.com            elif isinstance(imm, float):
14411901Sjason@lowepower.com                imm = "getDoubleBits(%.16f)" % imm
14511901Sjason@lowepower.com            self.imm = imm
14611901Sjason@lowepower.com            self.dataSize = dataSize
14711901Sjason@lowepower.com
14811901Sjason@lowepower.com        def getAllocator(self, microFlags):
14911901Sjason@lowepower.com            allocator = '''new %(class_name)s(machInst, macrocodeBlock,
15011901Sjason@lowepower.com                    %(flags)s, %(dest)s, %(imm)s, %(dataSize)s)''' % {
15111901Sjason@lowepower.com                "class_name" : self.className,
15211901Sjason@lowepower.com                "mnemonic" : self.mnemonic,
15311901Sjason@lowepower.com                "flags" : self.microFlagsText(microFlags),
15411901Sjason@lowepower.com                "dest" : self.dest, "imm" : self.imm,
15511901Sjason@lowepower.com                "dataSize" : self.dataSize}
15611901Sjason@lowepower.com            return allocator
15711901Sjason@lowepower.com
15811901Sjason@lowepower.com    microopClasses["lfpimm"] = LfpimmOp
15911901Sjason@lowepower.com}};
16011901Sjason@lowepower.com
16111901Sjason@lowepower.comlet {{
16211901Sjason@lowepower.com    # Build up the all register version of this micro op
16311901Sjason@lowepower.com    iops = [InstObjParams("limm", "Limm", 'X86MicroopBase',
16411901Sjason@lowepower.com            {"code" : "DestReg = merge(DestReg, imm, dataSize);"}),
16511901Sjason@lowepower.com            InstObjParams("limm", "LimmBig", 'X86MicroopBase',
16611921Spierre-yves.peneau@lirmm.fr            {"code" : "DestReg = imm & mask(dataSize * 8);"})]
16711921Spierre-yves.peneau@lirmm.fr    for iop in iops:
16811921Spierre-yves.peneau@lirmm.fr        header_output += MicroLimmOpDeclare.subst(iop)
16911921Spierre-yves.peneau@lirmm.fr        decoder_output += MicroLimmOpConstructor.subst(iop)
17011921Spierre-yves.peneau@lirmm.fr        decoder_output += MicroLimmOpDisassembly.subst(iop)
17111901Sjason@lowepower.com        exec_output += MicroLimmOpExecute.subst(iop)
17211901Sjason@lowepower.com
17311901Sjason@lowepower.com    iop = InstObjParams("lfpimm", "Lfpimm", 'X86MicroopBase',
17411901Sjason@lowepower.com            {"code" : "FpDestReg_uqw = imm"})
17511901Sjason@lowepower.com    header_output += MicroLimmOpDeclare.subst(iop)
17611901Sjason@lowepower.com    decoder_output += MicroLimmOpConstructor.subst(iop)
17712562Ssiddhesh.poyarekar@gmail.com    decoder_output += MicroLimmOpDisassembly.subst(iop)
17812562Ssiddhesh.poyarekar@gmail.com    exec_output += MicroLimmOpExecute.subst(iop)
17912562Ssiddhesh.poyarekar@gmail.com}};
18011901Sjason@lowepower.com