ó
™^c           @  s;  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z d  d l
 Z d  d l Z d  d l Z d  d l Z d  d l Z d f  d „  ƒ  YZ d e j f d „  ƒ  YZ d f  d „  ƒ  YZ d	 f  d
 „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functionNt   Functionc           B  s:  e  Z d  Z e e e e d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z e d	 „  ƒ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e  j! d „ Z" e  j! d „ Z# RS(   sT  Generalized x86-64 assembly function.

    A function consists of C signature and a list of instructions.

    On this level the function is supposed to be compatible with multiple ABIs. In particular, instructions may have
    virtual registers, and instruction stream may contain pseudo-instructions, such as LOAD.ARGUMENT or RETURN.
    c         C  sy  | |  _  | |  _ | |  _ | d k r< t j j j |  _ n  | |  _ | d k rc t j j j } n  | d k r� t j j	 j
 } n  t | t j j	 j ƒ s² t d t | ƒ ƒ ‚ n  | |  _ | d k rÜ t j j j |  _ n t | ƒ |  _ d d l m } d d l m } | | d d ƒ f ƒ |  _ d |  _ t ƒ  |  _ t ƒ  |  _ t ƒ  |  _ t j  j d ƒ |  _ d |  _ d |  _  d |  _! d |  _" d |  _# d d l$ m% }	 m& }
 m' } |	 |
 | g } t( g  |  j D] } | j) | k ^ qÍƒ p÷|  j | k |  _* d |  _+ d d	 l, m- } m. } m/ } m0 } d d
 l1 m2 } i | ƒ  | j3 6| ƒ  | j3 6| ƒ  | j3 6| ƒ  | j3 6|  _4 d S(   s"  
        :param str name: name of the function without mangling (as in C language).
        :param tuple arguments: a tuple of :class:`peachpy.Argument` objects.
        :param Type result_type: the return type of the function. None if the function returns no value (void function).
        :param str package: the name of the Go package containing this function.
        :param Microarchitecture target: the target microarchitecture for this function.
        :param int debug_level: the verbosity level for debug information collected for instructions. 0 means no
            debug information, 1 and above enables information about the lines of Python code that originated an
            instruction. Collecting debug information increases processing time by several times.
        :ivar Label entry: a label that marks the entry point of the function. A user can place the entry point in any
            place in the function by defining this label with LABEL pseudo-instruction. If this label is not defined
            by the user, it will be placed automatically before the first instruction of the function.

        :ivar int _indent_level: the level of indentation for this instruction in assembly listings. Indentation level
            is changed by Loop statements.
        :ivar list _instructions: the list of :class:`Instruction` objects that comprise the function code.

        :ivar set _label_names: a set of string names of LABEL quasi-instructions in the function. The set is populated
            as instructions are added and is intended to track duplicate labels.

        :ivar dict _named_constants: a dictionary that maps names of literal constants to Constant objects.
            As instructions are added the dictionary is used to track constants with same names, but different content.
        s   %s is not an valid CPU targetiÿÿÿÿ(   t   Label(   t   Namet	   __entry__i   i    (   t   m256t   m256dt   m256i(   t   GeneralPurposeRegistert   MMXRegistert   XMMRegistert	   KRegister(   t   RegisterAllocatorN(5   t   namet	   argumentst   result_typet   Nonet   peachpyt   x86_64t   optionst   packaget   targett   uarcht   defaultt
   isinstancet   Microarchitecturet	   TypeErrort   strt   debug_levelt   intt   peachpy.x86_64.pseudoR   t   peachpy.nameR   t   entryt   _indent_levelt   listt   _instructionst   sett   _label_namest   dictt   _names_memot	   Namespacet   _scopet   _local_variables_countt(   _virtual_general_purpose_registers_countt   _virtual_mmx_registers_countt   _virtual_xmm_registers_countt   _virtual_mask_registers_countt   peachpy.x86_64R   R   R   t   anyt   c_typet   avx_environmentt   _avx_prologt   peachpy.x86_64.registersR   R	   R
   R   t   peachpy.commonR   t   _kindt   _register_allocators(   t   selfR   R   R   R   R   R   R   R   R   R   R   t	   avx_typest   argR   R	   R
   R   R   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __init__   sP    											=	"c         C  s`   |  j  d k r d n t |  j  ƒ } | d |  j } | d d j t t |  j ƒ ƒ d } | S(   s8   C signature (including parameter names) for the functiont   voidt    t   (s   , t   )N(   R   R   R   R   t   joint   mapR   (   R8   t	   signature(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   c_signaturen   s    $'c           së   ‡  f d †  ‰  t  t ˆ  t t j d ƒ |  j ƒ ƒ ƒ } t t t | ƒ ƒ sR d St d „  t t t j d ƒ |  j ƒ | ƒ ƒ } |  j	 d k r« d |  j
 d j | ƒ f Sˆ  |  j	 ƒ } | d k rÊ d Sd |  j
 d j | ƒ | f Sd S(	   sˆ   Go signature (including parameter names) for the function.

        None if the function argument or return type is incompatible with Goc           sù   t  |  t j ƒ s t ‚ |  j rH |  j d  k	 rA d ˆ  |  j ƒ Sd Sn­ |  j rU d S|  j ro |  j	 rk d Sd S|  j	 rŸ i d d 6d d	 6d
 d 6d d 6|  j
 S|  j rÏ i d d 6d d	 6d d 6d d 6|  j
 S|  j rñ i d d 6d d 6|  j
 Sd  Sd  S(   Nt   *t   uintptrt   booleanR   t   uintt   int8i   t   int16i   t   int32i   t   int64i   t   uint8t   uint16t   uint32t   uint64t   float32t   float64(   R   R   t   Typet   AssertionErrort
   is_pointert   baseR   t   is_boolt   is_size_integert   is_signed_integert   sizet   is_unsigned_integert   is_floating_point(   R1   (   t   c_to_go_type(    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR\   }   s:    						R1   c         S  s   d j  |  ƒ S(   NR=   (   R@   (   t   name_gotype(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   <lambda>£   t    R   s   func %s(%s)s   , s   func %s(%s) %sN(   R"   RA   t   operatort
   attrgetterR   t   allt   boolR   t   zipR   R   R@   (   R8   t   go_argument_typest   go_argumentst   go_result_type(    (   R\   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   go_signaturew   s    !*	'c         C  sG   d d l  m } t ƒ  } x! |  j D] } | j | j ƒ q# W| | Œ  S(   Niÿÿÿÿ(   t
   Extensions(   t   peachpy.x86_64.isaRi   R$   R#   t   updatet   isa_extensions(   R8   Ri   t
   extensionst   instruction(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRl   ®   s
    	c         C  s   |  j  ƒ  |  S(   N(   t   attach(   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt	   __enter__¶   s    
c         C  sõ   |  j  ƒ  | d  k rî |  j ƒ  |  j ƒ  |  j ƒ  |  j ƒ  t j j j	 rl t j j j	 j
 |  j ƒ  ƒ n  |  j ƒ  |  j ƒ  |  j ƒ  |  j j ƒ  t j j j d  k	 rñ |  j t j j j ƒ } x$ t j j D] } | j | ƒ qÑ Wqñ n ‚  d  S(   N(   t   detachR   t   _add_default_labelst   _check_undefined_labelst   _remove_unused_labelst   _analizeR   R   R   t   rtl_dump_filet   writet   format_instructionst   _check_live_registerst   _preallocate_registerst   _bind_registersR)   t   assign_namest   abit   finalizet   writert   active_writerst   add_function(   R8   t   exc_typet	   exc_valuet	   tracebackt   abi_functionR   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __exit__º   s"    







c         C  sŒ   d d l  } d d l } | j j j d k	 rL t d | j j j j ƒ ‚ n  | j j	 d k	 rm t d ƒ ‚ n  |  | j j _ |  | j _	 |  S(   s#  Makes active the function and its associated instruction stream.

        While the instruction stream is active, generated instructions are added to this function.

        While the function is active, generated instructions are checked for compatibility with the function target.
        iÿÿÿÿNs>   Can not attach the function: alternative function %s is activesX   Can not attach the function instruction stream: alternative instruction stream is active(
   t   peachpy.streamt   peachpy.common.functiont   commont   functiont   active_functionR   t
   ValueErrorR   t   streamt   active_stream(   R8   R   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRo   Ï   s    c         C  s   d d l  } d d l } | j j j d k r< t d ƒ ‚ n  | j j j |  k	 r` t d ƒ ‚ n  d | j j _ d | j _ |  S(   s­   Make the function and its associated instruction stream no longer active.

        The function and its instruction stream must be active before calling the method.
        iÿÿÿÿNs2   Can not detach the function: no function is actives;   Can not detach the function: a different function is active(	   R‡   Rˆ   R‰   RŠ   R‹   R   RŒ   R�   RŽ   (   R8   R   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRq   â   s    c      	   C  s  t  |  t t f ƒ s. t d t |  ƒ ƒ ‚ n  xH t |  ƒ D]: \ } } t  | t ƒ s; t d | t | ƒ f ƒ ‚ q; q; Wt ƒ  } xy t |  ƒ D]k \ } } | j r� | j | k rê t	 d | t | ƒ | | j |  | | j f ƒ ‚ n  | | | j <q� q� Wd  S(   NsL   Invalid arguments types (%s): a tuple or list of function arguments expectedsH   Invalid argument object for argument #%d (%s): peachpy.Argument expecteds8   Argument #%d (%s) has the same name as argument #%d (%s)(
   R   R"   t   tupleR   R   t	   enumeratet   ArgumentR&   R   RŒ   (   t   argst   iR:   t   names(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _check_argumentsñ   s    		1c           s~   d d l  m } t ˆ  | t f ƒ s1 t d ƒ ‚ t ˆ  | ƒ rZ ˆ  |  j k rS ˆ  Sd  Sn  t ‡  f d †  |  j Dƒ d  ƒ Sd  S(   Niÿÿÿÿ(   R‘   s0   Either Argument object or argument name expectedc         3  s$   |  ] } | j  ˆ  k r | Vq d  S(   N(   R   (   t   .0t   argument(   t   argument_target(    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>  s    (   R   R‘   R   R   RS   R   R   t   next(   R8   R˜   R‘   (    (   R˜   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _find_argument  s    	c         C  s  | d  k r d  Sd d l m } t | | ƒ s> t d ƒ ‚ n  d d l m } t | | ƒ r† |  j j | j	 ƒ |  j
 j | j	 ƒ n  | j } | d  k	 r± |  j j | j ƒ n  xJ | j D]? } |  j d  k	 r» | |  j j k r» t d j | ƒ ƒ ‚ q» q» W|  j | _ |  j j | ƒ d  S(   Niÿÿÿÿ(   t   Instructions   Instruction object expected(   t   LABELs4   {0} is not supported on the target microarchitecture(   R   t   peachpy.x86_64.instructionsR›   R   R   R   Rœ   R)   t   add_scoped_namet
   identifierR%   t   addt   constantR   Rl   R   Rm   RŒ   t   formatR!   R#   t   append(   R8   Rn   R›   Rœ   R¡   t	   extension(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   add_instruction  s"    	!c         C  s"   x | D] } |  j  | ƒ q Wd  S(   N(   R¥   (   R8   t   instructionsRn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   add_instructions-  s    c         C  sE   d d l  m } t | | ƒ s8 t d t | ƒ ƒ ‚ n  t |  | ƒ S(   Niÿÿÿÿ(   t   ABIs   %s is not an ABI object(   t   peachpy.x86_64.abiR¨   R   R   R   t   ABIFunction(   R8   R}   R¨   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR~   1  s    c         C  sw   d d l  m } |  j j |  j j k rs |  j j d | |  j ƒ ƒ |  j j |  j j ƒ |  j	 j
 |  j j ƒ n  d S(   s+   Adds default labels if they are not definediÿÿÿÿ(   Rœ   i    N(   R   Rœ   R    R   R)   R”   R#   t   insertRž   R%   R    (   R8   Rœ   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRr   7  s
    c         C  s¨   d d l  m } t ƒ  } x< |  j D]1 } t | | ƒ r# | j r# | j | j ƒ q# q# W| j |  j ƒ s¤ | j	 |  j ƒ } t
 d d j t d „  | ƒ ƒ ƒ ‚ n  d S(   sF   Verifies that all labels referenced by branch instructions are definediÿÿÿÿ(   t   BranchInstructions   Undefined labels found: s   , c         S  s   d j  t t |  ƒ ƒ S(   Nt   .(   R@   RA   R   (   R   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   L  R_   N(   R�   R¬   R$   R#   R   t
   label_nameR    t   issubsetR%   t
   differenceRŒ   R@   RA   (   R8   R¬   t   referenced_label_namesRn   t   undefined_label_names(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRs   A  s    	c         C  s*  d d l  m } d d l m } t ƒ  } x< |  j D]1 } t | | ƒ r3 | j r3 | j | j ƒ q3 q3 W|  j	 j
 | ƒ } |  j j | k rØ t |  j d | ƒ s¿ |  j d j |  j j k rØ | j |  j j ƒ qØ n  g  |  j D]+ } t | | ƒ s| j | k râ | ^ qâ |  _ |  j	 j | ƒ d S(   s9   Removes labels that are not referenced by any instructioniÿÿÿÿ(   R¬   (   Rœ   i    N(   R�   R¬   R   Rœ   R$   R#   R   R®   R    R%   R°   R    R   RŸ   t   removet   difference_update(   R8   R¬   Rœ   R±   Rn   t   unreferenced_label_names(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRt   N  s    	3c            s&  d d l  m } d d l m ‰ m ‰ d d l m ‰ g  ‰ g  ‰ x1 |  j D]& } ˆ j | j	 ƒ ˆ j | j
 ƒ qL W‡ f d †  t |  j ƒ Dƒ } d } |  j j |  j k rÃ | |  j j } n  g  t |  j ƒ D]0 \ } } t | | ƒ rÓ | j rÓ | | f ^ qÓ } | h } xE | D]= \ } } | j | | j ƒ | j r| j | d ƒ qqWt | ƒ } g  t |  j ƒ D]A \ } } t | | ˆ ˆ ˆ f ƒ rv| t t | ˆ ƒ ƒ ^ qv}	 g  | D]" }
 |
 |	 t j |	 |
 ƒ f ^ qÄ} d d ‡ ‡ ‡ f d	 †  ƒ  Y‰  t t ‡  ‡ ‡ f d
 †  | ƒ ƒ } d „  t | | ƒ Dƒ } x¶ t | ƒ D]¨ \ } ‰ |  j ˆ j d } t | ˆ ˆ f ƒ r�qUt | | ƒ ré| j ré| | j } | | g ˆ _ | j rýˆ j j | | d ƒ qýqU| | d g ˆ _ qUWx/ | D]' ‰ t t ‡ f d †  | ƒ ƒ ˆ _ qW| | j ƒ  g  | D] } | j sH| j ^ qH} | | j  t! ƒ  ƒ x" | D] } | | j" t! ƒ  ƒ q�W| | j# |  j |  j$ ƒ x( | D]  } | | j% |  j |  j$ ƒ qÀWx | D] ‰ ˆ j& ƒ  qëWx( | D]  } | | j' |  j |  j$ ƒ qW|  j | j( |  _) xn | D]f ‰ xK t |  j ˆ j ˆ j !ˆ j* ˆ j+ ƒ D]! \ } } } | | _, | | _- qsWd  ˆ _ d  ˆ _ qDWt/ ƒ  ‰ xh|  j D]]} | j0 } | j1 ˆ ƒ xu | D]m } | j2 räg  t3 j4 | j, ƒ D]% \ } } | | j5 @d k r| ^ q} |  j6 | j7 j8 | j9 | ƒ qäqäWg  | D] } | j2 s\| ^ q\} | rd d l: m; } | j< d „  t3 j4 | j, ƒ Dƒ ƒ } x` | D]U } g  | D]% } | j5 | j5 @d k rÆ| j= ^ qÆ} |  j6 | j7 j8 | j9 | ƒ q¹Wn  | j> ‰ qÁWd  S(   Niÿÿÿÿ(   R¬   (   Rœ   t   RETURN(   t   RETc           s1   i  |  ]' \ } } t  | ˆ  ƒ r | | j “ q S(    (   R   RŸ   (   R–   R“   Rn   (   Rœ   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys
   <dictcomp>p  s   	 	i    i   t
   BasicBlockc             s¶   e  Z d  „  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z ‡  ‡ ‡ f d †  Z ‡  ‡ ‡ f d †  Z ‡  ‡ ‡ f d †  Z RS(   c         S  sb  | |  _  | |  _ | |  _ | |  _ t j t ƒ |  _ t j t ƒ |  _ t j t ƒ |  _	 t j t ƒ |  _
 t |  _ d |  _ d |  _ t ƒ  |  _ t ƒ  |  _ t ƒ  |  _ t ƒ  |  _ x¤ t | | ƒ D]“ \ } } xQ t j | ƒ D]@ \ } } | |  j | @}	 |	 d k rã |  j | c |	 O<qã qã Wx0 t j | ƒ D] \ }
 } |  j |
 c | O<q7WqÇ Wd  S(   Ni    (   t   start_positiont   end_positiont   input_registers_listt   output_registers_listt   collectionst   defaultdictR   t   consumed_register_maskst   produced_register_maskst   live_register_maskst   available_register_maskst   Falset   is_reachablet   liveness_analysis_passest   availability_analysis_passesR"   t   input_blockst   output_blocksR$   t   processed_input_blockst   processed_output_blocksRd   t   sixt	   iteritems(   R8   R¹   Rº   R»   R¼   t   input_registerst   output_registerst   input_register_idt   input_register_maskt   consumed_maskt   output_register_idt   output_register_mask(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   ‡  s,    							c         S  s   t  ƒ  |  _ t  ƒ  |  _ d  S(   N(   R$   RÉ   RÊ   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   reset_processed_blocks«  s    c         S  sŠ   d d l  m } g  } |  j j ƒ  } x^ |  j D]S } | j | j ƒ  ƒ x7 t j | ƒ D]& \ } } | j | d ƒ | B| | <qX Wq/ W| S(   Niÿÿÿÿ(   t   Registeri    (	   R4   RÕ   RÂ   t   copyR¼   R£   RË   RÌ   t   get(   R8   RÕ   t   available_registers_listt   available_registers_masksRÎ   RÒ   RÓ   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRØ   ¯  s    "c         S  s  d d l  m } g  } |  j j ƒ  } xÚ t t t |  j |  j ƒ ƒ ƒ D]· \ } } x[ t	 j
 | ƒ D]J \ } } | | k rc | | | @} | d k r£ | | | <q­ | | =qc qc Wx7 t	 j
 | ƒ D]& \ }	 }
 | j |	 d ƒ |
 B| |	 <qÁ W| j | j ƒ  ƒ qG W| j ƒ  | S(   Niÿÿÿÿ(   RÕ   i    (   R4   RÕ   RÁ   RÖ   t   reversedR"   Rd   R»   R¼   RË   RÌ   R×   R£   t   reverse(   R8   RÕ   t   live_registers_listt   live_registers_masksRÍ   RÎ   RÒ   RÓ   t   new_live_register_maskRÏ   RÐ   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRÜ   ½  s     +
c         S  s   d |  j  |  j f S(   Ns   [%d, %d)(   R¹   Rº   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __str__Õ  s    c         S  s
   t  |  ƒ S(   N(   R   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __repr__Ø  s    c   	      S  sj  |  j  d 7_  |  j  d k rz |  j j | ƒ |  j rx= t j |  j ƒ D]& \ } } | j | d ƒ | B| | <qJ WqnŒ x‰ t t j | ƒ ƒ D]r \ } } |  j | } | | @} | d k rÖ |  j | c | O<n  |  j r� | d k rø | | | <q| | =q� q� W|  j rf| s$|  j  d k rfx( |  j d D] } | j	 | j
 ƒ  ƒ q2W|  j d j	 | ƒ n  d  S(   Ni   i    (   RÆ   RÂ   Rk   RÈ   RË   RÌ   RÀ   R×   R"   t   analyze_availabilityRÖ   (	   R8   t   extra_available_registerst   produced_reg_idt   produced_reg_maskt   reg_idt   extra_reg_maskt   old_reg_maskt   update_reg_maskt   output_block(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRá   Û  s&    	$"	c   	      S  sŒ  |  j  d 7_  x» t t j | ƒ ƒ D]¤ \ } } |  j | } | | @} | d k rk |  j | c | O<n  |  j r% |  j  d k rŒ | } n  | |  j j | d ƒ M} | d k r¿ | | | <qÉ | | =q% q% W|  j r(|  j  d k r(x= t j |  j ƒ D]& \ } } | j | d ƒ | B| | <qø Wq(n  |  j rˆ| sF|  j  d k rˆx( |  j d D] } | j	 | j
 ƒ  ƒ qTW|  j d j	 | ƒ n  d  S(   Ni   i    (   RÅ   R"   RË   RÌ   RÁ   RÇ   RÀ   R×   R¿   t   analyze_livenessRÖ   (	   R8   t   extra_live_registersRå   Ræ   Rç   Rè   t   consumed_reg_idt   consumed_reg_maskt   input_block(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRê   ú  s*    "			$c         S  s7   |  j  s3 t |  _  x |  j D] } | j ƒ  q Wn  d  S(   N(   RÄ   t   TrueRÈ   t   analyze_reachability(   R8   Ré   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRð   !  s    		c         S  se   | |  | | ƒ } xL |  j  D]A } | j |  j k r |  j j | j ƒ | j | | | ƒ q q Wd  S(   N(   RÈ   R¹   RÊ   R    t   forward_pass(   R8   t   processing_functionR¦   t   input_statet   output_stateRé   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRñ   '  s
    c         S  se   | |  | | ƒ } xL |  j  D]A } | j |  j k r |  j j | j ƒ | j | | | ƒ q q Wd  S(   N(   RÇ   R¹   RÉ   R    t   backward_pass(   R8   Rò   R¦   Ró   Rô   Rî   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRõ   .  s
    c           sv   d d l  m ‰ m ‰ d d l m ‰  m ‰ | r8 t n d  } ‡ ‡  ‡ ‡ ‡ ‡ ‡ f d †  } |  j | | | ƒ d  S(   Niÿÿÿÿ(   t   VZEROALLt
   VZEROUPPER(   t   LOADt   STOREc           s¸   x± | |  j  |  j !D]œ } t | ˆ ˆ f ƒ r8 d  } q | j d  k rz t | ˆ j ˆ j ˆ ˆ ˆ  f ƒ r° | | _ q° q | j rŒ t } q | rª t d j	 | ƒ ƒ ‚ n  t
 } q W| S(   Ns8   AVX-mode instruction {0} follows an SSE-mode instruction(   R¹   Rº   R   R   t   avx_modet   ARGUMENTt   RESULTRï   R   R¢   RÃ   (   t   blockR¦   t	   avx_stateRn   (   Rœ   Rø   R·   R¶   Rù   Rö   R÷   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_forward:  s    	$			
(	   t   peachpy.x86_64.avxRö   R÷   R   Rø   Rù   Rï   R   Rñ   (   R8   R¦   t   is_avx_environmentRþ   Rÿ   (   Rœ   R·   R¶   (   Rø   Rù   Rö   R÷   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_sse_avx_state_forward5  s
    !c           sZ   d d l  m ‰  m ‰ | r" t n d  } ‡ ‡  ‡ ‡ ‡ f d †  } |  j | | | ƒ d  S(   Niÿÿÿÿ(   Rø   Rù   c           s‰   x‚ t  | |  j |  j !ƒ D]g } | j d  k	 r; | j } q | d  k	 r | r t | ˆ j ˆ j ˆ ˆ ˆ  f ƒ r� | | _ q� q q W| S(   N(   RÚ   R¹   Rº   Rú   R   R   Rû   Rü   (   Rý   R¦   Rþ   Rn   (   Rœ   Rø   R·   R¶   Rù   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_sse_backwardS  s     $(   R   Rø   Rù   Rï   R   Rõ   (   R8   R¦   R  Rþ   R  (   Rœ   R·   R¶   (   Rø   Rù   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_sse_state_backwardO  s    c           sZ   d d l  m ‰  m ‰ | r" t n d  } ‡ ‡  ‡ ‡ ‡ f d †  } |  j | | | ƒ d  S(   Niÿÿÿÿ(   Rø   Rù   c           s|   xu t  | |  j |  j !ƒ D]Z } | j d  k	 r; | j } q | r t | ˆ j ˆ j ˆ ˆ ˆ  f ƒ rt | | _ qt q q Wd  S(   N(   RÚ   R¹   Rº   Rú   R   R   Rû   Rü   (   Rý   R¦   Rþ   Rn   (   Rœ   Rø   R·   R¶   Rù   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_avx_backwarda  s     $(   R   Rø   Rù   Rï   R   Rõ   (   R8   R¦   R  Rþ   R  (   Rœ   R·   R¶   (   Rø   Rù   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   propogate_avx_state_backward]  s    (   t   __name__t
   __module__R;   RÔ   t   propertyRØ   RÜ   Rß   Rà   Rá   Rê   Rð   Rñ   Rõ   R  R  R  (    (   Rœ   R·   R¶   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR¸   †  s   	$					'			c           s9   ˆ  |  d |  d ˆ |  d |  d !ˆ |  d |  d !ƒ S(   Ni    i   (    (   t	   start_end(   R¸   RÍ   RÎ   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   k  s    c         S  s   i  |  ] \ } } | | “ q S(    (    (   R–   t   basic_block_startt   basic_block(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys
   <dictcomp>q  s   	c           s   ˆ  |  j  k S(   N(   RÈ   (   t   bb(   R  (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   †  R_   (   RÕ   c         S  s+   i  |  ]! \ } } | d  k  r | | “ q S(   i    (    (   R–   Rå   t   reg_mask(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys
   <dictcomp>·  s   	 	(    (?   R�   R¬   R   Rœ   R¶   t   peachpy.x86_64.genericR·   R#   R£   t   input_registers_maskst   output_registers_masksR�   R    R   R%   R   R®   R    t   is_conditionalt   sortedR   t   bisectt   bisect_rightR"   RA   Rd   Rº   RÈ   t   filterRÇ   Rð   R¹   Rá   R&   Rê   R  R2   R  RÔ   R  Rú   R3   RØ   RÜ   t   _live_registerst   _available_registersR   R$   RÍ   Rk   t
   is_virtualRË   RÌ   t   maskR7   t   kindt   add_conflictst
   virtual_idR4   RÕ   t   _reconstruct_multiplet   _internal_idRÎ   (    R8   R¬   Rn   t   labelst   entry_positionR“   t   branch_instructionst   basic_block_startst   branch_instructiont   basic_block_endst   startt   basic_block_boundst   basic_blockst   basic_blocks_mapt   last_instructiont   target_positionRý   t   exit_positionst   exit_positiont   available_registerst   live_registerst   instruction_registerst   instruction_registerRå   R  t   conflict_internal_idst   rt   physical_registersRÕ   t   live_virtual_registerst   live_virtual_registert   reg(    (   R¸   Rœ   R·   R¶   R  RÍ   RÎ   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRu   c  s®    *		;,å	%%					%c   	      C  s  d d l  m } m } m } m } i d | j 6d | j 6d | j 6d | j 6} xÈ |  j D]½ } | j ƒ  } x$ | j D] } | | j	 c d 8<qv Wt
 d „  t j | ƒ Dƒ ƒ rZ | j d
 k	 rû | j d
 k	 rû t j d t | ƒ | j | j f ƒ ‚ qt j d	 t | ƒ ƒ ‚ qZ qZ Wd
 S(   sv   Checks that the number of live registers does not exceed the number of physical registers for each insruction
        iÿÿÿÿ(   R   R	   R
   R   i   i   i   i   c         s  s   |  ] } | d  k  Vq d S(   i    N(    (   R–   t   surplus_count(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>Ï  s    sL   The number of live virtual registers exceeds physical constaints %s at %s:%dsC   The number of live virtual registers exceeds physical constaints %sN(   R4   R   R	   R
   R   R6   R#   RÖ   R/  R  R0   RË   t
   itervaluest   source_fileR   t   line_numberR   t   RegisterAllocationErrorR   (	   R8   R   R	   R
   R   t   max_live_registersRn   R/  R7  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRy   Á  s"    "


"c      
   C  sP  d d l  m } m } m } m } m } d d l m } t ƒ  } t ƒ  } xÍ|  j	 D]Â}	 |	 j
 d d d d h k rTt |	 j ƒ d k s¾ t d	 t |	 j ƒ d
 j t t |	 j ƒ ƒ f ƒ ‚ |	 j d }
 t |
 | ƒ sð t d t |
 ƒ ƒ ‚ |
 j r|	 j j | j d ƒ | j @d k r>| d d t |	 j
 ƒ ƒ ‚ n  | j |
 j ƒ qqT |	 j
 d d d d d d d d h k r>t |	 j ƒ d k sÄt d t |	 j ƒ d
 j t t |	 j ƒ ƒ f ƒ ‚ |	 j d } t | | ƒ r| j r|	 j j | j d ƒ | j @d k r(| d d |	 j
 ƒ ‚ n  | j | j ƒ qqT |	 j
 d d h k rT t |	 j ƒ d k sœt d	 t |	 j ƒ d
 j t t |	 j ƒ ƒ f ƒ ‚ |	 j d } t | | ƒ r| j r|	 j j | j d ƒ | j @d k r | d d |	 j
 ƒ ‚ n  | j | j ƒ qqT qT Wxn | D]f } t t j d | ƒ | ƒ } |  j d | } t g  | D] } | | k ^ q]ƒ r!| d  ƒ ‚ q!q!Wxn | D]f } t t j d | ƒ | ƒ } |  j d | } t g  | D] } | | k ^ qÎƒ r’| d! ƒ ‚ q’q’Wx% | D] } | j |  j | j | <qWx% | D] } | j |  j | j | <q+Wd" S(#   sÏ  Allocates registers that can be binded only to a single virtual register.

        Several instructions accept only a fixed a register as their operand. If a virtual register is supplied as such
        operand, it must be binded to the fixed register accepted by instruction encoding.

        These instructions are:

            - BLENDVPS xmm, xmm/m128, xmm0
            - BLENDVPD xmm, xmm/m128, xmm0
            - PBLENDVB xmm, xmm/m128, xmm0
            - SHA256RNDS2 xmm, xmm/m128, xmm0
            - SHR r/m, cl
            - SAR r/m, cl
            - SAL r/m, cl
            - SHL r/m, cl
            - ROR r/m, cl
            - ROL r/m, cl
            - SHRD r/m, r, cl
            - SHLD r/m, r, cl
        iÿÿÿÿ(   R   R
   t   GeneralPurposeRegister8t   xmm0t   cl(   R<  t   BLENDVPDt   BLENDVPSt   PBLENDVBt   SHA256RNDS2i   s    expected 3 operands, got %d (%s)s   , i   s1   expected xmm registers in the 3rd operand, got %si    sD   Instruction %s requires operand 3 to be allocated to xmm0 register, s   but xmm0 is a live registert   SALt   SARt   SHLt   SHRt   ROLt   RORt   RCLt   RCRs    expected 2 operands, got %d (%s)i   sB   Instruction %s requires operand 2 to be allocated to cl register, s   but cl is a live registert   SHLDt   SHRDsB   Instruction %s requires operand 3 to be allocated to cl register, t   __ne__s;   Two conflicting virtual registers are requred to bind to cls=   Two conflicting virtual registers are requred to bind to xmm0N(    R4   R   R
   R>  R?  R@  R   R<  R$   R#   R   t   lent   operandsRS   R@   RA   R   R   R  R  R×   R  t   _maskR    R  R`   t   methodcallert   _conflicting_registersR0   t   physical_idt   _register_allocationsR6   (   R8   R   R
   R>  R?  R@  R<  t   cl_binded_registerst   xmm0_binded_registersRn   t   xmm0_operandt   count_operandt   cl_registert   other_cl_registerst   conflicting_registerst   other_registert   xmm0_registert   other_xmm0_registers(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRz   Ø  sl    (		.	%'.%.%%%c         C  s`   xY |  j  D]N } xE | j D]: } | j r |  j | j j j | j | j ƒ | _ q q Wq
 Wd S(   sY   Iterates through the list of instructions and assigns physical IDs to allocated registersN(	   R#   t   register_objectsR  R7   R  t   register_allocationsR×   R  RU  (   R8   Rn   t   register(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR{   2  s
    	c         C  s   |  j  d 7_  |  j  S(   s,   Returns a new unique ID for a local variablei   (   R*   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _allocate_local_variable<  s    c         C  s   |  j  d 7_  |  j  S(   s7   Returns a new unique ID for a virtual mask (k) registeri   (   R.   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _allocate_mask_register_idA  s    c         C  s   |  j  d 7_  |  j  S(   sL   Returns a new unique ID for a virtual SSE/AVX/AVX-512 (xmm/ymm/zmm) registeri   (   R-   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _allocate_xmm_register_idF  s    c         C  s   |  j  d 7_  |  j  S(   s7   Returns a new unique ID for a virtual MMX (mm) registeri   (   R,   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   _allocate_mmx_register_idK  s    c         C  s   |  j  d 7_  |  j  S(   s>   Returns a new unique ID for a virtual general-purpose registeri   (   R+   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt%   _allocate_general_purpose_register_idP  s    c         C  s
   |  j  ƒ  S(   sH   Returns string representation of the function signature and instructions(   R¢   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRß   U  s    c         C  s^  d d l  m } m } g  } d } x|  j D]} | j | j d d t ƒƒ t | | | f ƒ s&| j | d d j t	 t
 t | j ƒ ƒ ƒ ƒ | j | d	 d j t	 t
 t | j ƒ ƒ ƒ ƒ | j | d
 d j t	 t
 t | j ƒ ƒ ƒ ƒ | j | d d j t	 t
 t | j ƒ ƒ ƒ ƒ n  | j d ƒ q, W| d k rG| St | ƒ j | ƒ Sd S(   sY   Formats instruction listing including data on input, output, available and live registersiÿÿÿÿ(   Rœ   t   ALIGNR=   i   R   t   indents   In regs:    s   , s   Out regs:   s   Live regs:  s   Avail regs: R_   Ns       (   R   Rœ   Ri  R#   R£   R¢   RÃ   R   R@   R  RA   R   RÍ   RÎ   R/  R.  R   (   R8   t   line_separatorRœ   Ri  t   codet   tabRn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRx   Z  s    0003c         C  sc   |  j  g } x- |  j D]" } | j | j d d t ƒƒ q W| d k rL | St | ƒ j | ƒ Sd S(   sJ   Formats assembly listing of the function according to specified parametersR   Rj  N(   RC   R#   R£   R¢   Rï   R   R   R@   (   R8   Rk  Rl  Rn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR¢   m  s     ($   R  R  t   __doc__R   R;   R	  RC   Rh   Rl   Rp   R†   Ro   Rq   t   staticmethodR•   Rš   R¥   R§   R~   Rr   Rs   Rt   Ru   Ry   Rz   R{   Rd  Re  Rf  Rg  Rh  Rß   t   ost   linesepRx   R¢   (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR      sB   M	7									
			ÿ _		Z	
						R‘   c           B  s    e  Z d  „  Z e d „  ƒ Z RS(   c         C  sÜ   t  | t j ƒ s t d ƒ ‚ d d l m } t  | | ƒ sI t d ƒ ‚ d d l m } t t |  ƒ j	 | | j
 ƒ | j ƒ |  j
 j d k r« |  j
 j | ƒ |  j
 _ n  | |  _ d |  _ d |  _ d |  _ t |  _ d S(   s¼  Extends generic Argument object with x86-64 specific attributes required for stack frame construction

        :ivar peachpy.x86_64.registers.Register register: the register in which the argument is passed to the function
            or None if the argument is passed on stack.
        :ivar int stack_offset: offset from the end of return address on the stack to the location of the argument on
            stack or None if the argument is passed in a register and has no stack location. Note that in Microsoft X64
            ABI the first four arguments are passed in registers but have stack space reserved for their storage.
            For these arguments both register and stack_offset are non-null.
        :ivar peachpy.x86_64.operand.MemoryAddress address: address of the argument on stack, relative to rsp or rbp.
            The value of this attribute is None until after register allocation. In Golang ABIs this attribute is never
            initialized because to load arguments from stack Golang uses its own pseudo-register FP, which is not
            representable in PeachPy (LOAD.ARGUMENT pseudo-instructions use stack_offset instead when formatted as
            Golang assembly).
        sO   Architecture-specific argument must be constructed from generic Argument objectiÿÿÿÿ(   R¨   s   ABI object expected(   t   deepcopyN(   R   R   R‘   RS   R©   R¨   RÖ   Rr  t   superR;   R1   R   RY   R   t   get_sizeR}   Rc  t   addresst   stack_offsetRÃ   t   save_on_stack(   R8   R—   R}   R¨   Rr  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   z  s    	%				c         C  s   |  j  d  k S(   N(   Rc  R   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   passed_on_stack—  s    (   R  R  R;   R	  Rx  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR‘   y  s   	Rª   c           B  sÚ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d e j e d d „ Z d e j d d „ Z d „  Z e d „  ƒ Z d „  Z RS(   s�   ABI-specific x86-64 assembly function.

    A function consists of C signature, ABI, and a list of instructions without virtual registers.
    c         C  s‚  d d l  m } m } m } m } m } m } m }	 m }
 m	 } d d l
 m } t | t ƒ sk t d ƒ ‚ t | | ƒ s† t d ƒ ‚ | j |  _ g  | j D] } t | | ƒ ^ qœ |  _ | j |  _ d  |  _ | j |  _ | j |  _ | j |  _ | |  _ | j |  _ | j |  _ | j |  _ | j |  _ d d l m } | |  _ d |  _  |  j j! |  _" d |  _# | | j$ ƒ |  _$ | | j% ƒ |  _% | | k r£|  j& ƒ  n] | | | | h k rÅ|  j' ƒ  n; | | |	 |
 | h k rê|  j( ƒ  n t) d t* | ƒ ƒ ‚ |  j+ | j ƒ |  j, ƒ  |  j- ƒ  |  j. ƒ  |  j/ ƒ  |  _0 |  j1 ƒ  |  j2 ƒ  |  j3 ƒ  |  j4 ƒ  |  j5 ƒ  |  j6 ƒ  |  _7 d  S(	   Niÿÿÿÿ(	   R¨   t   microsoft_x64_abit   system_v_x86_64_abit   linux_x32_abit   native_client_x86_64_abit   gosyso_amd64_abit   gosyso_amd64p32_abit   goasm_amd64_abit   goasm_amd64p32_abi(   Rr  s   Function object expecteds   ABI object expected(   t   rspi    s   Unsupported ABI: %s(8   R©   R¨   Ry  Rz  R{  R|  R}  R~  R  R€  RÖ   Rr  R   R   RS   R   R   R‘   R   R   t   result_offsetR   R   Rl   R}   RC   Rh   R2   R3   R4   R�  t   _stack_baset   _stack_frame_sizet   stack_alignmentt   _stack_frame_alignmentt   _local_variables_sizeR#   R7   t   _setup_windows_argumentst   _setup_unix_argumentst   _setup_golang_argumentsRŒ   R   t   _update_argument_loadst   _layout_local_variablest   _allocate_registersR{   t   _analyze_clobbered_registerst   _clobbered_registerst   _update_stack_framet   _update_argument_addressest   _lower_argument_loadst   _lower_pseudoinstructionst   _filter_instruction_encodingst   mangle_namet   mangled_name(   R8   RŠ   R}   R¨   Ry  Rz  R{  R|  R}  R~  R  R€  Rr  R—   R�  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   ¢  sR    @(					







c         C  s–   d d l  m } x |  j D]t } t | | j ƒ r | j d |  j | j | j d ƒ f | _ | j d j | j	 k rŽ t
 | j d _ qŽ q q Wd  S(   Niÿÿÿÿ(   Rø   i    i   (   R   Rø   R#   R   Rû   RQ  R   t   indexRc  R.  Rï   Rw  (   R8   R   Rø   Rn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR‹  Ú  s    -c         C  s¤  d d l  m } |  j | k s+ t d ƒ ‚ d d l m } d d l m } m } m	 } m
 } m } m } m }	 m }
 | | |	 |
 f } | | | | f } xt |  j ƒ D]ó \ } } | j oÇ | | k | _ | d k  r�| j rò | | | _ q�| j s%| j s%| j s%| j s%| j | k rg| | } i | j d 6| j d 6| j d 6| d	 6| j | _ q�| j r€| | | _ q�t s�t ‚ n  | d	 | _ q© Wd  S(
   Niÿÿÿÿ(   Ry  s6   This function must only be used with Microsoft x64 ABI(   t   m64(   t   rcxt   rdxt   r8t   r9R?  t   xmm1t   xmm2t   xmm3i   i   i   i   (    R©   Ry  R}   RS   R/   R˜  R4   R™  Rš  R›  Rœ  R?  R�  Rž  RŸ  R�   R   t	   is_vectort   passed_by_referenceR[   Rc  t
   is_integerRT   t   is_codeunitt   is_maskR1   t   as_low_bytet   as_wordt   as_dwordRY   RÃ   Rv  (   R8   Ry  R˜  R™  Rš  R›  Rœ  R?  R�  Rž  RŸ  t!   floating_point_argument_registerst   integer_argument_registersR—  R—   t   argument_register(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRˆ  ã  s8    	:					



	c         C  s<  d d l  m } m } m } |  j | | | h k s@ t d ƒ ‚ d d l m } m } m	 } m
 } m } m }	 m }
 m } m } m } m } m } m } m } |
 | | | | | | | g } | | | | | |	 g } d } x[|  j D]P} | j sü | j rŒt | ƒ d k rŒ| j d ƒ | _ | j d d d h k r;q4| j d	 k r\| j j | _ q4| j d
 k r}| j j | _ q4t s4t ‚ qä | j s§| j  s§| j! r t | ƒ d k r | j d ƒ } i | j" d 6| j" d 6| j" d 6| d 6| j | _ qä | j s| j# r!t s4t ‚ qä | | _$ | d 7} qä Wd  S(   Niÿÿÿÿ(   Rz  R{  R|  s_   This function must only be used with System V x86-64, Linux x32 or Native Client x86-64 SFI ABI(   t   rdit   rsiRš  R™  R›  Rœ  R?  R�  Rž  RŸ  t   xmm4t   xmm5t   xmm6t   xmm7i    i   i   i   i    i@   i   i   (%   R©   Rz  R{  R|  R}   RS   R4   R«  R¬  Rš  R™  R›  Rœ  R?  R�  Rž  RŸ  R­  R®  R¯  R°  R   R[   R   RP  t   popRc  RY   t   as_ymmt   as_zmmRÃ   R¢  RT   R£  R§  R¤  Rv  (   R8   Rz  R{  R|  R«  R¬  Rš  R™  R›  Rœ  R?  R�  Rž  RŸ  R­  R®  R¯  R°  t"   available_floating_point_registerst   available_integer_registersRv  R—   Rª  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR‰    s<    	^
