
    hj;                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  S r " S S5      rS	 rS
 rS r\" \5      r " S S\5      r " S S\\5      r " S S\\5      rg)zDTypes and functions to manage information on CPU microarchitectures.    N   )FEATURE_ALIASES)LazyDictionaryc                 F   ^  [         R                  " T 5      U 4S j5       nU$ )z`Decorator that automatically converts a known target name to a proper
Microarchitecture object.
c                    > [        U[        5      (       a/  U[        ;  a  Sn[        UR	                  U5      5      e[        U   nT" X5      $ )Nz "{0}" is not a valid target name)
isinstancestrTARGETS
ValueErrorformat)selfothermsgfuncs      >lib/python3.13/site-packages/archspec/cpu/microarchitecture.py_impl"coerce_target_names.<locals>._impl   sE    eS!!G#8 E!233ENED      )	functoolswraps)r   r   s   ` r   coerce_target_namesr      s'    
 __T! ! Lr   c                       \ rS rSrSr\rSS jr\S 5       r	S r
\S 5       rS r\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       rS rS rS r\S 5       r\S 5       rS r\SS j5       rS rSrg)Microarchitecture%   a8  Represents a specific CPU micro-architecture.

Args:
    name (str): name of the micro-architecture (e.g. skylake).
    parents (list): list of parents micro-architectures, if any.
        Parenthood is considered by cpu features and not
        chronologically. As such each micro-architecture is
        compatible with its ancestors. For example "skylake",
        which has "broadwell" as a parent, supports running binaries
        optimized for "broadwell".
    vendor (str): vendor of the micro-architecture
    features (set of str): supported CPU flags. Note that the semantic
        of the flags in this field might vary among architectures, if
        at all present. For instance x86_64 processors will list all
        the flags supported by a given CPU while Arm processors will
        list instead only the flags that have been added on top of the
        base model for the current micro-architecture.
    compilers (dict): compiler support to generate tuned code for this
        micro-architecture. This dictionary has as keys names of
        supported compilers, while values are list of dictionaries
        with fields:

        * name: name of the micro-architecture according to the
            compiler. This is the name passed to the ``-march`` option
            or similar. Not needed if the name is the same as that
            passed in as argument above.
        * versions: versions that support this micro-architecture.

    generation (int): generation of the micro-architecture, if relevant.
    cpu_part (str): cpu part of the architecture, if relevant.
c                     Xl         X l        X0l        X@l        XPl        X`l        Xpl        S U l        S U l        S U l	        g N)
nameparentsvendorfeatures	compilers
generationcpu_part
_ancestors_generic_family)r   r   r   r   r    r!   r"   r#   s           r   __init__Microarchitecture.__init__J   s<    	 "$  r   c                    ^ U R                   cN  U R                  SS mU R                   H(  nTR                  U4S jUR                   5       5        M*     TU l         U R                   $ )z,All the ancestors of this microarchitecture.Nc              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr    ).0avalues     r   	<genexpr>.Microarchitecture.ancestors.<locals>.<genexpr>b   s     K(81UNQQ(8s   		)r$   r   extend	ancestors)r   parentr.   s     @r   r2   Microarchitecture.ancestors\   sS     ??"LLOE,,K(8(8KK '#DOr   c           	          [        [        U 5      /U R                   Vs/ s H  n[        U5      PM     sn-   5      $ s  snf )z9Returns a set of the nodes in this microarchitecture DAG.)setr	   r2   r   xs     r   _to_setMicroarchitecture._to_setf   s4     CI;$..!A.Q#a&.!AABB!As   =
c                    [        U[        5      (       d  [        $ U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r   )
r   r   NotImplementedr   r   r    r   r!   r"   r#   r   r   s     r   __eq__Microarchitecture.__eq__l   s    %!233!! II# 0u||+0/0 -0 %//1	0
 5#3#330 /	
r   c                 ,    [        U R                  5      $ r   )hashr   r   s    r   __hash__Microarchitecture.__hash__{   s    DIIr   c                     X:X  + $ r   r+   r=   s     r   __ne__Microarchitecture.__ne__~   s      r   c                 z    [        U[        5      (       d  [        $ U R                  5       UR                  5       :  $ r   r   r   r<   r9   r=   s     r   __lt__Microarchitecture.__lt__   -    %!233!!||~//r   c                      X:H  =(       d    X:  $ r   r+   r=   s     r   __le__Microarchitecture.__le__       04<0r   c                 z    [        U[        5      (       d  [        $ U R                  5       UR                  5       :  $ r   rI   r=   s     r   __gt__Microarchitecture.__gt__   rL   r   c                      X:H  =(       d    X:  $ r   r+   r=   s     r   __ge__Microarchitecture.__ge__   rP   r   c                 Z    U R                   R                  nUS-   nUR                  U 5      $ )Nz({0.name!r}, {0.parents!r}, {0.vendor!r}, {0.features!r}, {0.compilers!r}, generation={0.generation!r}, cpu_part={0.cpu_part!r}))	__class____name__r   )r   cls_namefmts      r   __repr__Microarchitecture.__repr__   s4    >>** ' ' 	
 zz$r   c                     U R                   $ r   r   rB   s    r   __str__Microarchitecture.__str__   s    yyr   c           	          [        U[        5      (       d.  Sn[        UR                  [        [	        U5      5      5      5      eXR
                  ;   a  g[        R                  R                  US 5      nU" U 5      $ )Nz3only objects of string types are accepted [got {0}]Tc                     g)NFr+   r8   s    r   <lambda>0Microarchitecture.__contains__.<locals>.<lambda>   s    ur   )	r   r	   	TypeErrorr   typer    r   feature_aliasesget)r   featurer   match_aliass       r   __contains__Microarchitecture.__contains__   se    '3''GCCJJs4='9:;; mm# (77;;G_U4  r   c                 :   U R                   c~  U /U R                  -    Vs/ s H  oR                  (       a  M  UPM     nnSnUSSR                  S U 5       5       S3-  n[        U5      S:X  d   U5       eUR	                  5       U l         U R                   $ s  snf )z9Returns the architecture family a given target belongs toz>a target is expected to belong to just one architecture familyz[found , c              3   8   #    U  H  n[        U5      v   M     g 7fr   r	   r,   r8   s     r   r/   +Microarchitecture.family.<locals>.<genexpr>   s     &=u!s1vvu   ]r   )r&   r2   joinlenpop)r   r8   rootsr   s       r   familyMicroarchitecture.family   s     <<!% 7K 71{{Q 7EKRCWTYY&=u&==>a@@Cu:?'C'? 99;DL|| Ls
   BBc                     U R                   cA  U /U R                  -    Vs/ s H  oR                  S:X  d  M  UPM     nn[        US S9U l         U R                   $ s  snf )zBReturns the best generic architecture that is compatible with selfgenericc                 ,    [        U R                  5      $ r   )rx   r2   rd   s    r   re   +Microarchitecture.generic.<locals>.<lambda>   s    AKK8Hr   )key)r%   r2   r   max)r   r8   genericss      r   r~   Microarchitecture.generic   sW     == $(6DNN#:T#:ahh)>S#:HT.HIDM}} Us
   AAc           
      $   [        U R                  5      [        U R                  5      [        S U R                   5       5      U R
                  U R                   Vs/ s H  n[        U5      PM     snU R                  U R                  S.$ s  snf )z3Returns a dictionary representation of this object.c              3   8   #    U  H  n[        U5      v   M     g 7fr   rr   rs   s     r   r/   ,Microarchitecture.to_dict.<locals>.<genexpr>   s     =}!s1vv}ru   )r   r   r    r"   r   r!   cpupart)	r	   r   r   sortedr    r"   r   r!   r#   r7   s     r   to_dictMicroarchitecture.to_dict   sk     		N$++&=t}}==//(,51A5}}
 	

 6s   Bc                     [        U S   U S    Vs/ s H  n[        U   PM     snU S   [        U S   5      U R                  S0 5      U R                  SS5      U R                  SS	5      S
9$ s  snf )z?Construct a microarchitecture from a dictionary representation.r   r   r   r    r!   r"   r   r    )r   r   r   r    r!   r"   r#   )r   r
   r6   rj   )datar8   s     r   	from_dictMicroarchitecture.from_dict   ss     !f)-i9AWQZ9>j)*hh{B/xxa0XXi,
 	
9s   A-
c                 N   XR                   R                  ;  a  gXR                  ;  aZ  U R                   Vs/ s H  o1UR                  ;   d  M  UPM     snS   nSnUR                  XUR                   5      n[	        U5      e[
        R                  " SU5      (       d  Sn[        U5      eU R                  U   nS nU Hv  nU" X5      (       d  M  US   n	UR                  SU R                  5        UR                  S	S
5      n
U
(       a  [        R                  " U
5        U	R                  " S0 UD6nUs  $    SnU(       a-  U Vs/ s H  o3S   PM	     nnUSSR                  U5       S3-  nOUS-  nUR                  U R                  X5      n[	        U5      es  snf s  snf )a  Returns a string containing the optimization flags that needs
to be used to produce code optimized for this micro-architecture.

The version is expected to be a string of dot separated digits.

If there is no information on the compiler passed as argument the
function returns an empty string. If it is known that the compiler
version we want to use does not support this architecture the function
raises an exception.

Args:
    compiler (str): name of the compiler to be used
    version (str): version of the compiler to be used

Raises:
    UnsupportedMicroarchitecture: if the requested compiler does not support
        this micro-architecture.
    ValueError: if the version doesn't match the expected format
r   r   zf'{0}' compiler is known to optimize up to the '{1}' microarchitecture in the '{2}' architecture familyz^(?:\d+\.)*\d+$zXinvalid format for the compiler version argument. Only dot separated digits are allowed.c                     U S   R                  S5      u  p#[        U5      u  p$[        U5      u  p4[        U5      u  pS nU" U5      nU(       a  U" U5      nX!:  a  gU(       a  U" U5      nX1:  a  gg)Nversions:c                 D    [        S U R                  S5       5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )int)r,   ys     r   r/   fMicroarchitecture.optimization_flags.<locals>.satisfies_constraint.<locals>.tuplify.<locals>.<genexpr>  s     <^SVV^ru   .)tuplesplit)vers    r   tuplifySMicroarchitecture.optimization_flags.<locals>.satisfies_constraint.<locals>.tuplify  s    <SYYs^<<<r   FT)r   version_components)entryversionmin_versionmax_version_r   s         r   satisfies_constraintBMicroarchitecture.optimization_flags.<locals>.satisfies_constraint  s    ',Z'8'>'>s'C$K 0<NK/<NK+G4JG= g&G%k2( %k2( r   flagsr   warningsNzIcannot produce optimized binary for micro-architecture '{0}' with {1}@{2}r   z" [supported compiler versions are rp   rv   z! [no supported compiler versions]r+   )r{   r!   r2   r   UnsupportedMicroarchitecturerematchInvalidCompilerVersion
setdefaultr   rj   r   warnrw   )r   compilerr   r8   best_targetr   compiler_infor   compiler_entry	flags_fmtwarning_messager   r   s                r   optimization_flags$Microarchitecture.optimization_flags   s   * ;;000 >>)&*nnPnAKK8O1nPQRSKF  **XK4F4FGC.s33 xx*G449  )-- x0	2 ,N#N<<*73	 ))&$))< #1"4"4Z"F"MM/2!((:>: , Z/<=}!*}H=7		(8K7LANNC66CjjH6*3//G Q| >s   FFF")
r$   r&   r%   r!   r#   r    r"   r   r   r   N)r   r   )returnr   )rY   
__module____qualname____firstlineno____doc__r   ri   r'   propertyr2   r9   r   r>   rC   rF   rJ   rN   rR   rU   r\   r`   rm   r{   r~   r   staticmethodr   r   __static_attributes__r+   r   r   r   r   %   s   D &O$  C 
 
 ! ! 0 0 1 1 0 0 1 1 ! 	 	  

 

 

^0r   r   c                 ,    [        U / S[        5       0 S9$ )z{Returns a generic micro-architecture with no vendor and no features.

Args:
    name (str): name of the micro-architecture
r~   )r   r   r    r!   )r   r6   r_   s    r   generic_microarchitecturer   A  s     T2i#%[]^^r   c                     [         R                  " S[        U 5      5      nU(       d  gUR                  S5      nUR                  S5      nX#4$ )zDecomposes the version passed as input in version number and
suffix and returns them.

If the version number or the suffix are not present, an empty
string is returned.

Args:
    version (str): version to be decomposed into its components
z([\d.]*)(-?)(.*))r   r   r      )r   r   r	   group)r   r   version_numbersuffixs       r   r   r   J  sB     HH(#g,7E[[^N[[^F!!r   c                     ^ U4S jm0 n [         R                  R                  R                  S   nU H  nX ;   a  M
  T" X!U 5        M     [        R
                  " 5       nU R                  U[        U5      5        U $ )zReturns a dictionary of the known micro-architectures. If the
current host platform is unknown adds it too as a generic target.
c           
      B  > X   nUS   nU H  nXR;   a  M
  T" XQU5        M     U Vs/ s H  oRR                  U5      PM     nnUS   n[        US   5      nUR                  S0 5      n	UR                  SS5      n
UR                  SS5      n[        XXxXUS	9X '   g
s  snf )a>  Recursively fills targets by adding the micro-architecture
passed as argument and all its ancestors.

Args:
    name (str): micro-architecture to be added to targets.
    data (dict): raw data loaded from JSON.
    targets (dict): dictionary that maps micro-architecture names
        to ``Microarchitecture`` objects
fromr   r    r!   r"   r   r   r   )r"   r#   N)rj   r6   r   )r   r   targetsvaluesparent_namesr3   r   r   r    r!   r"   r#   fill_target_from_dicts               r   r   8_known_microarchitectures.<locals>.fill_target_from_dictc  s      f~"F !&8	 #
 6BB\6;;v&\B!vj)*JJ{B/	ZZa0
::i,)6YX`
 Cs   Bmicroarchitectures)archspeccpuschemaTARGETS_JSONplatformmachiner   r   )known_targetsr   r   host_platformr   s       @r   _known_microarchitecturesr   ^  ss    

> M<<++,@AD d-8	  $$&M],Em,TUr   c                       \ rS rSrSrSrg)ArchspecErrori  z%Base class for errors within archspecr+   NrY   r   r   r   r   r   r+   r   r   r   r     s    /r   r   c                       \ rS rSrSrSrg)r   i  z[Raised if a compiler version does not support optimization for a given
micro-architecture.
r+   Nr   r+   r   r   r   r     s    r   r   c                       \ rS rSrSrSrg)r   i  zHRaised when an invalid format is used for compiler versions in archspec.r+   Nr   r+   r   r   r   r     s    Rr   r   )r   r   r   r   r   r   archspec.cpu.aliasarchspec.cpu.schemaaliasr   r   r   r   r   r   r   r   r
   	Exceptionr   r   r   r   r+   r   r   <module>r      s   
 K   	     " "$Y0 Y0x_"(0h 2
30I 0=* S]J Sr   