specialize.isa (4601:38c989d15fef) | specialize.isa (4609:29b5f66fed1a) |
---|---|
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: --- 50 unchanged lines hidden (view full) --- 59// 60// Code to "specialize" a microcode sequence to use a particular 61// variety of operands 62// 63 64let {{ 65 # This code builds up a decode block which decodes based on switchval. 66 # vals is a dict which matches case values with what should be decoded to. | 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: --- 50 unchanged lines hidden (view full) --- 59// 60// Code to "specialize" a microcode sequence to use a particular 61// variety of operands 62// 63 64let {{ 65 # This code builds up a decode block which decodes based on switchval. 66 # vals is a dict which matches case values with what should be decoded to. |
67 # builder is called on the exploded contents of "vals" values to generate 68 # whatever code should be used. 69 def doSplitDecode(builder, switchVal, vals, default = None): | 67 # Each element of the dict is a list containing a function and then the 68 # arguments to pass to it. 69 def doSplitDecode(switchVal, vals, default = None): |
70 blocks = OutputBlocks() 71 blocks.decode_block = 'switch(%s) {\n' % switchVal 72 for (val, todo) in vals.items(): | 70 blocks = OutputBlocks() 71 blocks.decode_block = 'switch(%s) {\n' % switchVal 72 for (val, todo) in vals.items(): |
73 new_blocks = builder(*todo) | 73 new_blocks = todo[0](*todo[1:]) |
74 new_blocks.decode_block = \ 75 '\tcase %s: %s\n' % (val, new_blocks.decode_block) 76 blocks.append(new_blocks) 77 if default: | 74 new_blocks.decode_block = \ 75 '\tcase %s: %s\n' % (val, new_blocks.decode_block) 76 blocks.append(new_blocks) 77 if default: |
78 new_blocks = builder(*default) | 78 new_blocks = default[0](*default[1:]) |
79 new_blocks.decode_block = \ 80 '\tdefault: %s\n' % new_blocks.decode_block 81 blocks.append(new_blocks) 82 blocks.decode_block += '}\n' 83 return blocks 84}}; 85 86let {{ | 79 new_blocks.decode_block = \ 80 '\tdefault: %s\n' % new_blocks.decode_block 81 blocks.append(new_blocks) 82 blocks.decode_block += '}\n' 83 return blocks 84}}; 85 86let {{ |
87 def doRipRelativeDecode(Name, opTypes, env): 88 # print "RIPing %s with opTypes %s" % (Name, opTypes) 89 normBlocks = specializeInst(Name + "_M", copy.copy(opTypes), copy.copy(env)) 90 ripBlocks = specializeInst(Name + "_P", copy.copy(opTypes), copy.copy(env)) 91 92 blocks = OutputBlocks() 93 blocks.append(normBlocks) 94 blocks.append(ripBlocks) 95 96 blocks.decode_block = ''' 97 if(machInst.modRM.mod == 0 && 98 machInst.modRM.rm == 5 && 99 machInst.mode.submode == SixtyFourBitMode) 100 { %s } 101 else 102 { %s }''' % \ 103 (ripBlocks.decode_block, normBlocks.decode_block) 104 return blocks 105}}; 106 107let {{ |
|
87 class OpType(object): 88 parser = re.compile(r"(?P<tag>[A-Z]+)(?P<size>[a-z]*)|(r(?P<reg>[A-Z0-9]+)(?P<rsize>[a-z]*))") 89 def __init__(self, opTypeString): 90 match = OpType.parser.search(opTypeString) 91 if match == None: 92 raise Exception, "Problem parsing operand type %s" % opTypeString 93 self.reg = match.group("reg") 94 self.tag = match.group("tag") --- 42 unchanged lines hidden (view full) --- 137 # This might refer to memory or to a register. We need to 138 # divide it up farther. 139 regEnv = copy.copy(env) 140 regEnv.addReg(ModRMRMIndex) 141 # This refers to memory. The macroop constructor should set up 142 # modrm addressing. 143 memEnv = copy.copy(env) 144 memEnv.doModRM = True | 108 class OpType(object): 109 parser = re.compile(r"(?P<tag>[A-Z]+)(?P<size>[a-z]*)|(r(?P<reg>[A-Z0-9]+)(?P<rsize>[a-z]*))") 110 def __init__(self, opTypeString): 111 match = OpType.parser.search(opTypeString) 112 if match == None: 113 raise Exception, "Problem parsing operand type %s" % opTypeString 114 self.reg = match.group("reg") 115 self.tag = match.group("tag") --- 42 unchanged lines hidden (view full) --- 158 # This might refer to memory or to a register. We need to 159 # divide it up farther. 160 regEnv = copy.copy(env) 161 regEnv.addReg(ModRMRMIndex) 162 # This refers to memory. The macroop constructor should set up 163 # modrm addressing. 164 memEnv = copy.copy(env) 165 memEnv.doModRM = True |
145 return doSplitDecode(specializeInst, "MODRM_MOD", 146 {"3" : (Name + "_R", copy.copy(opTypes), regEnv)}, 147 (Name + "_M", copy.copy(opTypes), memEnv)) | 166 return doSplitDecode("MODRM_MOD", 167 {"3" : (specializeInst, Name + "_R", copy.copy(opTypes), regEnv)}, 168 (doRipRelativeDecode, Name, copy.copy(opTypes), memEnv)) |
148 elif opType.tag in ("I", "J"): 149 # Immediates 150 Name += "_I" 151 elif opType.tag in ("PR", "R", "VR"): 152 # Non register modrm settings should cause an error 153 env.addReg(ModRMRMIndex) 154 Name += "_R" 155 else: 156 raise Exception, "Unrecognized tag %s." % opType.tag 157 158 # Generate code to return a macroop of the given name which will 159 # operate in the "emulation environment" env 160 return genMacroop(Name, env) 161}}; | 169 elif opType.tag in ("I", "J"): 170 # Immediates 171 Name += "_I" 172 elif opType.tag in ("PR", "R", "VR"): 173 # Non register modrm settings should cause an error 174 env.addReg(ModRMRMIndex) 175 Name += "_R" 176 else: 177 raise Exception, "Unrecognized tag %s." % opType.tag 178 179 # Generate code to return a macroop of the given name which will 180 # operate in the "emulation environment" env 181 return genMacroop(Name, env) 182}}; |