Debian Codegraph @

rpython/jit/backend/x86/regloc.py

raw symbols SCIP
1 from rpython.jit.metainterp.history import ConstInt
2 from rpython.jit.backend.x86 import rx86
3 from rpython.rlib.unroll import unrolling_iterable
4 from rpython.jit.backend.x86.arch import WORD, IS_X86_32, IS_X86_64, WIN64
5 from rpython.tool.sourcetools import func_with_new_name
6 from rpython.rlib.objectmodel import specialize, instantiate
7 from rpython.rlib.rarithmetic import intmask, r_uint
8 from rpython.jit.metainterp.history import FLOAT, INT
9 from rpython.jit.codewriter import longlong
10 from rpython.rtyper.lltypesystem import rffi, lltype
11
12 #
13 # This module adds support for "locations", which can be either in a Const,
14 # or a RegLoc or a FrameLoc. It also adds operations like mc.ADD(), which
15 # take two locations as arguments, decode them, and calls the right
16 # mc.ADD_rr()/ADD_rb()/ADD_ri().
17 #
18
19 class AssemblerLocation(object):
20 _attrs_ = ('value', '_location_code')
21 _immutable_ = True
22 def _getregkey(self):
23 return self.value
24
25 def is_memory_reference(self):
26 return self.location_code() in ('b', 's', 'j', 'a', 'm')
27
28 def location_code(self):
29 return self._location_code
30
31 def get_width(self):
32 raise NotImplementedError
33
34 def value_r(self): return self.value
35 def value_b(self): return self.value
36 def value_s(self): return self.value
37 def value_j(self): return self.value
38 def value_i(self): return self.value
39 def value_x(self): return self.value
40 def value_a(self): raise AssertionError("value_a undefined")
41 def value_m(self): raise AssertionError("value_m undefined")
42
43 def find_unused_reg(self): return eax
44
45 def is_stack(self):
46 return False
47
48 def is_core_reg(self):
49 return False
50
51 def get_position(self):
52 raise NotImplementedError # only for stack
53
54 class RawEbpLoc(AssemblerLocation):
55 """ The same as stack location, but does not know it's position.
56 Mostly usable for raw frame access
57 """
58 _immutable_ = True
59 _location_code = 'b'
60
61 def __init__(self, value, type=INT):
62 self.value = value
63 self.type = type
64
65 def get_width(self):
66 if self.type == FLOAT:
67 return 8
68 return WORD
69
70 def __repr__(self):
71 return '%d(%%ebp)' % (self.value,)
72
73 def assembler(self):
74 return repr(self)
75
76 def is_float(self):
77 return self.type == FLOAT
78
79 def add_offset(self, ofs):
80 return RawEbpLoc(self.value + ofs)
81
82 def is_stack(self):
83 return True
84
85 class RawEspLoc(AssemblerLocation):
86 """ Esp-based location
87 """
88 _immutable_ = True
89 _location_code = 's'
90
91 def __init__(self, value, type):
92 assert value >= 0 # accessing values < 0 is forbidden on x86-32.
93 self.value = value # (on x86-64 we could allow values down to -128)
94 self.type = type
95
96 def _getregkey(self):
97 return ~self.value
98
99 def get_width(self):
100 if self.type == FLOAT:
101 return 8
102 return WORD
103
104 def __repr__(self):
105 return '%d(%%esp)' % (self.value,)
106
107 def assembler(self):
108 return repr(self)
109
110 def is_float(self):
111 return self.type == FLOAT
112
113 class FrameLoc(RawEbpLoc):
114 _immutable_ = True
115
116 def __init__(self, position, ebp_offset, type):
117 # _getregkey() returns self.value; the value returned must not
118 # conflict with RegLoc._getregkey(). It doesn't a bit by chance,
119 # so let it fail the following assert if it no longer does.
120 assert ebp_offset >= 8 + 8 * IS_X86_64
121 self.position = position
122 #if position != 9999:
123 # assert (position + JITFRAME_FIXED_SIZE) * WORD == ebp_offset
124 self.value = ebp_offset
125 # One of INT, REF, FLOAT
126 self.type = type
127
128 def get_position(self):
129 return self.position
130
131 class RegLoc(AssemblerLocation):
132 _immutable_ = True
133 def __init__(self, regnum, is_xmm):
134 assert regnum >= 0
135 self.value = regnum
136 self.is_xmm = is_xmm
137 if self.is_xmm:
138 self._location_code = 'x'
139 else:
140 self._location_code = 'r'
141 def __repr__(self):
142 if self.is_xmm:
143 return rx86.R.xmmnames[self.value]
144 else:
145 return rx86.R.names[self.value]
146
147 def get_width(self):
148 if self.is_xmm:
149 return 8
150 return WORD
151
152 def lowest8bits(self):
153 assert not self.is_xmm
154 if WORD == 4:
155 assert 0 <= self.value < 4
156 return RegLoc(rx86.low_byte(self.value), False)
157
158 def higher8bits(self):
159 assert not self.is_xmm
160 return RegLoc(rx86.high_byte(self.value), False)
161
162 def assembler(self):
163 return '%' + repr(self)
164
165 def find_unused_reg(self):
166 if self.value == eax.value:
167 return edx
168 else:
169 return eax
170
171 def is_float(self):
172 return self.is_xmm
173
174 def is_core_reg(self):
175 return True
176
177 class ImmediateAssemblerLocation(AssemblerLocation):
178 _immutable_ = True
179
180 class ImmedLoc(ImmediateAssemblerLocation):
181 _immutable_ = True
182 _location_code = 'i'
183
184 def __init__(self, value, is_float=False):
185 # force as a real int
186 self.value = rffi.cast(lltype.Signed, value)
187 self._is_float = is_float
188
189 def getint(self):
190 return self.value
191
192 def get_width(self):
193 return WORD
194
195 def __repr__(self):
196 return "ImmedLoc(%d)" % (self.value)
197
198 def lowest8bits(self):
199 val = self.value & 0xFF
200 if val > 0x7F:
201 val -= 0x100
202 return ImmedLoc(val)
203
204 def is_float(self):
205 return self._is_float
206
207 class AddressLoc(AssemblerLocation):
208 _immutable_ = True
209
210 # The address is base_loc + (scaled_loc << scale) + static_offset
211 def __init__(self, base_loc, scaled_loc, scale=0, static_offset=0):
212 assert 0 <= scale < 4
213 assert isinstance(base_loc, ImmedLoc) or isinstance(base_loc, RegLoc)
214 assert isinstance(scaled_loc, ImmedLoc) or isinstance(scaled_loc, RegLoc)
215
216 if isinstance(base_loc, ImmedLoc):
217 if isinstance(scaled_loc, ImmedLoc):
218 self._location_code = 'j'
219 self.value = base_loc.value + (scaled_loc.value << scale) + static_offset
220 else:
221 self._location_code = 'a'
222 self.loc_a = (rx86.NO_BASE_REGISTER, scaled_loc.value, scale, base_loc.value + static_offset)
223 else:
224 if isinstance(scaled_loc, ImmedLoc):
225 # FIXME: What if base_loc is ebp or esp?
226 self._location_code = 'm'
227 self.loc_m = (base_loc.value, (scaled_loc.value << scale) + static_offset)
228 else:
229 self._location_code = 'a'
230 self.loc_a = (base_loc.value, scaled_loc.value, scale, static_offset)
231
232 def __repr__(self):
233 dict = {'j': 'value', 'a': 'loc_a', 'm': 'loc_m', 'a':'loc_a'}
234 attr = dict.get(self._location_code, '?')
235 info = getattr(self, attr, '?')
236 return '<AddressLoc %r: %s>' % (self._location_code, info)
237
238 def get_width(self):
239 return WORD
240
241 def is_float(self):
242 return False # not 100% true, but we don't use AddressLoc for locations
243 # really, so it's ok
244
245 def value_a(self):
246 return self.loc_a
247
248 def value_m(self):
249 return self.loc_m
250
251 def find_unused_reg(self):
252 if self._location_code == 'm':
253 if self.loc_m[0] == eax.value:
254 return edx
255 elif self._location_code == 'a':
256 if self.loc_a[0] == eax.value:
257 if self.loc_a[1] == edx.value:
258 return ecx
259 return edx
260 if self.loc_a[1] == eax.value:
261 if self.loc_a[0] == edx.value:
262 return ecx
263 return edx
264 return eax
265
266 def add_offset(self, ofs):
267 result = instantiate(AddressLoc)
268 result._location_code = self._location_code
269 if self._location_code == 'm':
270 result.loc_m = (self.loc_m[0], self.loc_m[1] + ofs)
271 elif self._location_code == 'a':
272 result.loc_a = self.loc_a[:3] + (self.loc_a[3] + ofs,)
273 elif self._location_code == 'j':
274 result.value = self.value + ofs
275 else:
276 raise AssertionError(self._location_code)
277 return result
278
279 class ConstFloatLoc(ImmediateAssemblerLocation):
280 _immutable_ = True
281 _location_code = 'j'
282
283 def __init__(self, address):
284 self.value = address
285
286 def get_width(self):
287 return 8
288
289 def __repr__(self):
290 return '<ConstFloatLoc @%s>' % (self.value,)
291
292 def is_float(self):
293 return True
294
295 if IS_X86_32:
296 class FloatImmedLoc(ImmediateAssemblerLocation):
297 # This stands for an immediate float. It cannot be directly used in
298 # any assembler instruction. Instead, it is meant to be decomposed
299 # in two 32-bit halves. On 64-bit, FloatImmedLoc() is a function
300 # instead; see below.
301 _immutable_ = True
302 _location_code = '#' # don't use me
303
304 def __init__(self, floatstorage):
305 self.aslonglong = floatstorage
306
307 def get_width(self):
308 return 8
309
310 def low_part(self):
311 return intmask(self.aslonglong)
312
313 def high_part(self):
314 return intmask(self.aslonglong >> 32)
315
316 def low_part_loc(self):
317 return ImmedLoc(self.low_part())
318
319 def high_part_loc(self):
320 return ImmedLoc(self.high_part())
321
322 def __repr__(self):
323 floatvalue = longlong.getrealfloat(self.aslonglong)
324 return '<FloatImmedLoc(%s)>' % (floatvalue,)
325
326 def is_float(self):
327 return True
328
329 if IS_X86_64:
330 def FloatImmedLoc(floatstorage):
331 from rpython.rlib.longlong2float import float2longlong
332 value = intmask(float2longlong(floatstorage))
333 return ImmedLoc(value, True)
334
335
336 REGLOCS = [RegLoc(i, is_xmm=False) for i in range(16)]
337 XMMREGLOCS = [RegLoc(i, is_xmm=True) for i in range(16)]
338 eax, ecx, edx, ebx, esp, ebp, esi, edi, r8, r9, r10, r11, r12, r13, r14, r15 = REGLOCS
339 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 = XMMREGLOCS
340
341 # We use a scratch register to simulate having 64-bit immediates. When we
342 # want to do something like:
343 # mov rax, [0xDEADBEEFDEADBEEF]
344 # we actually do:
345 # mov r11, 0xDEADBEEFDEADBEEF
346 # mov rax, [r11]
347 #
348 # NB: You can use the scratch register as a temporary register in
349 # assembler.py, but care must be taken when doing so. A call to a method in
350 # LocationCodeBuilder could clobber the scratch register when certain
351 # location types are passed in.
352 X86_64_SCRATCH_REG = r11
353
354 # XXX: a GPR scratch register is definitely needed, but we could probably do
355 # without an xmm scratch reg.
356 if WIN64:
357 X86_64_XMM_SCRATCH_REG = xmm5
358 else:
359 X86_64_XMM_SCRATCH_REG = xmm15
360
361 # note: 'r' is after 'i' in this list, for _binaryop()
362 unrolling_location_codes = unrolling_iterable(list("irbsmajx"))
363
364 @specialize.arg(1)
365 def _rx86_getattr(obj, methname):
366 if hasattr(rx86.AbstractX86CodeBuilder, methname):
367 return getattr(obj, methname)
368 else:
369 raise AssertionError(methname + " undefined")
370
371 def _missing_binary_insn(name, code1, code2):
372 raise AssertionError(name + "_" + code1 + code2 + " missing")
373 _missing_binary_insn._dont_inline_ = True
374
375
376 class LocationCodeBuilder(object):
377 _mixin_ = True
378
379 _scratch_register_value = -1 # -1 means 'unknown'
380
381 def _binaryop(name):
382
383 def insn_with_64_bit_immediate(self, loc1, loc2):
384 # These are the worst cases:
385 val2 = loc2.value_i()
386 if name == 'MOV' and isinstance(loc1, RegLoc):
387 self.MOV_ri(loc1.value, val2)
388 return True
389 code1 = loc1.location_code()
390 if code1 == 'j':
391 checkvalue = loc1.value_j()
392 elif code1 == 'm':
393 checkvalue = loc1.value_m()[1]
394 elif code1 == 'a':
395 checkvalue = loc1.value_a()[3]
396 else:
397 checkvalue = 0
398 if not rx86.fits_in_32bits(checkvalue):
399 # INSN_ji, and both operands are 64-bit; or INSN_mi or INSN_ai
400 # and the constant offset in the address is 64-bit.
401 # Hopefully this doesn't happen too often
402 freereg = loc1.find_unused_reg()
403 self.PUSH_r(freereg.value)
404 self.MOV_ri(freereg.value, val2)
405 INSN(self, loc1, freereg)
406 self.POP_r(freereg.value)
407 return True
408 else:
409 # For this case, we should not need the scratch register more than here.
410 self._load_scratch(val2)
411 return False
412
413 def invoke(self, codes, val1, val2):
414 methname = name + "_" + codes
415 _rx86_getattr(self, methname)(val1, val2)
416 invoke._annspecialcase_ = 'specialize:arg(1)'
417
418 def has_implementation_for(loc1, loc2):
419 # A memo function that returns True if there is any NAME_xy that could match.
420 # If it returns False we know the whole subcase can be omitted from translated
421 # code. Without this hack, the size of most _binaryop INSN functions ends up
422 # quite large in C code.
423 if loc1 == '?':
424 return any([has_implementation_for(loc1, loc2)
425 for loc1 in unrolling_location_codes])
426 methname = name + "_" + loc1 + loc2
427 if not hasattr(rx86.AbstractX86CodeBuilder, methname):
428 return False
429 # any NAME_j should have a NAME_m as a fallback, too. Check it
430 if loc1 == 'j': assert has_implementation_for('m', loc2), methname
431 if loc2 == 'j': assert has_implementation_for(loc1, 'm'), methname
432 return True
433 has_implementation_for._annspecialcase_ = 'specialize:memo'
434
435 def INSN(self, loc1, loc2):
436 code1 = loc1.location_code()
437 code2 = loc2.location_code()
438
439 # You cannot pass in the scratch register as a location,
440 # except with a MOV instruction.
441 if name.startswith('MOV'):
442 if loc2 is X86_64_SCRATCH_REG:
443 assert code1 != 'j' and code1 != 'm' and code1 != 'a'
444 if loc1 is X86_64_SCRATCH_REG:
445 self.forget_scratch_register()
446 elif loc1 is X86_64_SCRATCH_REG or loc2 is X86_64_SCRATCH_REG:
447 raise AssertionError("%s with scratch reg specified" % name)
448
449 for possible_code2 in unrolling_location_codes:
450 if not has_implementation_for('?', possible_code2):
451 continue
452 if code2 == possible_code2:
453 val2 = getattr(loc2, "value_" + possible_code2)()
454 #
455 # Fake out certain operations for x86_64
456 if self.WORD == 8 and possible_code2 == 'i' and not rx86.fits_in_32bits(val2):
457 if insn_with_64_bit_immediate(self, loc1, loc2):
458 return # done
459 loc2 = X86_64_SCRATCH_REG
460 code2 = 'r'
461 # NB. unrolling_location_codes contains 'r'
462 # after 'i', so that it will be found after
463 # this iteration
464 continue
465 #
466 # Regular case
467 for possible_code1 in unrolling_location_codes:
468 if not has_implementation_for(possible_code1,
469 possible_code2):
470 continue
471 if code1 == possible_code1:
472 val1 = getattr(loc1, "value_" + possible_code1)()
473 # More faking out of certain operations for x86_64
474 fits32 = rx86.fits_in_32bits
475 if possible_code1 == 'j' and not fits32(val1):
476 val1 = self._addr_as_reg_offset(val1)
477 invoke(self, "m" + possible_code2, val1, val2)
478 return
479 if possible_code2 == 'j' and not fits32(val2):
480 val2 = self._addr_as_reg_offset(val2)
481 invoke(self, possible_code1 + "m", val1, val2)
482 return
483 if possible_code1 == 'm' and not fits32(val1[1]):
484 val1 = self._fix_static_offset_64_m(val1)
485 if possible_code2 == 'm' and not fits32(val2[1]):
486 val2 = self._fix_static_offset_64_m(val2)
487 if possible_code1 == 'a' and not fits32(val1[3]):
488 val1 = self._fix_static_offset_64_a(val1)
489 if possible_code2 == 'a' and not fits32(val2[3]):
490 val2 = self._fix_static_offset_64_a(val2)
491 invoke(self, possible_code1 + possible_code2, val1, val2)
492 return
493 _missing_binary_insn(name, code1, code2)
494
495 return func_with_new_name(INSN, "INSN_" + name)
496
497 def _unaryop(name):
498 def INSN(self, loc):
499 if loc is X86_64_SCRATCH_REG:
500 raise AssertionError("%s with scratch reg specified" % name)
501
502 code = loc.location_code()
503 for possible_code in unrolling_location_codes:
504 if code == possible_code:
505 val = getattr(loc, "value_" + possible_code)()
506 # Faking out of certain operations for x86_64
507 fits32 = rx86.fits_in_32bits
508 if possible_code == 'i' and not fits32(val):
509 self._load_scratch(val) # for 'PUSH(imm)'
510 _rx86_getattr(self, name + "_r")(X86_64_SCRATCH_REG.value)
511 return
512 if possible_code == 'j' and not fits32(val):
513 val = self._addr_as_reg_offset(val)
514 _rx86_getattr(self, name + "_m")(val)
515 return
516 if possible_code == 'm' and not fits32(val[1]):
517 val = self._fix_static_offset_64_m(val)
518 if possible_code == 'a' and not fits32(val[3]):
519 val = self._fix_static_offset_64_a(val)
520 methname = name + "_" + possible_code
521 _rx86_getattr(self, methname)(val)
522
523 return func_with_new_name(INSN, "INSN_" + name)
524
525 def _relative_unaryop(name):
526 def INSN(self, loc):
527 code = loc.location_code()
528 for possible_code in unrolling_location_codes:
529 if code == possible_code:
530 val = getattr(loc, "value_" + possible_code)()
531 if possible_code == 'i':
532 # This is for CALL or JMP only.
533 if self.WORD == 4:
534 _rx86_getattr(self, name + "_l")(val)
535 self.add_pending_relocation()
536 else:
537 # xxx can we avoid "MOV r11, $val; JMP/CALL *r11"
538 # in case it would fit a 32-bit displacement?
539 # Hard, because we don't know yet where this insn
540 # will end up...
541 assert self.WORD == 8
542 self._load_scratch(val)
543 _rx86_getattr(self, name + "_r")(X86_64_SCRATCH_REG.value)
544 else:
545 methname = name + "_" + possible_code
546 _rx86_getattr(self, methname)(val)
547 # This is for CALL and JMP, so it's correct to forget
548 # the value of the R11 register here.
549 self.forget_scratch_register()
550
551 return func_with_new_name(INSN, "INSN_" + name)
552
553 def _addr_as_reg_offset(self, addr):
554 # Encodes a (64-bit) address as an offset from the scratch register.
555 # If we are within a "reuse_scratch_register" block, we remember the
556 # last value we loaded to the scratch register and encode the address
557 # as an offset from that if we can
558 if self._scratch_register_value != -1:
559 offset = r_uint(addr) - r_uint(self._scratch_register_value)
560 offset = intmask(offset)
561 if rx86.fits_in_32bits(offset):
562 #print '_addr_as_reg_offset(%x) [REUSED r11+%d]' % (
563 # addr, offset)
564 return (X86_64_SCRATCH_REG.value, offset)
565 #print '_addr_as_reg_offset(%x) [too far]' % (addr,)
566 # else: fall through
567 #else:
568 # print('_addr_as_reg_offset(%x) [new]' % (addr,))
569 self._scratch_register_value = addr
570 self.MOV_ri(X86_64_SCRATCH_REG.value, addr)
571 return (X86_64_SCRATCH_REG.value, 0)
572
573 def _fix_static_offset_64_m(self, (basereg, static_offset)):
574 # For cases where an AddressLoc has the location_code 'm', but
575 # where the static offset does not fit in 32-bits. We have to fall
576 # back to the X86_64_SCRATCH_REG. Returns a new location encoded
577 # as mode 'm' too. These are all possibly rare cases.
578 reg, ofs = self._addr_as_reg_offset(static_offset)
579 self.forget_scratch_register()
580 self.LEA_ra(X86_64_SCRATCH_REG.value, (basereg, reg, 0, ofs))
581 return (X86_64_SCRATCH_REG.value, 0)
582
583 def _fix_static_offset_64_a(self, (basereg, scalereg,
584 scale, static_offset)):
585 # For cases where an AddressLoc has the location_code 'a', but
586 # where the static offset does not fit in 32-bits. We have to fall
587 # back to the X86_64_SCRATCH_REG. In one case it is even more
588 # annoying. These are all possibly rare cases.
589 reg, ofs = self._addr_as_reg_offset(static_offset)
590 #
591 if basereg != rx86.NO_BASE_REGISTER:
592 self.forget_scratch_register()
593 self.LEA_ra(X86_64_SCRATCH_REG.value, (basereg, reg, 0, ofs))
594 reg = X86_64_SCRATCH_REG.value
595 ofs = 0
596 return (reg, scalereg, scale, ofs)
597
598 def _load_scratch(self, value):
599 if self._scratch_register_value != -1:
600 if self._scratch_register_value == value:
601 #print '_load_scratch(%x) [REUSED]' % (value,)
602 return
603 offset = r_uint(value) - r_uint(self._scratch_register_value)
604 offset = intmask(offset)
605 if rx86.fits_in_32bits(offset):
606 #print '_load_scratch(%x) [LEA r11+%d]' % (value, offset)
607 #global COUNT_
608 #try:
609 # COUNT_ += 1
610 #except NameError:
611 # COUNT_ = 1
612 #if COUNT_ % 182 == 0:
613 # import pdb;pdb.set_trace()
614 self.LEA_rm(X86_64_SCRATCH_REG.value,
615 (X86_64_SCRATCH_REG.value, offset))
616 self._scratch_register_value = value
617 return
618 #print '_load_scratch(%x) [too far]' % (value,)
619 #else:
620 # print('_load_scratch(%x) [new]' % (value,))
621 self._scratch_register_value = value
622 self.MOV_ri(X86_64_SCRATCH_REG.value, value)
623
624 def forget_scratch_register(self):
625 self._scratch_register_value = -1
626
627 def get_scratch_register_known_value(self):
628 return self._scratch_register_value
629
630 def restore_scratch_register_known_value(self, saved_value):
631 self._scratch_register_value = saved_value
632
633 def load_scratch_if_known(self, saved_value):
634 if saved_value != -1:
635 assert IS_X86_64
636 self._load_scratch(saved_value)
637
638 def trap(self):
639 self.INT3()
640
641 def _vector_size_choose(name):
642 def invoke(self, suffix, val1, val2):
643 methname = name + suffix
644 _rx86_getattr(self, methname)(val1, val2)
645 invoke._annspecialcase_ = 'specialize:arg(1)'
646
647 possible_instr_unrolled = unrolling_iterable([(1,'B_xx'),(2,'W_xx'),(4,'D_xx'),(8,'Q_xx')])
648
649 def INSN(self, loc1, loc2, size):
650 code1 = loc1.location_code()
651 code2 = loc2.location_code()
652 assert code1 == code2 == 'x'
653 val1 = loc1.value_x()
654 val2 = loc2.value_x()
655 for s,suffix in possible_instr_unrolled:
656 if s == size:
657 invoke(self, suffix, val1, val2)
658 break
659
660 return INSN
661
662 AND = _binaryop('AND')
663 OR = _binaryop('OR')
664 OR8 = _binaryop('OR8')
665 XOR = _binaryop('XOR')
666 NOT = _unaryop('NOT')
667 SHL = _binaryop('SHL')
668 SHR = _binaryop('SHR')
669 SAR = _binaryop('SAR')
670 TEST = _binaryop('TEST')
671 PTEST = _binaryop('PTEST')
672 TEST8 = _binaryop('TEST8')
673 BTS = _binaryop('BTS')
674
675 INC = _unaryop('INC')
676 ADD = _binaryop('ADD')
677 SUB = _binaryop('SUB')
678 IMUL = _binaryop('IMUL')
679 NEG = _unaryop('NEG')
680 MUL = _unaryop('MUL')
681
682 CMP = _binaryop('CMP')
683 CMP16 = _binaryop('CMP16')
684 PCMPEQQ = _binaryop('PCMPEQQ')
685 PCMPEQD = _binaryop('PCMPEQD')
686 PCMPEQW = _binaryop('PCMPEQW')
687 PCMPEQB = _binaryop('PCMPEQB')
688 PCMPEQ = _vector_size_choose('PCMPEQ')
689 MOV = _binaryop('MOV')
690 MOV8 = _binaryop('MOV8')
691 MOV16 = _binaryop('MOV16')
692 MOVZX8 = _binaryop('MOVZX8')
693 MOVSX8 = _binaryop('MOVSX8')
694 MOVZX16 = _binaryop('MOVZX16')
695 MOVSX16 = _binaryop('MOVSX16')
696 MOV32 = _binaryop('MOV32')
697 MOVSX32 = _binaryop('MOVSX32')
698 # Avoid XCHG because it always implies atomic semantics, which is
699 # slower and does not pair well for dispatch.
700 #XCHG = _binaryop('XCHG')
701 CMOVNS = _binaryop('CMOVNS')
702
703 PUSH = _unaryop('PUSH')
704 POP = _unaryop('POP')
705
706 LEA = _binaryop('LEA')
707
708 MOVSD = _binaryop('MOVSD')
709 MOVSS = _binaryop('MOVSS')
710 MOVAPD = _binaryop('MOVAPD')
711 MOVAPS = _binaryop('MOVAPS')
712 MOVDQA = _binaryop('MOVDQA')
713 MOVDQU = _binaryop('MOVDQU')
714 MOVUPD = _binaryop('MOVUPD')
715 MOVUPS = _binaryop('MOVUPS')
716 ADDSD = _binaryop('ADDSD')
717 SUBSD = _binaryop('SUBSD')
718 MULSD = _binaryop('MULSD')
719 DIVSD = _binaryop('DIVSD')
720
721 # packed
722 ADDPD = _binaryop('ADDPD')
723 ADDPS = _binaryop('ADDPS')
724 SUBPD = _binaryop('SUBPD')
725 SUBPS = _binaryop('SUBPS')
726 MULPD = _binaryop('MULPD')
727 MULPS = _binaryop('MULPS')
728 DIVPD = _binaryop('DIVPD')
729 DIVPS = _binaryop('DIVPS')
730
731 UCOMISD = _binaryop('UCOMISD')
732 CVTSI2SD = _binaryop('CVTSI2SD')
733 CVTTSD2SI = _binaryop('CVTTSD2SI')
734 CVTSD2SS = _binaryop('CVTSD2SS')
735 CVTSS2SD = _binaryop('CVTSS2SD')
736 CVTPD2PS = _binaryop('CVTPD2PS')
737 CVTPS2PD = _binaryop('CVTPS2PD')
738 CVTPD2DQ = _binaryop('CVTPD2DQ')
739 CVTDQ2PD = _binaryop('CVTDQ2PD')
740
741 SQRTSD = _binaryop('SQRTSD')
742
743 ANDPD = _binaryop('ANDPD')
744 ANDPS = _binaryop('ANDPS')
745 XORPD = _binaryop('XORPD')
746 XORPS = _binaryop('XORPS')
747
748 PADDQ = _binaryop('PADDQ')
749 PADDD = _binaryop('PADDD')
750 PHADDD = _binaryop('PHADDD')
751 PADDW = _binaryop('PADDW')
752 PADDB = _binaryop('PADDB')
753
754 PSUBQ = _binaryop('PSUBQ')
755 PSUBD = _binaryop('PSUBD')
756 PSUBW = _binaryop('PSUBW')
757 PSUBB = _binaryop('PSUBB')
758
759 PMULDQ = _binaryop('PMULDQ')
760 PMULLD = _binaryop('PMULLD')
761 PMULLW = _binaryop('PMULLW')
762
763 PAND = _binaryop('PAND')
764 POR = _binaryop('POR')
765 PXOR = _binaryop('PXOR')
766 PSRLDQ = _binaryop('PSRLDQ')
767
768 MOVDQ = _binaryop('MOVDQ')
769 MOVD32 = _binaryop('MOVD32')
770 MOVUPS = _binaryop('MOVUPS')
771 MOVDDUP = _binaryop('MOVDDUP')
772
773 UNPCKHPD = _binaryop('UNPCKHPD')
774 UNPCKLPD = _binaryop('UNPCKLPD')
775 UNPCKHPS = _binaryop('UNPCKHPS')
776 UNPCKLPS = _binaryop('UNPCKLPS')
777
778 PUNPCKLQDQ = _binaryop('PUNPCKLQDQ')
779 PUNPCKHQDQ = _binaryop('PUNPCKHQDQ')
780 PUNPCKLDQ = _binaryop('PUNPCKLDQ')
781 PUNPCKHDQ = _binaryop('PUNPCKHDQ')
782
783 PSHUFB = _binaryop('PSHUFB')
784
785 HADDPD = _binaryop('HADDPD')
786 HADDPS = _binaryop('HADDPS')
787
788 CALL = _relative_unaryop('CALL')
789 JMP = _relative_unaryop('JMP')
790
791 def imm(x):
792 # XXX: ri386 migration shim
793 if isinstance(x, ConstInt):
794 return ImmedLoc(x.getint())
795 else:
796 return ImmedLoc(x)
797
798 imm0 = imm(0)
799 imm1 = imm(1)
800
801 all_extra_instructions = [name for name in LocationCodeBuilder.__dict__
802 if name[0].isupper()]
803 all_extra_instructions.sort()