Deleted Added
sdiff udiff text old ( 2649:2fb859a457a2 ) new ( 2665:a124942bacb8 )
full compact
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////////////////////////////////////////////////////////////////////
30//
31// Integer operate instructions
32//
33
34output header {{
35 /**
36 * Base class for integer immediate instructions.
37 */
38 class IntegerImm : public AlphaStaticInst
39 {
40 protected:
41 /// Immediate operand value (unsigned 8-bit int).
42 uint8_t imm;
43
44 /// Constructor
45 IntegerImm(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
46 : AlphaStaticInst(mnem, _machInst, __opClass), imm(INTIMM)
47 {
48 }
49
50 std::string
51 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
52 };
53}};
54
55output decoder {{
56 std::string
57 IntegerImm::generateDisassembly(Addr pc, const SymbolTable *symtab) const
58 {
59 std::stringstream ss;
60
61 ccprintf(ss, "%-10s ", mnemonic);
62
63 // just print the first source reg... if there's
64 // a second one, it's a read-modify-write dest (Rc),
65 // e.g. for CMOVxx
66 if (_numSrcRegs > 0) {
67 printReg(ss, _srcRegIdx[0]);
68 ss << ",";
69 }
70
71 ss << (int)imm;
72
73 if (_numDestRegs > 0) {
74 ss << ",";
75 printReg(ss, _destRegIdx[0]);
76 }
77
78 return ss.str();
79 }
80}};
81
82
83def template RegOrImmDecode {{
84 {
85 AlphaStaticInst *i =
86 (IMM) ? (AlphaStaticInst *)new %(class_name)sImm(machInst)
87 : (AlphaStaticInst *)new %(class_name)s(machInst);
88 if (RC == 31) {
89 i = makeNop(i);
90 }
91 return i;
92 }
93}};
94
95// Primary format for integer operate instructions:
96// - Generates both reg-reg and reg-imm versions if Rb_or_imm is used.
97// - Generates NOP if RC == 31.
98def format IntegerOperate(code, *opt_flags) {{
99 # If the code block contains 'Rb_or_imm', we define two instructions,
100 # one using 'Rb' and one using 'imm', and have the decoder select
101 # the right one.
102 uses_imm = (code.find('Rb_or_imm') != -1)
103 if uses_imm:
104 orig_code = code
105 # base code is reg version:
106 # rewrite by substituting 'Rb' for 'Rb_or_imm'
107 code = re.sub(r'Rb_or_imm', 'Rb', orig_code)
108 # generate immediate version by substituting 'imm'
109 # note that imm takes no extenstion, so we extend
110 # the regexp to replace any extension as well
111 imm_code = re.sub(r'Rb_or_imm(\.\w+)?', 'imm', orig_code)
112
113 # generate declaration for register version
114 cblk = CodeBlock(code)
115 iop = InstObjParams(name, Name, 'AlphaStaticInst', cblk, opt_flags)
116 header_output = BasicDeclare.subst(iop)
117 decoder_output = BasicConstructor.subst(iop)
118 exec_output = BasicExecute.subst(iop)
119
120 if uses_imm:
121 # append declaration for imm version
122 imm_cblk = CodeBlock(imm_code)
123 imm_iop = InstObjParams(name, Name + 'Imm', 'IntegerImm', imm_cblk,
124 opt_flags)
125 header_output += BasicDeclare.subst(imm_iop)
126 decoder_output += BasicConstructor.subst(imm_iop)
127 exec_output += BasicExecute.subst(imm_iop)
128 # decode checks IMM bit to pick correct version
129 decode_block = RegOrImmDecode.subst(iop)
130 else:
131 # no imm version: just check for nop
132 decode_block = OperateNopCheckDecode.subst(iop)
133}};