$


	c   	      C  sÕ   d d l  m } m } m } m } |  j | | | | h k sI t d ƒ ‚ d d l m } d } xE t	 |  j
 ƒ D]4 \ } } | | | j ƒ } | | _ | | j 7} qo W|  j d  k	 rÑ | | |  j j ƒ |  _ n  d  S(   Niÿÿÿÿ(   R}  R~  R  R€  sA   This function must only be used with Golang AMD64 or AMD64p32 ABI(   t   roundupi    (   R©   R}  R~  R  R€  R}   RS   t   peachpy.utilR¶  R�   R   RY   Rv  R   R   R‚  (	   R8   R}  R~  R  R€  R¶  Rv  R—  R—   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRŠ  5  s    "		c   	      C  s™  d d l  m } t ƒ  } t ƒ  } x[ |  j D]P } | j } | d  k	 r, | j } | | k r| | j | ƒ | j	 | ƒ q| q, q, W| r•t t
 | d d „  ƒƒ } t d „  | Dƒ ƒ |  _ d } d d l m } x6 | D]. } | | | j ƒ } | | _ | | j 7} q× W| |  _ x€ |  j D]r } | j } | d  k	 r| j d  k	 sLt ‚ | j } | d  k	 sgt ‚ | j | k s|t ‚ | j | j _ qqWn  d  S(   Niÿÿÿÿ(   R�  t   keyc         S  s   |  j  S(   N(   RY   (   t   var(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   T  R_   c         s  s   |  ] } | j  Vq d  S(   N(   t	   alignment(   R–   R¹  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>U  s    i    (   R¶  (   R4   R�  R$   R"   R#   t   local_variableR   t   rootR    R£   R  t   maxR†  R·  R¶  Rº  t   _addressRY   R‡  Ru  RS   t   memory_addressRU   t   displacement(	   R8   R�  t   local_variables_sett   local_variables_listRn   R»  t   local_variable_addressR¶  R¿  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRŒ  G  s8    								c         C  sD  x3 t  j |  j ƒ D] \ } } | j |  j | ƒ q Wd d l m } d d l m } m	 } m
 } m } m } x¨ |  j D]� }	 t |	 | j ƒ rx |	 j d }
 |	 j d } t |
 | ƒ s¿ t ‚ t | t ƒ sÔ t ‚ |
 j r| j d  k	 r|  j |
 j j |
 j | j j ƒ qqx qx Wx$ t  j |  j ƒ D] } | j ƒ  q,Wd  S(   Niÿÿÿÿ(   Rø   (   RÕ   R   R	   R
   R   i    i   (   RË   RÌ   R7   t   set_allocation_optionsR}   R   Rø   R4   RÕ   R   R	   R
   R   R#   R   Rû   RQ  RS   R‘   R  Rc  R   R  t   try_allocate_registerR  RU  R9  t   allocate_registers(   R8   t   register_kindt   register_allocatorRø   RÕ   R   R	   R
   R   Rn   t   dst_regt   src_arg(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR�  g  s    (c         C  s«  d d l  m } d d l m } m } d d l m } m } m } m	 } d d l
 m } m }	 |  j | k s| |  j | k r€ d  Sg  }
 xt |  j ƒ D]\ } } t | | j ƒ r�t | j d | | | | f ƒ sâ t d ƒ ‚ | j d j d  k	 rJ| | j d | j d j | j d j d	 | ƒ} | d  k	 rŠ|
 j | ƒ qŠqš|	 | j d | j d j | j d j d	 | ƒ} |
 j | ƒ q– |
 j | ƒ q– W|
 |  _ d  S(
   Niÿÿÿÿ(   Rø   (   R  R€  (   R   R	   R
   t   YMMRegister(   t   load_registert   load_memoryi    s`   Lowering LOAD.ARGUMENT is supported only for general-purpose, mmx, xmm, and ymm target registersi   t	   prototype(   R   Rø   R©   R  R€  R4   R   R	   R
   RË  t   peachpy.x86_64.lowerRÌ  RÍ  R}   R�   R#   R   Rû   RQ  RS   Rc  R   R1   R£   Ru  (   R8   Rø   R  R€  R   R	   R
   RË  RÌ  RÍ  t   lowered_instructionsR“   Rn   t   ld_regt   ld_mem(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR’  z  s4    "			c   A        s›
  d d l  m } m } d d l m } d d l m } m } d d l m	 } m
 } m } m }	 m }
 m } m } m } m } d d l m } m } m } m } m } d d l m } d d l m } m } m } m } m } d d	 l  m! } m" } m# } m$ } m% } d d
 l& m' } m( }  m) }! d d l* m+ }" t, ƒ  }# t, ƒ  }$ t, ƒ  }% |" ƒ  �ì}& xr |  j- D]g }' t. |' | | f ƒ s’t/ d t0 |' ƒ ƒ ‚ t. |' | ƒ r»|% j1 |' ƒ | |' ƒ qa|$ j1 |' ƒ qaW|  j2 |  j3 j4 k r|% j1 | ƒ | | ƒ |
 | | ƒ n  |$ s|  j5 d k rè|  j6 t7 |% ƒ | j8 }( |  j3 | k r†| | |( |  j5 ƒ |  j2 |  j3 j4 k rå| | |  j2 ƒ qåqè|  j2 |  j3 j4 k rÔ| | | |( |  j5 g ƒ | | |  j2 ƒ | | ƒ qè| |( |  j5 ƒ n  xQ t9 |$ ƒ D]C \ }) }* |  j: r| n | }+ |+ | |  j5 |) | j8 g |* ƒ qõWWd  QX|# j; |& j< ƒ x9|  j= D].}, t. |, | ƒ r%	d d l  m> }- m? }. m" } m@ }/ mA }0 m% } mB }1 mC }2 mD }3 mE }4 mF }5 mG }6 mH }7 |  j3 | | h k }8 |  j3 | | h k }9 |" ƒ  �}: |, jI r{t7 |, jI ƒ d k s#t/ ‚ |! |, jI d ƒ r`|  jJ jK sT|  jJ jL sTt/ ‚ |8 rØ|  jJ j8 d k s|  |, jI d ƒ r¢| jM |, jI d d |, d |  ƒq]|
 | |, jI d d |, ƒ| jM | d |, d |  ƒqx|, jI d d k r|	 | | d |, ƒqx|  jJ j8 d k s&| |, jI d ƒ rC|
 | |, jI d d |, ƒqx|
 |0 |, jI d d |, ƒq{t. |, jI d |- ƒ rS|8 r»|, jI d j8 |  jJ j8 k r»| jM |, jI d d |, d |  ƒqx|  jJ j8 d k rÓ| n |0 }; |: jN | |; |, jI d |  jJ d |, ƒƒ |8 rxi |2 d 6|1 d 6| d 6|0 d 6|  jJ j8 }< | jM |< d |, d |  ƒqxq{t. |, jI d |. ƒ r•|: jN | |5 |, jI d |  jJ d |, ƒƒ q{t. |, jI d | ƒ r*|  jJ jO rþ|8 rþ|  jJ j8 d d h k sÛt/ ‚ | jM |, jI d d |, d |  ƒqx|: jN | |6 |, jI d |  jJ d |, ƒƒ q{t. |, jI d |/ ƒ rl|: jN | |7 |, jI d |  jJ d |, ƒƒ q{tP s{t/ ‚ n  |, jQ rž|  jR rž| d |, ƒ n  xQ t9 |$ ƒ D]C \ }) }* |  jR rÆ| n | }+ |+ |* | |  j5 |) | j8 g ƒ q«W|  j2 |  j3 j4 k r|
 | | ƒ ni |$ s,|  j5 d k r€|  j6 t7 |% ƒ | j8 }( |  j3 | k rl| | |( |  j5 ƒ q€| |( |  j5 ƒ n  xP tS |% ƒ D]B }' |' | k rÅ|  j3 | k rÅ| |3 ƒ | |4 ƒ q�| |' ƒ q�W|  j3 | k rÿ| |3 d |, ƒ| |4 ƒ n | d |, ƒ Wd  QX|# j; |: j< ƒ q\t. |, | jM ƒ rS	|  jT |, _U |# j1 |, ƒ q\|  j3 | k r}
|, jV d k r}
d d lW mX ‰  t, tY ‡  f d †  |, jI ƒ ƒ }= |= r}
t7 |= ƒ d k sÆ	t/ d ƒ ‚ |= d jZ }> d d lW m[ }? t. |> |? ƒ rz
|> j\ d  k	 r
t^ d ƒ ‚ n  d d l  m$ } m# } m_ }@ |> j` d  k	 rw
|> j` | | |@ h k rw
|> j` |> _\ d |> _a |@ |> _` qw
qz
q}
n  |# j1 |, ƒ q\W|# |  _= d  S(   Niÿÿÿÿ(   R¶   Rù   (   t   MOVAPS(   t   VMOVAPSR÷   (	   t   PUSHt   SUBt   ADDt   XORt   MOVt   POPR·   t   ANDt   LEA(   t   NACLJMPt
   NACLRESTBPt
   NACLRESTSPt   NACLASPt   NACLSSP(   RÌ  (   R|  R}  R~  R  R€  (   t   GeneralPurposeRegister64R
   R�  t   rbpt   eax(   t	   is_uint32t	   is_sint32t   is_int(   t   InstructionStreams6   Internal error: unexpected register %s in clobber listi    (   R   R	   R
   RË  t   raxRä  t   axt   alR™  t   ecxt   mm0R?  t   ymm0i   i   RÎ  t   target_functioni   i   RÜ  (   t   is_mc           s
   ˆ  |  ƒ S(   N(    (   t   op(   Rð  (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   N  R_   sD   x86-64 instructions can not have more than 1 explicit memory operand(   t   MemoryAddresss$   NaCl does not allow index addressing(   Rã  R�  t   r15(b   R   R¶   Rù   t   peachpy.x86_64.mmxsseRÓ  R   RÔ  R÷   R  RÕ  RÖ  R×  RØ  RÙ  RÚ  R·   RÛ  RÜ  t   peachpy.x86_64.naclRÝ  RÞ  Rß  Rà  Rá  RÏ  RÌ  R©   R|  R}  R~  R  R€  R4   Râ  R
   R�  Rã  Rä  R·  Rå  Ræ  Rç  R‡   Rè  R"   R�  R   RS   R   R£   R†  R}   R…  R‡  R„  RP  RY   R�   R3   t   extendR¦   R#   R   R	   RË  Ré  Rê  Rë  R™  Rì  Rí  R?  Rî  RQ  R   R¢  RT   Rü   R¥   R[   RÃ   Rú   R2   RÚ   R‚  t   destination_offsetR   t   peachpy.x86_64.operandRð  R  Ru  Rò  R—  R   RŒ   Ró  RU   t   scale(A   R8   R¶   Rù   RÓ  RÔ  R÷   RÕ  RÖ  R×  RØ  RÙ  RÚ  R·   RÛ  RÜ  RÝ  RÞ  Rß  Rà  Rá  RÌ  R|  R}  R~  R  R€  Râ  R
   R�  Rã  Rä  Rå  Ræ  Rç  Rè  R¦   t   cloberred_xmm_registerst#   cloberred_general_purpose_registerst   prolog_streamR7  t   stack_adjustmentR“   t   xmm_regt   movapsRn   R   R	   RË  Ré  Rê  Rë  R™  Rì  Rí  R?  Rî  t   is_goasm_abit   is_gosyso_abit   epilog_streamt
   result_regt   result_subregt   memory_operandsR¿  Rò  Ró  (    (   Rð  sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR“  ›  s   @(((			
,X	%#%"#
	

	#
	
	&
!	'	c         C  s'   x  |  j  D] } | j ƒ  | _ q
 Wd  S(   N(   R#   t   _filter_encodingst	   encodings(   R8   Rn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR”  `  s    c         C  s=   x6 |  j  D]+ } | j d  k	 r
 |  j | j | _ q
 q
 Wd  S(   N(   R   Rv  R   t   _argument_stack_baseRu  (   R8   R—   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR‘  d  s    c   	        sØ   d d l  m } m } m } m } t ƒ  } x! ˆ  j D] } | j | j ƒ q5 Wt ƒ  } x[ | D]S } t	 | | ƒ r‡ | j
 | j ƒ q_ t	 | | | | f ƒ r_ | j
 | j ƒ q_ q_ Wt t t ‡  f d †  | ƒ ƒ ƒ S(   Niÿÿÿÿ(   R   R
   RË  t   ZMMRegisterc           s   |  ˆ  j  j k S(   N(   R}   t   callee_save_registers(   R7  (   R8   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   u  R_   (   R4   R   R
   RË  R	  R$   R#   Rk   RÎ   R   R    t   as_qwordt   as_xmmR"   R  R  (	   R8   R   R
   RË  R	  t   output_subregistersRn   RÎ   t   subreg(    (   R8   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRŽ  i  s    "		c   
      C  sa  d d l  m } m } m } m } d } d } xb |  j D]W } t | | | f ƒ si t d t | ƒ ƒ ‚ t | | ƒ r… | d 7} q8 | d 7} q8 W|  j	 |  j
 j k rµ | d 7} n  | | j | | j |  _ | d k së |  j d k r| d d k r|  j d 7_ n  d } |  j	 |  j
 j k rBd }	 | | |	 |  _ n | | |  j |  j |  _ d  S(   Niÿÿÿÿ(   Râ  R
   Rã  R�  i    s6   Internal error: unexpected register %s in clobber listi   i   i   (   R4   Râ  R
   Rã  R�  R�  R   RS   R   R†  R}   R…  RY   R„  R‡  R  (
   R8   Râ  R
   Rã  R�  t#   clobbered_general_purpose_registerst   clobbered_xmm_registersR7  t   return_address_sizet   saved_rbp_size(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR�  w  s(    "
+c         C  sU   xN |  j  D]C } x: | j D]/ } | j r |  j | j j | j | _ q q Wq
 Wd S(   sY   Iterates through the list of instructions and assigns physical IDs to allocated registersN(   R#   Ra  R  R7   R  Rb  R  RU  (   R8   Rn   Rc  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR{   ›  s    	R   i   c   
   
   C  së   g  } | d k rk d d l  m } xF t |  j ƒ D]2 \ } } t | | ƒ r2 | | | j d _ q2 q2 Wn  xV t |  j ƒ D]E \ } } d d l m }	 | j	 | j
 d | d | d | | ƒ ƒ q{ W| d	 k rÔ | St | ƒ j | ƒ Sd	 S(
   s=   Returns code of assembly instructions comprising the functiont   gasiÿÿÿÿ(   Rœ   i    (   R›   t   assembly_formatRj  R;  N(   R   Rœ   R�   R#   R   RQ  R;  R�   R›   R£   R¢   R   R   R@   (
   R8   R  Rk  Rj  R;  Rl  Rœ   R“   Rn   R›   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   format_code¤  s    	-c   
      C  s‘  | d k r(|  j  } | d( k r* d } n  t j rN | d |  j d g } n | d |  j d g } | j d ƒ t t t j	 d ƒ |  j
 ƒ ƒ } |  j d( k	 r¹ |  j |  j j } n  | d k rÕ | j d	 ƒ n | j d
 | ƒ d d j | ƒ g } |  j d( k	 rî| j d d |  j ƒ qînÆ | d k rèd d l m } d }	 d d d j d |  j ƒ d j d | |	 ƒ ƒ d j d |  j ƒ d d d j d | |	 ƒ d |	 d ƒ d |  j d j d |  j ƒ d  j d |  j ƒ d! g } n g  } | |  j | d" d( d# t d$ | t | ƒ ƒ7} | d k rN| d% d& j d |  j ƒ d' g 7} n  | d) k rj| j d ƒ n  | d( k rz| St | ƒ j | ƒ Sd( S(*   sJ   Formats assembly listing of the function according to specified parameterst   goR_   s   Â·s   (SB)s   \u00B7t   4RY   i    s   $0s   $0-%ds   TEXT t   ,s   // R  iÿÿÿÿ(   t   ilog2i   s   #ifdef __APPLE__s0   .section __TEXT,__text,regular,pure_instructionss   .globl _{name}R   s   .p2align {ilog2alignment}, 0x90t   ilog2alignments   _{name}:s   #else /* !__APPLE__ */s   .texts0   .p2align {ilog2alignment},,{max_alignment_bytes}t   max_alignment_bytesi   s   .globl s   .type {name}, @functions   {name}:s   #endif /* !__APPLE */Rk  Rj  R;  s   #ifndef __APPLE__s   .size {name}, .-{name}s   #endif /* !__APPLE__ */N(   R  R  (   R   R   RË   t   PY2R–  R£   t   sumRA   R`   Ra   R   R‚  R   RY   R@   Rh   R«   R·  R  R¢   R  Rï   RP  R   (
   R8   R  Rk  R;  t   package_stringt   text_argumentst
   stack_sizeRl  R  t   code_alignment(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR¢   ¿  s^    			!		

/c         C  s
   t  |  ƒ S(   N(   t   EncodedFunction(   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   encodeÿ  s    c         C  sê   t  j d d |  j f d |  j f d |  j d  k r9 d n t |  j ƒ f d g  |  j D]3 } t  j d | j f d t | j ƒ f g ƒ ^ qU f d d t |  j	 ƒ f d |  j
 j f d g  |  j j ƒ  D] } t | ƒ ^ qÅ f g	 ƒ } | S(   NR    RŠ   R   t   symbolt   returnR<   R   t   typet   archs   x86-64R}   R   t   isa(   R    RŠ   (   R'  s   x86-64(   R½   t   OrderedDictR   R–  R   R   R   R   R1   R}   R   Rl   t   minify(   R8   R—   R¤   t   metadata(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR+    s    '@4c         C  s  d d  l  } d d  l } | j j j j d |  j ƒ j d |  j j ƒ  ƒ j d |  j j ƒ  ƒ j d |  j	 j
 ƒ j d |  j	 j
 j ƒ  ƒ j d |  j	 j
 j ƒ  ƒ j d d	 j g  |  j j ƒ  D] } | j ^ q» ƒ ƒ j d
 d	 j g  |  j j ƒ  D] } | j j ƒ  ^ qï ƒ ƒ } | S(   Niÿÿÿÿs   ${Name}s   ${name}s   ${NAME}s   ${uArch}s   ${uarch}s   ${UARCH}s   ${ISA}t   _s   ${isa}(   t   peachpy.x86_64.optionst   stringR   R   t   name_manglingt   replaceR   t   lowert   upperR   t   idR@   Rl   R*  t	   safe_name(   R8   R   R.  R¤   R   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR•    s    4:(   R  R  Rn  R;   R‹  Rˆ  R‰  RŠ  RŒ  R�  R’  R“  R”  R‘  RŽ  R�  R{   Rp  Rq  Rï   R  R¢   R#  R	  R+  R•  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRª   œ  s(   	8			$	.		 		!	Å				$		@	t   InstructionBundlec           B  sb   e  Z d  „  Z e d „  ƒ Z d „  Z d e d „ Z d „  Z	 d „  Z
 e d „  ƒ Z d „  Z RS(	   c         C  sX   | d d d h k r$ t  d ƒ ‚ n  | |  _ | |  _ d |  _ g  |  _ t ƒ  |  _ d  S(   Ni   i    i@   s%   Bundle capacity must be 16, 32, or 64i    (   RŒ   t   capacityRu  RY   R#   R&   t   branch_info_map(   R8   R6  Ru  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   #  s    				c         C  s   |  j  |  j S(   N(   R6  RY   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   padding-  s    c           sé   d d l  m ‰  t | t ƒ s% t ‚ t ‡  f d †  | Dƒ ƒ sM t d ƒ ‚ t ƒ  j g  | D] } | j ƒ  ^ q] ƒ } |  j	 t
 | ƒ |  j k rÜ |  j	 t
 | ƒ 7_	 x9 | D]% } | j ƒ  | _ |  j j | ƒ q° Wn	 t ƒ  ‚ d  S(   Niÿÿÿÿ(   R›   c         3  s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R   (   R–   Rn   (   R›   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>4  s    s   Instruction instance expected(   R�   R›   R   R"   RS   Rb   t	   bytearrayR@   R#  RY   RP  R6  t   bytecodeR#   R£   t   BufferError(   R8   R¦   Rn   R:  (    (   R›   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR    1  s    	+c         C  s  d d l  m } t | | ƒ s+ t d ƒ ‚ | j |  j |  j | | ƒ \ } } |  j |  j t | ƒ k r|  j t | ƒ 7_ | rÄ | d  k	 rÄ | |  j t | ƒ } t
 | d |  j ƒ } n	 |  j } | | _ | | | f |  j t |  j ƒ <|  j j | ƒ n	 t ƒ  ‚ d  S(   Niÿÿÿÿ(   R¬   s#   BranchInstruction instance expectedi€   (   R�   R¬   R   RS   t   _encode_label_branchRu  RY   R6  RP  R   t   minR:  R7  R#   R£   R;  (   R8   Rn   t   label_addresst   long_encodingR¬   R:  t
   branch_post   branch_pos_max(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   add_label_branch?  s    	%		c           s#  d d l  m ‰  d d l m ‰ t ‡  ‡ f d †  ˆ j Dƒ ƒ rF d  S‡ f d †  } xÇ ˆ j ˆ j k  rg  ˆ j D] } t | | ƒ ƒ rt | ^ qt } | s¢ Pn  t | d d „  ƒ} t | | ƒ d t	 j
 d ƒ ƒ\ } } ˆ j | t | j ƒ 7_ ˆ j ˆ j k st ‚ | | _ qX Wd  S(	   Niÿÿÿÿ(   R¬   (   Rœ   c         3  s$   |  ] } t  | ˆ  ˆ f ƒ Vq d  S(   N(   R   (   R–   Rn   (   R¬   Rœ   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>\  s    c           s^   g  t  j |  j ƒ  ƒ D]D \ } } d | t |  j ƒ k  oI ˆ  j k n r | | f ^ q S(   Ni    (   RË   RÌ   t   encode_length_optionsRP  R:  R8  (   Rn   t   lengtht   encoding(   R8   (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   suitable_encodings_  s    "R¸  c         S  s   t  |  j ƒ S(   N(   RP  R:  (   t   instr(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   h  R_   i   (   R�   R¬   R   Rœ   R0   R#   RY   R6  R=  R`   t
   itemgetterRP  R:  RS   (   R8   RF  RG  t   suitable_instructionst   shortest_suitable_instructiont   new_encodingt
   new_length(    (   R¬   Rœ   R8   sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   optimizeX  s    ".c         C  sL   d d l  m } x) |  j |  j k r; |  j | ƒ  g ƒ q W|  j |  _ d  S(   Niÿÿÿÿ(   t   NOP(   R  RN  R6  RY   R    (   R8   RN  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR~   o  s    c         C  sl   d d l  m } t ƒ  } |  j } xC |  j D]8 } t | | ƒ rQ | | | j <q, | t | j ƒ 7} q, W| S(   Niÿÿÿÿ(   Rœ   (	   R   Rœ   R&   Ru  R#   R   RŸ   RP  R:  (   R8   Rœ   t   label_address_mapt   code_addressRn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRO  u  s    		c         C  s   |  j  S(   N(   RY   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __len__�  s    N(   R  R  R;   R	  R8  R    R   RÃ   RB  RM  R~   RO  RQ  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR5  "  s   	
			R"  c           B  sk   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e j	 e
 d „ Z d e j	 d „ Z d	 „  Z RS(
   s�   ABI-specific x86-64 assembly function.

    A function consists of C signature, ABI, and a list of instructions without virtual registers.
    c         C  sP  d d l  m  } m } t | t ƒ s1 t d ƒ ‚ | j |  _ | j |  _ t t | | j	 ƒ ƒ |  _	 | j
 |  _
 | j |  _ | j |  _ d d l m } m } d d l m } |  j | k rä | | j d d ƒ|  _ d |  j _ n$ | | j d d	 ƒ|  _ d
 |  j _ | | j ƒ |  _ | | j ƒ |  _ t ƒ  |  _ |  j ƒ  |  j ƒ  d  S(   Niÿÿÿÿ(   RÖ   Rr  s   ABIFunction object expected(   t   Sectiont   SectionType(   R|  t   alignment_byteiô   i    iÌ   i   (   RÖ   Rr  R   Rª   RS   R   R–  R"   RA   R   R   R   R}   t   peachpy.x86_64.metaRR  RS  R©   R|  Rl  t   code_sectionRº  t
   const_datat   const_sectionR#   R&   t   _constant_symbol_mapt   _layout_literal_constantst   _encode(   R8   RŠ   RÖ   Rr  RR  RS  R|  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   ‹  s(    
c         C  s7  d d l  m } d d l m } m } | |  j j ƒ } t ƒ  } x6 |  j D]+ } | j	 } | d  k	 rK | j | ƒ qK qK Wd } d }	 | r» t d „  | Dƒ ƒ } t d „  | Dƒ ƒ }	 n  |	 |  j _ t ƒ  }
 t ƒ  } | d k rt ƒ  } x|  j D]} | j	 } | d  k	 rø t | j | ƒ ƒ } | | k r’| j | k sOt d ƒ ‚ | j |	 k sjt d ƒ ‚ t |  j ƒ | | <|  j j | 7_ n  | j | k rü| j | j ƒ | | | | j d	 | j d
 | j ƒ} |
 j | ƒ | |  j | j <qüqø qø Wn  x- t |
 d d „  ƒD] } |  j j | ƒ qWd  S(   Niÿÿÿÿ(   t   Encoder(   t   Symbolt
   SymbolTypei    c         s  s   |  ] } | j  Vq d  S(   N(   RY   (   R–   R¡   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>¶  s    c         s  s   |  ] } | j  Vq d  S(   N(   Rº  (   R–   R¡   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pys	   <genexpr>·  s    sQ   Handling of functions with constant literals of different size is not implementedsV   Handling of functions with constant literals of different alignment is not implementedR   RY   R¸  c         S  s   |  j  |  j f S(   N(   t   offsetRY   (   t   sym(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   Ö  R_   (   t   peachpy.encoderR\  RU  R]  R^  R}   t
   endiannessR"   R#   R¡   R   R£   R½  RX  Rº  R$   R&   t   bytesR#  RY   RS   RP  t   contentR   R    t   literal_constantRY  R  t
   add_symbol(   R8   R\  R]  R^  t   encodert	   constantsRn   R¡   t   max_constant_sizet   max_constant_alignmentt   constant_symbolst   constant_names_sett   constants_address_mapt   constant_valuet   const_symbolt   constant_symbol(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRZ  ¨  sN    								
		c      
   C  ss  d d l  m } d d l m } t ƒ  } t ƒ  } d d l m } |  j | k rht	 } t	 } t
 ƒ  } xŒ| su | rôd }	 t } t } t
 ƒ  } t d |	 ƒ }
 xBt |  j ƒ D]1\ } } t | | ƒ rê |	 | | j <|
 j | g ƒ næt | | ƒ rà| j rà| j | j ƒ } | d  k r)t	 } n  | | k } | j |	 | d | ƒ\ } | _ | ry| ry| j | ƒ t	 } n  y |
 j | | | ƒ WqÐt k
 rÜ| j |
 ƒ t d |
 j |
 j ƒ }
 |
 j | | | ƒ qÐXnð | g } | j } d d l m } t | | ƒ rx| j d  k	 rxd d	 l  m! } | ƒ  �: d d
 l" m# } | j$ d | | j j% | j j% ƒ ƒ Wd  QXn  y |
 j | ƒ WnD t k
 rÏ| j |
 ƒ t d |
 j |
 j ƒ }
 |
 j | ƒ n X|
 j |
 j& }	 q¯ W| j |
 ƒ qi Wt
 ƒ  |  _ xk| D]Y} | j' ƒ  xÔ | j D]É } | j( } | rÊ| j) } x. t* | j+ | j+ d ƒ D] } d | j | <qZW| j+ t, |  j- ƒ 7_+ | j. t, |  j- ƒ 7_. |  j/ | j( j0 | _1 |  j- j2 | ƒ n  | j r"|  j- j3 | j 7_3 q"q"W| j& | j k  r| | d k	 r9|  j- j3 |  j4 | j | j& ƒ 7_3 qa|  j- j3 |  j5 | j | j& ƒ 7_3 qqWnt	 } t	 } x!| sƒ| r—d }	 t } t } xü t |  j ƒ D]ë \ } } t | | ƒ rÐ|	 | | j <n¡ t | | ƒ rb| j rb| j | j ƒ } | d  k rt	 } n  | | k } | j |	 | d | ƒ\ } | _ | rq| rq| j | ƒ t	 } qqn | j6 ƒ  | _ | j r¥|	 t, | j ƒ 7}	 q¥q¥WqwWxÔ |  j D]É } | j( } | rJ| j) } x. t* | j+ | j+ d ƒ D] } d | j | <qÚW| j+ t, |  j- ƒ 7_+ | j. t, |  j- ƒ 7_. |  j/ | j( j0 | _1 |  j- j2 | ƒ n  | j r¢|  j- j3 | j 7_3 q¢q¢Wd  S(   Niÿÿÿÿ(   Rœ   (   R¬   (   R|  i    i    R?  (   Rò  (   t
   NullStream(   RÙ  i   (7   R   Rœ   R�   R¬   R&   R$   R©   R|  R}   Rï   R"   RÃ   R5  R�   R#   R   RŸ   R    R®   R×   R   R<  R:  RB  R;  R£   Ru  R6  R¿  Rø  Rò  R—  R‡   Rq  R  RÙ  R«   R§  RY   RM  R¡   t
   relocationt   rangeR_  RP  RV  t   program_counterRY  R   R$  t   add_relocationRd  t   _encode_nopst   _encode_abortR#  (   R8   Rœ   R¬   RO  t   long_branchesR|  t   has_updated_branchest   has_unresolved_labelst   bundlesRP  t   current_bundleR“   Rn   R>  t   was_longt   is_longt   instruction_groupR¿  Rò  Rq  RÙ  t   bundleR¡   Rr  R—  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR[  Ù  sÒ    								
	%
		 	(/				 	c         C  s–   d | k o d k n s" t  ‚ d d l m } | d k rH | | ƒ S| d k rt | | d ƒ | | | d ƒ S| d ƒ | d ƒ | d ƒ Sd  S(	   Ni   i   iÿÿÿÿ(   t   nopi   i   i   i   (   RS   t   peachpy.x86_64.encodingR�  (   R8   RD  R�  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRv  O  s    "
 c         C  ss   d d l  m } m } m } |  j | k r< t d g | ƒ S|  j | | h k r^ t d g ƒ St d g | ƒ Sd  S(   Niÿÿÿÿ(   R|  R  R€  iô   iÍ   (   R©   R|  R  R€  R}   R9  (   R8   RD  R|  R  R€  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRw  Y  s    R   c         C  s…   g  } xI |  j  D]> } | j | j d | ƒ ƒ | j | j d | d | ƒ ƒ q W| d k rb | St | ƒ j t d „  | ƒ ƒ Sd S(   s=   Returns code of assembly instructions comprising the functionRj  R  c         S  s
   |  d  k	 S(   N(   R   (   t   line(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR^   o  R_   N(   R#   R£   t   format_encodingR¢   R   R   R@   R  (   R8   R  Rk  Rj  Rl  Rn   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR  e  s    #c         C  sÌ   | d k rX d |  j  |  j f g } | j d ƒ | j d ƒ d d j | ƒ g } n g  } | j |  j | d d
 d t ƒƒ | d k rœ | j d	 ƒ n  | d
 k r¬ | St | ƒ j t	 t
 | ƒ ƒ Sd
 S(   sJ   Formats assembly listing of the function according to specified parametersR  s
   %sÂ·%s(SB)R  s   $0s   TEXT R  Rk  Rj  R_   N(   t   package_nameR   R£   R@   Rö  R  R   Rï   R   R  Rc   (   R8   R  Rk  R  Rl  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR¢   q  s    "c         C  s
   t  |  ƒ S(   N(   t   ExecutableFuntion(   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   loadˆ  s    (   R  R  Rn  R;   RZ  R[  Rv  Rw  Rp  Rq  Rï   R  R¢   R‡  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR"  …  s   		1	v	
	R†  c           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  sê  t  | t ƒ s t d ƒ ‚ d d  l } | j j j ƒ  } | | j k rp t d t | j ƒ t | ƒ f ƒ ‚ n  t	 | j
 j ƒ |  _ t	 | j j ƒ |  _ d d  l } | j j t |  j ƒ t |  j ƒ ƒ |  _ d d l m } d d l m } x>| j
 j D]0} | j | j k st ‚ | j | j j k s6t ‚ |  j | j |  j | j d d >B|  j | j d d	 >B|  j | j d
 d >B} | |  j j | j j |  j j | j } | | ƒ sÅt ‚ | d @|  j | j <| d ?d @|  j | j d <| d	 ?d @|  j | j d <| d ?d @|  j | j d
 <qý W| j j sDt ‚ |  j j  |  j ƒ |  j j! |  j ƒ d d  l" }	 | j# d  k r‹d  n	 | j# j% }
 g  | j& D] } | j' j% ^ q¡} |	 j( |
 | Œ |  _) |  j) |  j j ƒ |  _* d  S(   Ns   EncodedFunction object expectediÿÿÿÿs1   Function ABI (%s) does not match process ABI (%s)(   t   RelocationType(   Ræ  i   i   i   i   i   i   iÿ   (+   R   R"  RS   R©   R   R}   t   detectRŒ   R   R9  RV  Rd  t   code_segmentRX  t   const_segmentt   peachpy.loadert   loadert   LoaderRP  RU  Rˆ  R·  Ræ  t   relocationsR&  t
   rip_disp32R$  t   symbolsR_  t   data_addressRP  Rt  t	   copy_codet	   copy_datat   ctypesR   R   t   as_ctypes_typeR   R1   t	   CFUNCTYPEt   function_typet   function_pointer(   R8   RŠ   R   t   process_abiRˆ  Ræ  Rr  t	   old_valuet	   new_valueR•  R   R:   t   argument_types(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   �  s@    "*9 !"c         G  s   |  j  | Œ  S(   N(   R™  (   R8   R’   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __call__¸  s    c         C  s   |  `  d  |  _  d  |  _ d  S(   N(   R�  R   R™  (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __del__»  s    	(   R  R  R;   Rž  RŸ  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR†  Œ  s   	+	t   LocalVariablec           B  s›   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „  ƒ Z
 e	 d „  ƒ Z e	 d „  ƒ Z e	 d	 „  ƒ Z e	 d
 „  ƒ Z e	 d „  ƒ Z RS(   c         C  s!  d d l  m } | d  k	 rB | | ƒ rB t d t | ƒ ƒ ‚ n  | d  k	 rm | d k rm t d | ƒ ‚ n  | |  _ | | ƒ r­ | d k r¡ t d | ƒ ‚ n  | |  _ n7 t | t	 j
 j j ƒ rÔ | j |  _ n t d | ƒ ‚ |  j d  k r|  j |  _ n  d  |  _ d |  _ d  |  _ d  S(   Niÿÿÿÿ(   Rç  s   alignment %s is not an integeri    s&   alignment %d is not a positive integers!   size %d is not a positive integers?   Unsupported size specification %s: register or integer expected(   R·  Rç  R   R   R   RŒ   Rº  RY   R   R   R   t	   registersRÕ   R¾  t   _offsett   parent(   R8   t   size_optionRº  Rç  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR;   Â  s$    			c         C  sC   t  | t ƒ oB |  j | j k oB |  j | j k oB |  j | j k S(   N(   R   R   R¼  RY   R_  (   R8   t   other(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __eq__×  s    !c         C  sD   t  | t ƒ pC |  j | j k	 pC |  j | j k pC |  j | j k S(   N(   R   R   R¼  RY   R_  (   R8   R¥  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRO  Û  s    "c         C  s'   t  |  j ƒ t |  j ƒ At |  j ƒ AS(   N(   R3  R¼  t   hashRY   R_  (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   __hash__ß  s    c         C  sO   |  j  d  k	 r$ d t |  j  ƒ d Sd t |  j ƒ |  j |  j |  j f Sd  S(   Nt   [t   ]s   local-variable<%d[%d:%d]>(   Ru  R   R   R3  R¼  R_  RY   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRß   â  s    c         C  s
   t  |  ƒ S(   N(   R   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRà   è  s    c         C  s   |  j  d  k	 S(   N(   R£  R   (   R8   (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   is_subvariableë  s    c         C  s)   |  } x | j  d  k	 r$ | j  } q	 W| S(   N(   R£  R   (   R8   R¼  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR¼  ï  s    c         C  s<   |  } d } x) | j  d  k	 r7 | | j 7} | j  } q W| S(   Ni    (   R£  R   R¢  (   R8   t   nodeR_  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR_  ö  s    c         C  s:   |  j  r/ |  j j } | d  k	 r6 | |  j Sn |  j Sd  S(   N(   R«  R¼  Ru  R   R_  R¾  (   R8   t   base_address(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyRu  ÿ  s
    	c         C  sX   |  j  d d k s t ‚ t |  j  d t |  j  d |  j ƒ ƒ } |  | _ d | _ | S(   Ni   i    (   RY   RS   R   R=  Rº  R£  R¢  (   R8   t   child(    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   lo  s
    )		c         C  s_   |  j  d d k s t ‚ t |  j  d t |  j  d |  j ƒ ƒ } |  | _ |  j  d | _ | S(   Ni   i    (   RY   RS   R   R=  Rº  R£  R¢  (   R8   R®  (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   hi  s
    )	N(   R  R  R   R;   R¦  RO  R¨  Rß   Rà   R	  R«  R¼  R_  Ru  R¯  R°  (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyR   Á  s   							(   t
   __future__R    Rp  R`   R  R½   RË   R   t   peachpy.writerR   R�   R4   R   R-  RU  R   R‘   Rª   R5  R"  R†  R   (    (    (    sD   /torch/pytorch/third_party/python-peachpy/peachpy/x86_64/function.pyt   <module>   s4   ÿ ÿ ÿ g#ÿ ÿ ˆcÿ 5