int.isa revision 2665
1// -*- mode:c++ -*-
2
3// Copyright (c) 2003-2005 The Regents of The University of Michigan
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met: redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer;
10// redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution;
13// neither the name of the copyright holders nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29// Authors: Steve Reinhardt
30
31////////////////////////////////////////////////////////////////////
32//
33// Integer operate instructions
34//
35
36output header {{
37    /**
38     * Base class for integer immediate instructions.
39     */
40    class IntegerImm : public AlphaStaticInst
41    {
42      protected:
43        /// Immediate operand value (unsigned 8-bit int).
44        uint8_t imm;
45
46        /// Constructor
47        IntegerImm(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
48            : AlphaStaticInst(mnem, _machInst, __opClass), imm(INTIMM)
49        {
50        }
51
52        std::string
53        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
54    };
55}};
56
57output decoder {{
58    std::string
59    IntegerImm::generateDisassembly(Addr pc, const SymbolTable *symtab) const
60    {
61        std::stringstream ss;
62
63        ccprintf(ss, "%-10s ", mnemonic);
64
65        // just print the first source reg... if there's
66        // a second one, it's a read-modify-write dest (Rc),
67        // e.g. for CMOVxx
68        if (_numSrcRegs > 0) {
69            printReg(ss, _srcRegIdx[0]);
70            ss << ",";
71        }
72
73        ss << (int)imm;
74
75        if (_numDestRegs > 0) {
76            ss << ",";
77            printReg(ss, _destRegIdx[0]);
78        }
79
80        return ss.str();
81    }
82}};
83
84
85def template RegOrImmDecode {{
86 {
87     AlphaStaticInst *i =
88         (IMM) ? (AlphaStaticInst *)new %(class_name)sImm(machInst)
89               : (AlphaStaticInst *)new %(class_name)s(machInst);
90     if (RC == 31) {
91         i = makeNop(i);
92     }
93     return i;
94 }
95}};
96
97// Primary format for integer operate instructions:
98// - Generates both reg-reg and reg-imm versions if Rb_or_imm is used.
99// - Generates NOP if RC == 31.
100def format IntegerOperate(code, *opt_flags) {{
101    # If the code block contains 'Rb_or_imm', we define two instructions,
102    # one using 'Rb' and one using 'imm', and have the decoder select
103    # the right one.
104    uses_imm = (code.find('Rb_or_imm') != -1)
105    if uses_imm:
106        orig_code = code
107        # base code is reg version:
108        # rewrite by substituting 'Rb' for 'Rb_or_imm'
109        code = re.sub(r'Rb_or_imm', 'Rb', orig_code)
110        # generate immediate version by substituting 'imm'
111        # note that imm takes no extenstion, so we extend
112        # the regexp to replace any extension as well
113        imm_code = re.sub(r'Rb_or_imm(\.\w+)?', 'imm', orig_code)
114
115    # generate declaration for register version
116    cblk = CodeBlock(code)
117    iop = InstObjParams(name, Name, 'AlphaStaticInst', cblk, opt_flags)
118    header_output = BasicDeclare.subst(iop)
119    decoder_output = BasicConstructor.subst(iop)
120    exec_output = BasicExecute.subst(iop)
121
122    if uses_imm:
123        # append declaration for imm version
124        imm_cblk = CodeBlock(imm_code)
125        imm_iop = InstObjParams(name, Name + 'Imm', 'IntegerImm', imm_cblk,
126                                opt_flags)
127        header_output += BasicDeclare.subst(imm_iop)
128        decoder_output += BasicConstructor.subst(imm_iop)
129        exec_output += BasicExecute.subst(imm_iop)
130        # decode checks IMM bit to pick correct version
131        decode_block = RegOrImmDecode.subst(iop)
132    else:
133        # no imm version: just check for nop
134        decode_block = OperateNopCheckDecode.subst(iop)
135}};
136