specialize.isa (4568:65dcd045da1d) specialize.isa (4575:d0017efdfa02)
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:

--- 52 unchanged lines hidden (view full) ---

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.
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:

--- 52 unchanged lines hidden (view full) ---

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(Name, builder, switchVal, vals, default = None):
69 def doSplitDecode(builder, 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(Name, *todo)
73 new_blocks = builder(*todo)
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(Name, *default)
78 new_blocks = builder(*default)
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 {{

--- 28 unchanged lines hidden (view full) ---

115 env.addReg("INTREG_R%s" % opType.reg)
116 if opType.size:
117 if opType.rsize in ("l", "h", "b"):
118 print "byte"
119 elif opType.rsize == "x":
120 print "word"
121 else:
122 print "Didn't recognize fixed register size %s!" % opType.rsize
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 {{

--- 28 unchanged lines hidden (view full) ---

115 env.addReg("INTREG_R%s" % opType.reg)
116 if opType.size:
117 if opType.rsize in ("l", "h", "b"):
118 print "byte"
119 elif opType.rsize == "x":
120 print "word"
121 else:
122 print "Didn't recognize fixed register size %s!" % opType.rsize
123 Name += "_R"
123 elif opType.tag == None or opType.size == None:
124 raise Exception, "Problem parsing operand tag: %s" % opType.tag
125 elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"):
126 # Use the "reg" field of the ModRM byte to select the register
127 env.addReg(ModRMRegIndex)
124 elif opType.tag == None or opType.size == None:
125 raise Exception, "Problem parsing operand tag: %s" % opType.tag
126 elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"):
127 # Use the "reg" field of the ModRM byte to select the register
128 env.addReg(ModRMRegIndex)
129 Name += "_R"
128 elif opType.tag in ("E", "Q", "W"):
129 # This might refer to memory or to a register. We need to
130 # divide it up farther.
131 regTypes = copy.copy(opTypes)
132 regTypes.pop(0)
133 regEnv = copy.copy(env)
134 regEnv.addReg(ModRMRMIndex)
130 elif opType.tag in ("E", "Q", "W"):
131 # This might refer to memory or to a register. We need to
132 # divide it up farther.
133 regTypes = copy.copy(opTypes)
134 regTypes.pop(0)
135 regEnv = copy.copy(env)
136 regEnv.addReg(ModRMRMIndex)
137 regName = Name + "_R"
135 # This needs to refer to memory, but we'll fill in the details
136 # later. It needs to take into account unaligned memory
137 # addresses.
138 memTypes = copy.copy(opTypes)
139 memTypes.pop(0)
140 memEnv = copy.copy(env)
138 # This needs to refer to memory, but we'll fill in the details
139 # later. It needs to take into account unaligned memory
140 # addresses.
141 memTypes = copy.copy(opTypes)
142 memTypes.pop(0)
143 memEnv = copy.copy(env)
144 memName = Name + "_M"
141 print "%0"
145 print "%0"
142 return doSplitDecode(Name, specializeInst, "MODRM_MOD",
143 {"3" : (regTypes, regEnv)}, (memTypes, memEnv))
146 return doSplitDecode(specializeInst, "MODRM_MOD",
147 {"3" : (regName, regTypes, regEnv)},
148 (memName, memTypes, memEnv))
144 elif opType.tag in ("I", "J"):
145 # Immediates
146 print "IMMEDIATE"
149 elif opType.tag in ("I", "J"):
150 # Immediates
151 print "IMMEDIATE"
152 Name += "_I"
147 elif opType.tag == "M":
148 # This needs to refer to memory, but we'll fill in the details
149 # later. It needs to take into account unaligned memory
150 # addresses.
151 print "%0"
153 elif opType.tag == "M":
154 # This needs to refer to memory, but we'll fill in the details
155 # later. It needs to take into account unaligned memory
156 # addresses.
157 print "%0"
158 Name += "_M"
152 elif opType.tag in ("PR", "R", "VR"):
153 # There should probably be a check here to verify that mod
154 # is equal to 11b
155 env.addReg(ModRMRMIndex)
159 elif opType.tag in ("PR", "R", "VR"):
160 # There should probably be a check here to verify that mod
161 # is equal to 11b
162 env.addReg(ModRMRMIndex)
163 Name += "_R"
156 else:
157 raise Exception, "Unrecognized tag %s." % opType.tag
158 opTypes.pop(0)
159
160 # Generate code to return a macroop of the given name which will
161 # operate in the "emulation environment" env
162 return genMacroop(Name, env)
163}};
164 else:
165 raise Exception, "Unrecognized tag %s." % opType.tag
166 opTypes.pop(0)
167
168 # Generate code to return a macroop of the given name which will
169 # operate in the "emulation environment" env
170 return genMacroop(Name, env)
171}};