microasm.isa revision 4344
111106Spower.jg@gmail.com// -*- mode:c++ -*-
211106Spower.jg@gmail.com
311106Spower.jg@gmail.com// Copyright (c) 2007 The Hewlett-Packard Development Company
411106Spower.jg@gmail.com// All rights reserved.
511106Spower.jg@gmail.com//
611106Spower.jg@gmail.com// Redistribution and use of this software in source and binary forms,
711106Spower.jg@gmail.com// with or without modification, are permitted provided that the
811106Spower.jg@gmail.com// following conditions are met:
911106Spower.jg@gmail.com//
1011106Spower.jg@gmail.com// The software must be used only for Non-Commercial Use which means any
1111106Spower.jg@gmail.com// use which is NOT directed to receiving any direct monetary
1211106Spower.jg@gmail.com// compensation for, or commercial advantage from such use.  Illustrative
1311106Spower.jg@gmail.com// examples of non-commercial use are academic research, personal study,
1411106Spower.jg@gmail.com// teaching, education and corporate research & development.
1511106Spower.jg@gmail.com// Illustrative examples of commercial use are distributing products for
1611106Spower.jg@gmail.com// commercial advantage and providing services using the software for
1711106Spower.jg@gmail.com// commercial advantage.
1811106Spower.jg@gmail.com//
1911106Spower.jg@gmail.com// If you wish to use this software or functionality therein that may be
2011106Spower.jg@gmail.com// covered by patents for commercial use, please contact:
2111106Spower.jg@gmail.com//     Director of Intellectual Property Licensing
2211106Spower.jg@gmail.com//     Office of Strategy and Technology
2311106Spower.jg@gmail.com//     Hewlett-Packard Company
2411106Spower.jg@gmail.com//     1501 Page Mill Road
2511106Spower.jg@gmail.com//     Palo Alto, California  94304
2611106Spower.jg@gmail.com//
2711106Spower.jg@gmail.com// Redistributions of source code must retain the above copyright notice,
2811106Spower.jg@gmail.com// this list of conditions and the following disclaimer.  Redistributions
2911106Spower.jg@gmail.com// in binary form must reproduce the above copyright notice, this list of
3011106Spower.jg@gmail.com// conditions and the following disclaimer in the documentation and/or
3111106Spower.jg@gmail.com// other materials provided with the distribution.  Neither the name of
3211106Spower.jg@gmail.com// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
3311106Spower.jg@gmail.com// contributors may be used to endorse or promote products derived from
3411106Spower.jg@gmail.com// this software without specific prior written permission.  No right of
3511106Spower.jg@gmail.com// sublicense is granted herewith.  Derivatives of the software and
3611106Spower.jg@gmail.com// output created using the software may be prepared, but only for
3711106Spower.jg@gmail.com// Non-Commercial Uses.  Derivatives of the software may be shared with
3811106Spower.jg@gmail.com// others provided: (i) the others agree to abide by the list of
3911106Spower.jg@gmail.com// conditions herein which includes the Non-Commercial Use restrictions;
4011106Spower.jg@gmail.com// and (ii) such Derivatives of the software include the above copyright
4111106Spower.jg@gmail.com// notice to acknowledge the contribution from this software where
4211106Spower.jg@gmail.com// applicable, this list of conditions and the disclaimer below.
4311106Spower.jg@gmail.com//
4411106Spower.jg@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4511106Spower.jg@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4611106Spower.jg@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4711106Spower.jg@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4811106Spower.jg@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4911106Spower.jg@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5011106Spower.jg@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5111106Spower.jg@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5211106Spower.jg@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5311106Spower.jg@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5411106Spower.jg@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5511106Spower.jg@gmail.com//
5611106Spower.jg@gmail.com// Authors: Gabe Black
5711106Spower.jg@gmail.com
5811106Spower.jg@gmail.com////////////////////////////////////////////////////////////////////
5911106Spower.jg@gmail.com//
6011106Spower.jg@gmail.com//  Code to "specialize" a microcode sequence to use a particular
6111106Spower.jg@gmail.com//  variety of operands
6211106Spower.jg@gmail.com//
6311106Spower.jg@gmail.com
6411106Spower.jg@gmail.comlet {{
6511106Spower.jg@gmail.com    # This code builds up a decode block which decodes based on switchval.
6611106Spower.jg@gmail.com    # vals is a dict which matches case values with what should be decoded to.
6711106Spower.jg@gmail.com    # builder is called on the exploded contents of "vals" values to generate
6811106Spower.jg@gmail.com    # whatever code should be used.
6911106Spower.jg@gmail.com    def doSplitDecode(name, Name, builder, switchVal, vals, default = None):
7011106Spower.jg@gmail.com        header_output = ''
7111106Spower.jg@gmail.com        decoder_output = ''
7211106Spower.jg@gmail.com        decode_block = 'switch(%s) {\n' % switchVal
7311106Spower.jg@gmail.com        exec_output = ''
7411106Spower.jg@gmail.com        for (val, todo) in vals.items():
7511106Spower.jg@gmail.com            (new_header_output,
7611106Spower.jg@gmail.com             new_decoder_output,
7711106Spower.jg@gmail.com             new_decode_block,
7811106Spower.jg@gmail.com             new_exec_output) = builder(name, Name, *todo)
7911106Spower.jg@gmail.com            header_output += new_header_output
8011106Spower.jg@gmail.com            decoder_output += new_decoder_output
8111106Spower.jg@gmail.com            decode_block += '\tcase %s: %s\n' % (val, new_decode_block)
8211106Spower.jg@gmail.com            exec_output += new_exec_output
8311106Spower.jg@gmail.com        if default:
8411106Spower.jg@gmail.com            (new_header_output,
8511106Spower.jg@gmail.com             new_decoder_output,
8611106Spower.jg@gmail.com             new_decode_block,
8711106Spower.jg@gmail.com             new_exec_output) = builder(name, Name, *default)
8811106Spower.jg@gmail.com            header_output += new_header_output
8911106Spower.jg@gmail.com            decoder_output += new_decoder_output
9011106Spower.jg@gmail.com            decode_block += '\tdefault: %s\n' % new_decode_block
9111106Spower.jg@gmail.com            exec_output += new_exec_output
9211106Spower.jg@gmail.com        decode_block += '}\n'
9311106Spower.jg@gmail.com        return (header_output, decoder_output, decode_block, exec_output)
9411106Spower.jg@gmail.com}};
9511106Spower.jg@gmail.com
9611106Spower.jg@gmail.comlet {{
9711106Spower.jg@gmail.com    class OpType(object):
9811106Spower.jg@gmail.com        parser = re.compile(r"(?P<tag>[A-Z][A-Z]*)(?P<size>[a-z][a-z]*)|(r(?P<reg>[A-Za-z0-9][A-Za-z0-9]*))")
9911106Spower.jg@gmail.com        def __init__(self, opTypeString):
10011106Spower.jg@gmail.com            match = OpType.parser.search(opTypeString)
10111106Spower.jg@gmail.com            if match == None:
10211106Spower.jg@gmail.com                raise Exception, "Problem parsing operand type %s" % opTypeString
10311106Spower.jg@gmail.com            self.reg = match.group("reg")
10411106Spower.jg@gmail.com            self.tag = match.group("tag")
10511106Spower.jg@gmail.com            self.size = match.group("size")
10611106Spower.jg@gmail.com}};
10711106Spower.jg@gmail.com
10811106Spower.jg@gmail.comlet {{
10911106Spower.jg@gmail.com
11011106Spower.jg@gmail.com    # This function specializes the given piece of code to use a particular
11111106Spower.jg@gmail.com    # set of argument types described by "opTypes". These are "implemented"
11211106Spower.jg@gmail.com    # in reverse order.
11311106Spower.jg@gmail.com    def specializeInst(name, Name, code, opTypes):
11411106Spower.jg@gmail.com        opNum = len(opTypes) - 1
11511106Spower.jg@gmail.com        while len(opTypes):
11611106Spower.jg@gmail.com            # print "Building a composite op with tags", opTypes
11711106Spower.jg@gmail.com            # print "And code", code
11811106Spower.jg@gmail.com            opNum = len(opTypes) - 1
11911106Spower.jg@gmail.com            # A regular expression to find the operand placeholders we're
12011106Spower.jg@gmail.com            # interested in.
12111106Spower.jg@gmail.com            opRe = re.compile("\\^(?P<operandNum>%d)(?=[^0-9]|$)" % opNum)
12211106Spower.jg@gmail.com
12311106Spower.jg@gmail.com            # Parse the operand type strign we're working with
12411106Spower.jg@gmail.com            opType = OpType(opTypes[opNum])
12511106Spower.jg@gmail.com
12611106Spower.jg@gmail.com            if opType.reg:
12711106Spower.jg@gmail.com                #Figure out what to do with fixed register operands
12811106Spower.jg@gmail.com                if opType.reg in ("Ax", "Bx", "Cx", "Dx"):
12911106Spower.jg@gmail.com                    code = opRe.sub("%%{INTREG_R%s}" % opType.reg.upper(), code)
13011106Spower.jg@gmail.com                elif opType.reg == "Al":
13111106Spower.jg@gmail.com                    # We need a way to specify register width
13211106Spower.jg@gmail.com                    code = opRe.sub("%{INTREG_RAX}", code)
13311106Spower.jg@gmail.com                else:
13411106Spower.jg@gmail.com                    print "Didn't know how to encode fixed register %s!" % opType.reg
13511106Spower.jg@gmail.com            elif opType.tag == None or opType.size == None:
13611106Spower.jg@gmail.com                raise Exception, "Problem parsing operand tag: %s" % opType.tag
13711106Spower.jg@gmail.com            elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"):
13811106Spower.jg@gmail.com                # Use the "reg" field of the ModRM byte to select the register
13911106Spower.jg@gmail.com                code = opRe.sub("%{(uint8_t)MODRM_REG}", code)
14011106Spower.jg@gmail.com            elif opType.tag in ("E", "Q", "W"):
14111106Spower.jg@gmail.com                # This might refer to memory or to a register. We need to
14211106Spower.jg@gmail.com                # divide it up farther.
14311106Spower.jg@gmail.com                regCode = opRe.sub("%{(uint8_t)MODRM_RM}", code)
14411106Spower.jg@gmail.com                regTypes = copy.copy(opTypes)
14511106Spower.jg@gmail.com                regTypes.pop(-1)
14611106Spower.jg@gmail.com                # This needs to refer to memory, but we'll fill in the details
14711106Spower.jg@gmail.com                # later. It needs to take into account unaligned memory
14811106Spower.jg@gmail.com                # addresses.
14911106Spower.jg@gmail.com                memCode = opRe.sub("%0", code)
15011106Spower.jg@gmail.com                memTypes = copy.copy(opTypes)
15111106Spower.jg@gmail.com                memTypes.pop(-1)
15211106Spower.jg@gmail.com                return doSplitDecode(name, Name, specializeInst, "MODRM_MOD",
15311106Spower.jg@gmail.com                    {"3" : (regCode, regTypes)}, (memCode, memTypes))
15411106Spower.jg@gmail.com            elif opType.tag in ("I", "J"):
15511106Spower.jg@gmail.com                # Immediates are already in the instruction, so don't leave in
15611106Spower.jg@gmail.com                # those parameters
15711106Spower.jg@gmail.com                code = opRe.sub("${IMMEDIATE}", code)
15811106Spower.jg@gmail.com            elif opType.tag == "M":
15911106Spower.jg@gmail.com                # This needs to refer to memory, but we'll fill in the details
16011106Spower.jg@gmail.com                # later. It needs to take into account unaligned memory
16111106Spower.jg@gmail.com                # addresses.
16211106Spower.jg@gmail.com                code = opRe.sub("%0", code)
16311106Spower.jg@gmail.com            elif opType.tag in ("PR", "R", "VR"):
16411106Spower.jg@gmail.com                # There should probably be a check here to verify that mod
16511106Spower.jg@gmail.com                # is equal to 11b
16611106Spower.jg@gmail.com                code = opRe.sub("%{(uint8_t)MODRM_RM}", code)
16711106Spower.jg@gmail.com            else:
16811106Spower.jg@gmail.com                raise Exception, "Unrecognized tag %s." % opType.tag
16911106Spower.jg@gmail.com            opTypes.pop(-1)
17011106Spower.jg@gmail.com
17111106Spower.jg@gmail.com        # At this point, we've built up "code" to have all the necessary extra
17211106Spower.jg@gmail.com        # instructions needed to implement whatever types of operands were
17311106Spower.jg@gmail.com        # specified. Now we'll assemble it it into a StaticInst.
17411106Spower.jg@gmail.com        return assembleMicro(name, Name, code)
17511106Spower.jg@gmail.com}};
17611106Spower.jg@gmail.com
17711106Spower.jg@gmail.com////////////////////////////////////////////////////////////////////
17811106Spower.jg@gmail.com//
17911106Spower.jg@gmail.com//  The microcode assembler
18011106Spower.jg@gmail.com//
18111106Spower.jg@gmail.com
18211106Spower.jg@gmail.comlet {{
18311106Spower.jg@gmail.com    # These are used when setting up microops so that they can specialize their
18411106Spower.jg@gmail.com    # base class template properly.
18511106Spower.jg@gmail.com    RegOpType = "RegisterOperand"
18611106Spower.jg@gmail.com    ImmOpType = "ImmediateOperand"
18711106Spower.jg@gmail.com}};
18811106Spower.jg@gmail.com
18911106Spower.jg@gmail.comlet {{
19011106Spower.jg@gmail.com    class MicroOpStatement(object):
19111106Spower.jg@gmail.com        def __init__(self):
19211106Spower.jg@gmail.com            self.className = ''
19311106Spower.jg@gmail.com            self.label = ''
19411106Spower.jg@gmail.com            self.args = []
19511106Spower.jg@gmail.com
19611106Spower.jg@gmail.com        # This converts a list of python bools into
19711106Spower.jg@gmail.com        # a comma seperated list of C++ bools.
19811106Spower.jg@gmail.com        def microFlagsText(self, vals):
19911106Spower.jg@gmail.com            text = ""
20011106Spower.jg@gmail.com            for val in vals:
20111106Spower.jg@gmail.com                if val:
20211106Spower.jg@gmail.com                    text += ", true"
20311106Spower.jg@gmail.com                else:
20411106Spower.jg@gmail.com                    text += ", false"
20511106Spower.jg@gmail.com            return text
20611106Spower.jg@gmail.com
20711106Spower.jg@gmail.com        def getAllocator(self, *microFlags):
20811106Spower.jg@gmail.com            args = ''
20911106Spower.jg@gmail.com            signature = "<"
21011106Spower.jg@gmail.com            emptySig = True
21111106Spower.jg@gmail.com            for arg in self.args:
21211106Spower.jg@gmail.com                if not emptySig:
21311106Spower.jg@gmail.com                    signature += ", "
21411106Spower.jg@gmail.com                emptySig = False
21511106Spower.jg@gmail.com                if arg.has_key("operandImm"):
21611106Spower.jg@gmail.com                    args += ", %s" % arg["operandImm"]
21711106Spower.jg@gmail.com                    signature += ImmOpType
21811106Spower.jg@gmail.com                elif arg.has_key("operandReg"):
21911106Spower.jg@gmail.com                    args += ", %s" % arg["operandReg"]
22011106Spower.jg@gmail.com                    signature += RegOpType
22111106Spower.jg@gmail.com                elif arg.has_key("operandLabel"):
22211106Spower.jg@gmail.com                    raise Exception, "Found a label while creating allocator string."
22311106Spower.jg@gmail.com                else:
22411106Spower.jg@gmail.com                    raise Exception, "Unrecognized operand type."
22511106Spower.jg@gmail.com            signature += ">"
22611106Spower.jg@gmail.com            return 'new %s%s(machInst%s%s)' % (self.className, signature, self.microFlagsText(microFlags), args)
22711106Spower.jg@gmail.com}};
22811106Spower.jg@gmail.com
22911106Spower.jg@gmail.comlet{{
23011106Spower.jg@gmail.com    def assembleMicro(name, Name, code):
23111106Spower.jg@gmail.com
23211106Spower.jg@gmail.com        # This function takes in a block of microcode assembly and returns
23311106Spower.jg@gmail.com        # a python list of objects which describe it.
23411106Spower.jg@gmail.com
23511106Spower.jg@gmail.com        # Keep this around in case we need it later
23611106Spower.jg@gmail.com        orig_code = code
23711106Spower.jg@gmail.com        # A list of the statements we've found thus far
23811106Spower.jg@gmail.com        statements = []
23911106Spower.jg@gmail.com
24011106Spower.jg@gmail.com        # Regular expressions to pull each piece of the statement out at a
24111106Spower.jg@gmail.com        # time. Each expression expects the thing it's looking for to be at
24211106Spower.jg@gmail.com        # the beginning of the line, so the previous component is stripped
24311106Spower.jg@gmail.com        # before continuing.
24411106Spower.jg@gmail.com        labelRe = re.compile(r'^[ \t]*(?P<label>\w\w*)[ \t]:')
24511106Spower.jg@gmail.com        lineRe = re.compile(r'^(?P<line>[^\n][^\n]*)$')
24611106Spower.jg@gmail.com        classRe = re.compile(r'^[ \t]*(?P<className>[a-zA-Z_]\w*)')
24711106Spower.jg@gmail.com        # This recognizes three different flavors of operands:
24811106Spower.jg@gmail.com        # 1. Raw decimal numbers composed of digits between 0 and 9
24911106Spower.jg@gmail.com        # 2. Code beginning with "{" and continuing until the first "}"
25011106Spower.jg@gmail.com        #         ^ This one might need revising
25111106Spower.jg@gmail.com        # 3. A label, which starts with a capital or small letter, or
25211106Spower.jg@gmail.com        #    underscore, which is optionally followed by a sequence of
25311106Spower.jg@gmail.com        #    capital or small letters, underscores, or digts between 0 and 9
25411106Spower.jg@gmail.com        opRe = re.compile( \
25511106Spower.jg@gmail.com            r'^[ \t]*((\@(?P<operandLabel0>\w\w*))|' +
25611106Spower.jg@gmail.com                    r'(\@\{(?P<operandLabel1>[^}]*)\})|' +
25711106Spower.jg@gmail.com                    r'(\%(?P<operandReg0>\w\w*))|' +
25811106Spower.jg@gmail.com                    r'(\%\{(?P<operandReg1>[^}]*)\})|' +
25911106Spower.jg@gmail.com                    r'(\$(?P<operandImm0>\w\w*))|' +
26011106Spower.jg@gmail.com                    r'(\$\{(?P<operandImm1>[^}]*)\}))')
26111106Spower.jg@gmail.com        lineMatch = lineRe.search(code)
26211106Spower.jg@gmail.com        while lineMatch != None:
26311106Spower.jg@gmail.com            statement = MicroOpStatement()
26411106Spower.jg@gmail.com            # Get a line and seperate it from the rest of the code
26511106Spower.jg@gmail.com            line = lineMatch.group("line")
26611106Spower.jg@gmail.com            orig_line = line
26711106Spower.jg@gmail.com            # print "Parsing line %s" % line
26811106Spower.jg@gmail.com            code = lineRe.sub('', code, 1)
26911106Spower.jg@gmail.com
27011106Spower.jg@gmail.com            # Find the label, if any
27111106Spower.jg@gmail.com            labelMatch = labelRe.search(line)
27211106Spower.jg@gmail.com            if labelMatch != None:
27311106Spower.jg@gmail.com                statement.label = labelMatch.group("label")
27411106Spower.jg@gmail.com                # print "Found label %s." % statement.label
27511106Spower.jg@gmail.com            # Clear the label from the statement
27611106Spower.jg@gmail.com            line = labelRe.sub('', line, 1)
27711106Spower.jg@gmail.com
27811106Spower.jg@gmail.com            # Find the class name which is roughly equivalent to the op name
27911106Spower.jg@gmail.com            classMatch = classRe.search(line)
28011106Spower.jg@gmail.com            if classMatch == None:
28111106Spower.jg@gmail.com                raise Exception, "Couldn't find class name in statement: %s" \
28211106Spower.jg@gmail.com                        % orig_line
28311106Spower.jg@gmail.com            else:
28411106Spower.jg@gmail.com                statement.className = classMatch.group("className")
28511106Spower.jg@gmail.com                # print "Found class name %s." % statement.className
28611106Spower.jg@gmail.com
28711106Spower.jg@gmail.com            # Clear the class name from the statement
28811106Spower.jg@gmail.com            line = classRe.sub('', line, 1)
28911106Spower.jg@gmail.com
29011106Spower.jg@gmail.com            #Find as many arguments as you can
29111106Spower.jg@gmail.com            statement.args = []
29211106Spower.jg@gmail.com            opMatch = opRe.search(line)
29311106Spower.jg@gmail.com            while opMatch is not None:
29411106Spower.jg@gmail.com                statement.args.append({})
29511106Spower.jg@gmail.com                # args is a list of dicts which collect different
29611106Spower.jg@gmail.com                # representations of operand values. Different forms might be
29711106Spower.jg@gmail.com                # needed in different places, for instance to replace a label
29811106Spower.jg@gmail.com                # with an offset.
29911106Spower.jg@gmail.com                for opType in ("operandLabel0", "operandReg0", "operandImm0",
30011106Spower.jg@gmail.com                               "operandLabel1", "operandReg1", "operandImm1"):
30111106Spower.jg@gmail.com                    if opMatch.group(opType):
30211106Spower.jg@gmail.com                        statement.args[-1][opType[:-1]] = opMatch.group(opType)
30311106Spower.jg@gmail.com                if len(statement.args[-1]) == 0:
30411106Spower.jg@gmail.com                    print "Problem parsing operand in statement: %s" \
30511106Spower.jg@gmail.com                            % orig_line
30611106Spower.jg@gmail.com                line = opRe.sub('', line, 1)
30711106Spower.jg@gmail.com                # print "Found operand %s." % statement.args[-1]
30811106Spower.jg@gmail.com                opMatch = opRe.search(line)
30911106Spower.jg@gmail.com            # print "Found operands", statement.args
31011106Spower.jg@gmail.com
31111106Spower.jg@gmail.com            # Add this statement to our collection
31211106Spower.jg@gmail.com            statements.append(statement)
31311106Spower.jg@gmail.com
31411106Spower.jg@gmail.com            # Get the next line
31511106Spower.jg@gmail.com            lineMatch = lineRe.search(code)
31611106Spower.jg@gmail.com
31711106Spower.jg@gmail.com        # Decode the labels into displacements
31811106Spower.jg@gmail.com
31911106Spower.jg@gmail.com        labels = {}
32011106Spower.jg@gmail.com        micropc = 0
32111106Spower.jg@gmail.com        for statement in statements:
32211106Spower.jg@gmail.com            if statement.label:
32311106Spower.jg@gmail.com                labels[statement.label] = count
32411106Spower.jg@gmail.com            micropc += 1
32511106Spower.jg@gmail.com        micropc = 0
32611106Spower.jg@gmail.com        for statement in statements:
32711106Spower.jg@gmail.com            for arg in statement.args:
32811106Spower.jg@gmail.com                if arg.has_key("operandLabel"):
32911106Spower.jg@gmail.com                    if not labels.has_key(arg["operandLabel"]):
33011106Spower.jg@gmail.com                        raise Exception, "Unrecognized label: %s." % arg["operandLabel"]
33111106Spower.jg@gmail.com                    # This is assuming that intra microcode branches go to
33211106Spower.jg@gmail.com                    # the next micropc + displacement, or
33311106Spower.jg@gmail.com                    # micropc + 1 + displacement.
33411106Spower.jg@gmail.com                    arg["operandImm"] = labels[arg["operandLabel"]] - micropc - 1
33511106Spower.jg@gmail.com            micropc += 1
33611106Spower.jg@gmail.com
33711106Spower.jg@gmail.com        # If we can implement this instruction with exactly one microop, just
33811106Spower.jg@gmail.com        # use that directly.
33911106Spower.jg@gmail.com        if len(statements) == 1:
34011106Spower.jg@gmail.com            decode_block = "return %s;" % \
34111106Spower.jg@gmail.com                            statements[0].getAllocator()
34211106Spower.jg@gmail.com            return ('', '', decode_block, '')
34311106Spower.jg@gmail.com        else:
34411106Spower.jg@gmail.com            # Build a macroop to contain the sequence of microops we've
34511106Spower.jg@gmail.com            # been given.
34611106Spower.jg@gmail.com            return genMacroOp(name, Name, statements)
34711106Spower.jg@gmail.com}};
34811106Spower.jg@gmail.com