multi.isa revision 4310:8f9d834f19bc
1// -*- mode:c++ -*-
2
3// Copyright (c) 2007 The Hewlett-Packard Development Company
4// All rights reserved.
5//
6// Redistribution and use of this software in source and binary forms,
7// with or without modification, are permitted provided that the
8// following conditions are met:
9//
10// The software must be used only for Non-Commercial Use which means any
11// use which is NOT directed to receiving any direct monetary
12// compensation for, or commercial advantage from such use.  Illustrative
13// examples of non-commercial use are academic research, personal study,
14// teaching, education and corporate research & development.
15// Illustrative examples of commercial use are distributing products for
16// commercial advantage and providing services using the software for
17// commercial advantage.
18//
19// If you wish to use this software or functionality therein that may be
20// covered by patents for commercial use, please contact:
21//     Director of Intellectual Property Licensing
22//     Office of Strategy and Technology
23//     Hewlett-Packard Company
24//     1501 Page Mill Road
25//     Palo Alto, California  94304
26//
27// Redistributions of source code must retain the above copyright notice,
28// this list of conditions and the following disclaimer.  Redistributions
29// in binary form must reproduce the above copyright notice, this list of
30// conditions and the following disclaimer in the documentation and/or
31// other materials provided with the distribution.  Neither the name of
32// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
33// contributors may be used to endorse or promote products derived from
34// this software without specific prior written permission.  No right of
35// sublicense is granted herewith.  Derivatives of the software and
36// output created using the software may be prepared, but only for
37// Non-Commercial Uses.  Derivatives of the software may be shared with
38// others provided: (i) the others agree to abide by the list of
39// conditions herein which includes the Non-Commercial Use restrictions;
40// and (ii) such Derivatives of the software include the above copyright
41// notice to acknowledge the contribution from this software where
42// applicable, this list of conditions and the disclaimer below.
43//
44// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
47// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
48// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55//
56// Authors: Gabe Black
57
58////////////////////////////////////////////////////////////////////
59//
60// Instructions that do the same thing to multiple sets of arguments.
61//
62
63output header {{
64}};
65
66output decoder {{
67}};
68
69output exec {{
70}};
71
72let {{
73    multiops = {}
74}};
75
76def format MultiOp(code, switchVal, opTags, *opt_flags) {{
77    # These are C++ statements to create each type of static int. Since we
78    # don't know what will be microcoded and what won't, we can't assume a
79    # particular set of arguments for the constructor.
80    instNew = []
81    orig_code = code
82    opRe = re.compile(r"%(?P<operandNum>[0-9]*)")
83    # Get all the labels out of the code and make a dict for them. We'll do
84    # this once since the position of labels shouldn't need to change at all.
85    ops = assembleMicro(code)
86    labels = buildLabelDict(ops)
87    for tagSet in opTags:
88        # A list of strings which either have the register number to use, or
89        # a piece of code for calculating it.
90        regNums = []
91        code = orig_code
92        # Build up a name for this instructions class using the argument
93        # types. Each variation will get its own name this way.
94        postfix = ''
95        for tag in tagSet:
96            postfix += '_' + tag
97
98        # Figure out what register indexes to use for each operand. This
99        # is where loads/stores could be set up. I need to distinguish
100        # between inputs and outputs.
101        # For right now, the indexes are just an increasing sequence
102        counter = 0
103        for tag in tagSet:
104            regNums.append("%d" % counter)
105            counter += 1
106
107        # Replace the placeholders %0, %1, etc., with the right register
108        # indexes.
109        opMatch = opRe.search(code)
110        while opMatch:
111            opNum = opMatch.group("operandNum")
112            opNum = int(opNum)
113            if opNum > len(regNums):
114                print "No operand type specified for operand %d!" % opNum
115                print "I should bail out here too!"
116            regNum = regNums[opNum]
117            code = opRe.sub(regNum, code, 1)
118            opMatch = opRe.search(code)
119
120        # All the loads which feed this instruction
121        loads = []
122        # All the ops that make up the instruction proper.
123        ops = assembleMicro(code)
124        # Get all the labels out and make a dict for them
125        # All the stores for this instruction's results
126        stores = []
127
128        # Various counts
129        numLoads = len(loads)
130        numOps = len(ops)
131        numStores = len(stores)
132        totalOps = numLoads + numOps + numStores
133        print "There are %d total ops" % totalOps
134
135        # If we can implement this instruction with exactly one microop, just
136        # use that directly.
137        newStmnt = ''
138        if totalOps == 1:
139            newStmnt = ops[0].getAllocator(labels)
140        else:
141            # Build up a macro op. We'll punt on this for now
142            pass
143
144        instNew.append(newStmnt)
145
146    decodeBlob = 'switch(%s) {\n' % switchVal
147    counter = 0
148    for newStmnt in instNew:
149        decodeBlob += 'case %d: return (X86StaticInst *)(%s);\n' % \
150                      (counter, newStmnt)
151        counter += 1
152    decodeBlob += '}\n'
153    decode_block = decodeBlob
154}};
155