limmop.isa revision 10184:bbfa3152bdea
1// Copyright (c) 2007 The Hewlett-Packard Development Company
2// All rights reserved.
3//
4// The license below extends only to copyright in the software and shall
5// not be construed as granting a license to any other intellectual
6// property including but not limited to intellectual property relating
7// to a hardware implementation of the functionality of the software
8// licensed hereunder.  You may use the software subject to the license
9// terms below provided that you ensure that this notice is replicated
10// unmodified and in its entirety in all distributions of the software,
11// modified or unmodified, in source code or in binary form.
12//
13// Redistribution and use in source and binary forms, with or without
14// modification, are permitted provided that the following conditions are
15// met: redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer;
17// redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution;
20// neither the name of the copyright holders nor the names of its
21// contributors may be used to endorse or promote products derived from
22// this software without specific prior written permission.
23//
24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35//
36// Authors: Gabe Black
37
38//////////////////////////////////////////////////////////////////////////
39//
40// LIMMOp Microop templates
41//
42//////////////////////////////////////////////////////////////////////////
43
44def template MicroLimmOpExecute {{
45        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
46                Trace::InstRecord *traceData) const
47        {
48            %(op_decl)s;
49            %(op_rd)s;
50            %(code)s;
51            %(op_wb)s;
52            return NoFault;
53        }
54}};
55
56def template MicroLimmOpDeclare {{
57    class %(class_name)s : public X86ISA::X86MicroopBase
58    {
59      protected:
60        const RegIndex dest;
61        const uint64_t imm;
62        const uint8_t dataSize;
63        RegIndex foldOBit;
64
65        std::string generateDisassembly(Addr pc,
66            const SymbolTable *symtab) const;
67
68      public:
69        %(class_name)s(ExtMachInst _machInst,
70                const char * instMnem,
71                uint64_t setFlags, InstRegIndex _dest,
72                uint64_t _imm, uint8_t _dataSize);
73
74        %(BasicExecDeclare)s
75    };
76}};
77
78def template MicroLimmOpDisassembly {{
79    std::string %(class_name)s::generateDisassembly(Addr pc,
80            const SymbolTable *symtab) const
81    {
82        std::stringstream response;
83
84        printMnemonic(response, instMnem, mnemonic);
85        printDestReg(response, 0, dataSize);
86        response << ", ";
87        ccprintf(response, "%#x", imm);
88        return response.str();
89    }
90}};
91
92def template MicroLimmOpConstructor {{
93    %(class_name)s::%(class_name)s(
94            ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
95            InstRegIndex _dest, uint64_t _imm, uint8_t _dataSize) :
96        %(base_class)s(machInst, "%(mnemonic)s", instMnem,
97                setFlags, %(op_class)s),
98                dest(_dest.idx), imm(_imm), dataSize(_dataSize)
99    {
100        foldOBit = (dataSize == 1 && !machInst.rex.present) ? 1 << 6 : 0;
101        %(constructor)s;
102    }
103}};
104
105let {{
106    class LimmOp(X86Microop):
107        def __init__(self, dest, imm, dataSize="env.dataSize"):
108            self.className = "Limm"
109            self.mnemonic = "limm"
110            self.dest = dest
111            if isinstance(imm, (int, long)):
112                imm = "ULL(%d)" % imm
113            self.imm = imm
114            self.dataSize = dataSize
115
116        def getAllocator(self, microFlags):
117            allocString = '''
118                (%(dataSize)s >= 4) ?
119                    (StaticInstPtr)(new %(class_name)sBig(machInst,
120                        macrocodeBlock, %(flags)s, %(dest)s, %(imm)s,
121                        %(dataSize)s)) :
122                    (StaticInstPtr)(new %(class_name)s(machInst,
123                        macrocodeBlock, %(flags)s, %(dest)s, %(imm)s,
124                        %(dataSize)s))
125            '''
126            allocator = allocString % {
127                "class_name" : self.className,
128                "mnemonic" : self.mnemonic,
129                "flags" : self.microFlagsText(microFlags),
130                "dest" : self.dest, "imm" : self.imm,
131                "dataSize" : self.dataSize}
132            return allocator
133
134    microopClasses["limm"] = LimmOp
135
136    class LfpimmOp(X86Microop):
137        def __init__(self, dest, imm, dataSize="env.dataSize"):
138            self.className = "Lfpimm"
139            self.mnemonic = "lfpimm"
140            self.dest = dest
141            if isinstance(imm, (int, long)):
142                imm = "ULL(%d)" % imm
143            elif isinstance(imm, float):
144                imm = "getDoubleBits(%.16f)" % imm
145            self.imm = imm
146            self.dataSize = dataSize
147
148        def getAllocator(self, microFlags):
149            allocator = '''new %(class_name)s(machInst, macrocodeBlock,
150                    %(flags)s, %(dest)s, %(imm)s, %(dataSize)s)''' % {
151                "class_name" : self.className,
152                "mnemonic" : self.mnemonic,
153                "flags" : self.microFlagsText(microFlags),
154                "dest" : self.dest, "imm" : self.imm,
155                "dataSize" : self.dataSize}
156            return allocator
157
158    microopClasses["lfpimm"] = LfpimmOp
159}};
160
161let {{
162    # Build up the all register version of this micro op
163    iops = [InstObjParams("limm", "Limm", 'X86MicroopBase',
164            {"code" : "DestReg = merge(DestReg, imm, dataSize);"}),
165            InstObjParams("limm", "LimmBig", 'X86MicroopBase',
166            {"code" : "DestReg = imm & mask(dataSize * 8);"})]
167    for iop in iops:
168        header_output += MicroLimmOpDeclare.subst(iop)
169        decoder_output += MicroLimmOpConstructor.subst(iop)
170        decoder_output += MicroLimmOpDisassembly.subst(iop)
171        exec_output += MicroLimmOpExecute.subst(iop)
172
173    iop = InstObjParams("lfpimm", "Lfpimm", 'X86MicroopBase',
174            {"code" : "FpDestReg_uqw = imm"})
175    header_output += MicroLimmOpDeclare.subst(iop)
176    decoder_output += MicroLimmOpConstructor.subst(iop)
177    decoder_output += MicroLimmOpDisassembly.subst(iop)
178    exec_output += MicroLimmOpExecute.subst(iop)
179}};
180