ó
^c           @   s0   d  e  f d     YZ d e f d     YZ d S(   t   Instructionc           B   s  e  Z d d d   Z d   Z e d    Z e d d  Z d   Z	 e d    Z
 e d    Z e d    Z e d    Z e d	    Z e d
    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z d   Z d   Z d   Z e d    Z RS(   c         C   sĄ  t  t |   j   | |  _ d  |  _ d  |  _ d  |  _ | d  k	 r | d d |  _ | d d |  _ | d d d j   |  _ n3 | d  k	 rś | j |  _ | j |  _ | j |  _ n  d |  _	 t
   |  _ t
   |  _ d |  _ d |  _ d |  _ g  |  _ d  |  _ d  |  _ d  |  _ t   |  _ d  |  _ d  |  _ t |  _ | d  k rmt
   |  _ t
   |  _ d |  _ n0 | j j   |  _ | j j   |  _ | j |  _ d  S(	   Ni   i   i   i    (    (    (    (    (   t   superR    t   __init__t   namet   Nonet   line_numbert   source_filet   source_codet   stript   operandst   dictt   _implicit_in_regst   _implicit_out_regst   in_regst   out_regst   out_operandst	   encodingst   bytecodet	   _gas_namet   go_namet	   frozensett   isa_extensionst   mmx_modet   avx_modet   Falset   _cancelling_inputst   _available_registerst   _live_registerst   _indent_levelt   copy(   t   selfR   t   origint	   prototype(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR      sD    															c         C   sD   |  j  r3 t |  j  d d j t t |  j    St |  j  Sd  S(   Nt    s   , (   R	   t   strR   t   joint   map(   R   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   __str__/   s    	*c         C   s'   |  j  d  k r |  j j   S|  j  Sd  S(   N(   R   R   R   t   lower(   R   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   gas_name5   s    c            s  d d l  m  | r# d |  j n d }   d k rC | t |   S  d k r] | t |   S  d k r|  j rud d l m } | d  k	 r:t |  j  d	 k r:t	 |  j d
 |  r:|  j d
 j
 d  k	 r:|  j d
 } d j d | d |  j d |  j d
 j
 d t |  j d
  d |  j d
 j
 | k  r3d n d  S| |  j d d j    f d   t |  j  D  Sq| |  j Sn  d k r|  j r]d d l m } |  j d k r| |  j d	  r| t |  j  d d j    f d   |  j D  S|  j rI| t |  j  d d j    f d   t |  j  D  S| t |  j  Sq| d j t d   |  j     d t |   Sn  d  S(   Ni˙˙˙˙(   t   format_operands   	t    t   peachpyt   nasmt   gas(   t   Labeli   i    s9   {indent}{mnemonic} {label_line}{direction} # {label_name}t   indentt   mnemonict
   label_linet
   label_namet	   directiont   bt   fR!   s   , c         3   s   |  ] }  |    Vq d  S(   N(    (   t   .0t   op(   t   assembly_formatR(   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>O   s    t   go(   t   is_intt   CMPc         3   s   |  ] }  |    Vq d  S(   N(    (   R5   R6   (   R7   R(   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>X   s    c         3   s   |  ] }  |    Vq d  S(   N(    (   R5   R6   (   R7   R(   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>[   s    s   ; c         S   s   d |  S(   Ns   BYTE $0x%02X(    (   R3   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   <lambda>_   R)   s    // (   t   peachpy.x86_64.operandR(   R   R"   R	   t   peachpy.x86_64.pseudoR-   R   t   lent
   isinstanceR   t   formatR'   R#   t   reversedR   t   peachpy.utilR9   R   R$   t   encode(   R   R7   R.   R   t   textR-   t   labelR9   (    (   R7   R(   sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR@   <   s<    	M		#;	"$	*c         C   sH   |  j  rD | r d |  j n d } | d d j d   |  j  D  Sd  S(   Ns   	R)   s   # R!   c         s   s   |  ] } d  | Vq d S(   s   %02XN(    (   R5   t   byte(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>d   s    (   R   R   R#   (   R   R.   RD   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   format_encodinga   s    	c         C   sD   d d l  m } t   } x$ |  j D] } | j | |   q# W| S(   Ni˙˙˙˙(   t   get_operand_registers(   R<   RH   t   setR	   t   update(   R   RH   t	   registerst   operand(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyRK   f   s
    	c         C   s)   d d l  m } t t | |  j  g   S(   Ni˙˙˙˙(   RH   (   R<   RH   t   sumR$   R	   (   R   RH   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   register_objectsn   s    c         C   s    d d l  m } | j |  j  S(   Ni˙˙˙˙(   t   Register(   t   peachpy.x86_64.registersRO   t   _reconstruct_multipleR   (   R   RO   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   available_registerss   s    c         C   s    d d l  m } | j |  j  S(   Ni˙˙˙˙(   RO   (   RP   RO   RQ   R   (   R   RO   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   live_registersx   s    c         C   s    d d l  m } | j |  j  S(   Ni˙˙˙˙(   RO   (   RP   RO   RQ   t   input_registers_masks(   R   RO   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   input_registers}   s    c   	         sT  d d l  m } |  j rŃ d d l m   g  t |  j |  j  D] \ } } | r? | ^ q? } t |  d k s{ t	 d   t
 t   f d   |   sĽ t	 d   | d | d	 k rŔ t   Sd
   | D Sn |  j j   } xi t |  j |  j  D]R \ } } | rö x= | |  D], } | j } | j | d  | j B| | <qWqö qö W| Sd  S(   Ni˙˙˙˙(   RH   (   RO   i   s=   Instruction forms with cancelling inputs must have two inputsc            s   t  |     S(   N(   R?   (   R6   (   RO   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR;      R)   sH   Both inputs of instruction form with cancelling inputs must be registersi    i   c         S   s   i  |  ] } | j  | j  q S(    (   t   maskt   _internal_id(   R5   t   reg(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys
   <dictcomp>   s   	 (   R<   RH   R   RP   RO   t   zipR   R	   R>   t   AssertionErrort   allR$   R
   R   R   RW   t   getRV   (	   R   RH   t   is_input_regRL   t   input_operandst   registers_maskst   has_input_registerst   registert   register_id(    (   RO   sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyRT      s"    	4!	"	(c         C   s    d d l  m } | j |  j  S(   Ni˙˙˙˙(   RO   (   RP   RO   RQ   t   output_registers_masks(   R   RO   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   output_registers   s    c         C   sü   d d l  m } d d l m } m } m } m } |  j j   } x´ t	 |  j
 |  j  D] \ } } | rW x | |  D]w }	 |	 j }
 |	 j } | | j k rŠ | j } n* t |  j  rÓ | | j k rÓ | j } n  | j |
 d  | B| |
 <qv WqW qW W| S(   Ni˙˙˙˙(   RH   (   t   GeneralPurposeRegister32t   GeneralPurposeRegister64t   XMMRegistert   YMMRegisteri    (   R<   RH   RP   Re   Rf   Rg   Rh   R   R   RY   R   R	   RW   RV   t   _maskt   boolR   R\   (   R   RH   Re   Rf   Rg   Rh   R_   t   is_output_registerRL   Ra   Rb   t   register_mask(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyRc      s    ""		%c            sI   d d l  m  d d l m   t t    f d   |  j D  d   S(   Ni˙˙˙˙(   t   MemoryOperand(   t   Constantc         3   s9   |  ]/ } t  |   r t  | j    r | j Vq d  S(   N(   R?   t   symbol(   R5   RL   (   Rn   Rm   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>ľ   s    (   R<   Rm   t   peachpy.literalRn   t   nextt   iterR	   R   (   R   (    (   Rn   Rm   sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   constantą   s    "c            sI   d d l  m  d d l m   t t    f d   |  j D  d   S(   Ni˙˙˙˙(   Rm   (   t   LocalVariablec         3   s9   |  ]/ } t  |   r t  | j    r | j Vq d  S(   N(   R?   Ro   (   R5   RL   (   Rt   Rm   (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pys	   <genexpr>ź   s    (   R<   Rm   t   peachpy.x86_64.functionRt   Rq   Rr   R	   R   (   R   (    (   Rt   Rm   sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   local_variable¸   s    "c         C   sn   d d l  m } g  |  j D] } t | |  r | ^ q } | rj t |  d k s_ t d   | d j Sd  S(   Ni˙˙˙˙(   Rm   i   sD   x86-64 instructions can not have more than 1 explicit memory operandi    (   R<   Rm   R	   R?   R>   RZ   t   address(   R   Rm   RL   t   memory_operands(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   memory_addressż   s    +	c         C   sU   |  j    } | rJ g  | D] \ } } | |  j  ^ q } t | d t St   Sd  S(   Nt   key(   t   _filter_encodingsR	   t   minR>   t	   bytearray(   R   R   t   _t   encodingt	   bytecodes(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyRC   Č   s
    (c            sm   |  j  rb g  |  j   D] \ } } | |  j  ^ q } t t t |     t   f d   |  St   Sd  S(   Nc            s   t  |     k S(   N(   R>   (   R3   (   t
   min_length(    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR;   Ô   R)   (   R   R{   R	   R|   R$   R>   t   filterR}   (   R   R~   R   R   (    (   R   sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   encode_optionsĐ   s
    	.c   
   	   C   sš  d d l  m } m } i  } g  } x­|  j   D]\ } } d } | |  j  } | | j @d k rt | |  j d t  t |  k r | | j O} n  t | |  j d d  t |  k rŃ | | j	 O} n  t | |  j d d  t |  k r| | j
 O} qn  | | j @d k rXt | |  j d t  t |  k rX| | j O} qXn  | | j @d k rĽt | |  j d	 t  t |  k rĽ| | j O} qĽn  | j t |  |  | j | | f  q/ Wx | D] \ } } | | j	 @r | |  j d d }	 | j t |	  |	  n  | | j
 @rŮ| |  j d d }	 | j t |	  |	  qŮqŮWxĹ | D]˝ \ } } | | j @rf| |  j d t }	 | j t |	  |	  | | j	 @rĺ| |  j d d }	 | j t |	  |	  n  | | j
 @r#| |  j d d }	 | j t |	  |	  q#qfqfWxŃ | D]É \ } } | | j @r.| |  j d	 t }	 | j t |	  |	  | | j	 @rł| |  j d	 t d d }	 | j t |	  |	  n  | | j
 @r÷| |  j d	 t d d }	 | j t |	  |	  q÷q.q.Wxđ | D]č \ } } | | j @r| | j @r| |  j d	 t d t }	 | j t |	  |	  | | j	 @r | |  j d	 t d t d d }	 | j t |	  |	  n  | | j
 @rę| |  j d	 t d t d d }	 | j t |	  |	  qęqqWxŃ | D]É \ } } | | j @rő| |  j d t }	 | j t |	  |	  | | j	 @rz| |  j d t d d }	 | j t |	  |	  n  | | j
 @rž| |  j d t d d }	 | j t |	  |	  qžqőqőWxđ | D]č \ } } | | j @rÉ| | j @rÉ| |  j d t d t }	 | j t |	  |	  | | j	 @rg| |  j d t d t d d }	 | j t |	  |	  n  | | j
 @rą| |  j d t d t d d }	 | j t |	  |	  qąqÉqÉW| S(
   Ni˙˙˙˙(   t   Flagst   Optionsi    t   sibt   min_dispi   i   t   rext   vex3(   t   peachpy.x86_64.encodingR   R   R{   R	   t   ModRMSIBDispR>   t   Truet   SIBt   Disp8t   Disp32t   OptionalREXt   REXt   VEX2t   VEX3t
   setdefaultt   append(
   R   R   R   t   length_encoding_mapR   t   flagsRC   t   optionst   baselineR   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   encode_length_optionsŘ   s    '''''  !!  !! c         C   sË   g  } d d l  m } xŽ |  j D]Ł \ } } | | j @d k rn |  j d j d k rĂ | j | | f  qĂ q  | | j @d k r° |  j d j d k rĂ | j | | f  qĂ q  | j | | f  q  W| S(   Ni˙˙˙˙(   R   i    i   (   R   R   R   t   AccumulatorOp0R	   t   physical_idR   t   AccumulatorOp1(   R   R   R   R   R   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR{   4  s    c   
      C   sŽ  d d l  m } m } |  j rŞd d l m } |  j d k	 rŞi d d 6d d 6d d 6d	 d
 6} |  j d | k r | |  j d d } n´ d } |  j d d k rą | d 7} n  |  j | d @d k rŐ | d 7} n  |  j | d k rő | d 7} n  |  j | d k r5| d 7} |  j | d k r5| d 7} q5n  | d } |  j | } | d @} | d ?}	 | d k rx|	 d k st d   | | d | j	 d t
 |  j  Sn  d S(   s9  Returns relocation corresponding to encoding of this instruction of None if no relocation needed.
        Relocation offset and type variables are initialized, symbol variable needs to be initialized by the caller.
        Relocation offset specifies offset relative to the start of instruction encoding.
        i˙˙˙˙(   t
   Relocationt   RelocationType(   Rn   i   iĹ   i   iÄ   i   i   ib   i    i   if   iň   ió   iđ   i@   i   i8   i:   i   i   i   sE   Encoding must use rip-relative disp32 addressing, can't have SIB bytet   program_counterN(   if   iň   ió   (   if   iň   ió   (   i8   i:   (   t   peachpy.x86_64.metaR   R   R   Rp   Rn   Rs   R   RZ   t
   rip_disp32R>   (
   R   R   R   Rn   t   prefix_lengthst   mod_rm_positiont   decode_positiont   mod_rmt   rmt   mode(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt
   relocationB  s:    		




	N(   t   __name__t
   __module__R   R   R%   t   propertyR'   R   R@   RG   RK   RN   RR   RS   RU   RT   Rd   Rc   Rs   Rv   Ry   RC   R   R   R{   RŠ   (    (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR       s*   )	%					\	t   BranchInstructionc           B   s5   e  Z d d d   Z d e d  Z e d    Z RS(   c         C   s5   t  t |   j | d | d | | d k |  _ d  S(   NR   R    t   JMP(   R   R­   R   t   is_conditional(   R   R   R   R    (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR   y  s    "c         C   s{  | d  k r7 g  |  j D] \ } } | d  ^ q } nĐ g  } d d l m } d d l m } m }	 x |  j D]z \ }
 } | | t | d   } |
 | j @d k r˛ | |  sŃ |
 | j	 @d k rm |	 |  rm | j
 | |   qm qm W| st d |  j   n  t |  d k s%t d   t |  d k rEt | d f S| rat t | d	 t f St t | d	 t f Sd  S(
   Ni    i˙˙˙˙(   R   (   t   is_sint8t	   is_sint32s!   Can not encode offset to label %si   sO   At most 2 encodings expected for branch instructions with immediate code offseti   Rz   (   R   R   R   R   RB   R°   Rą   R>   t	   Rel8Labelt
   Rel32LabelR   t
   ValueErrorR1   RZ   R   t   maxR   R|   (   R   Rw   t   label_addresst   long_encodingR~   RC   R   R   R°   Rą   R   t   offset(    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   _encode_label_branch}  s$    +c         C   s8   d d l  m } t |  j d |  r4 |  j d j Sd  S(   Ni˙˙˙˙(   R-   i    (   R=   R-   R?   R	   R   (   R   R-   (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR1     s    N(   RŞ   RŤ   R   R   R   Rš   RŹ   R1   (    (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyR­   x  s   N(   t   objectR    R­   (    (    (    sH   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/instructions.pyt   <module>   s   ˙ t