
    h#&                    <   S SK Jr  S SKrS SKrS SKJrJrJrJrJrJ	r	J
r
  S SKJr   \R                  S:H  r\R                  " \R                  5      S:H  rSS jrSS jr/ S	Qr/ S
Qr/ SQrSrSrSrSr " S S\R4                  5      r " S S5      rSS jrSS jrg)    )annotationsN)	CFUNCTYPEPOINTERc_longc_size_tc_uint32c_ulongc_void_p)ClassVarnt   c                 &    SS K Jn   U R                  $ Nr   )polars._plr_plrRUNTIME_REPR)plrs    K/home/james-whalen/.local/lib/python3.13/site-packages/polars/_cpu_check.pyget_runtime_reprr   +   s        c                     [         R                  " 5       R                  S:X  a  [        R                  " SSS9$ [        R                  " SSS9$ ! [
         a-    SSKJn   [        R                  " U R                  S5      SS9s $ f = f)	NDarwinz
libc.dylibT)	use_errnoz	libc.so.6r   )utilc)osunamesysnamectypesCDLL	Exceptionr   find_library)ctutils    r   _open_posix_libcr$   1   sn    E88:);;|t<<;;{d;; E){{6..s3tDDEs   7A A 4BB)S         r&            r&      r&   _      r&   O   r   r&   W      [      )r%   r&      I   r&      D   r&      r)   r*   A   r&      r8   r&   Y   r-   r8   r&   r4   r   r8   r&   Q   r0   r1   r2   )r%   r/      |   $   r0   r<   r6   r>      r<   L   r>      r)   r*   r&   r+   r&   r,   r-   r&   r.   r   r&   r/   r0   r,   r1   r2          i   @   c                  f    \ rS rSr% S V VVs/ s H
  o[        4PM     snnn rS\S'   Srgs  snnn f )CPUID_struct~   )eaxebxecxedxz ClassVar[list[tuple[str, type]]]_fields_ N)__name__
__module____qualname____firstlineno__r   rL   __annotations____static_attributes__).0rr   s   000r   rF   rF   ~   s+    ;2;!H;2H.  2s   ,rF   c                  6    \ rS rSrSS jrSS	S jjrSS jrSrg)
CPUID   c                   [         (       aS  [        (       a"  [        R                  " S5      U l        [
        nO=[        R                  R                  U l        [        nO[        (       a  [        O[        n[        U5      n[        R                  U-  " U6 n[         (       a  [        U R                  R                  l        [        R                  [        R                  [        R                   [        R                   /U R                  R                  l        U R                  R                  S U[$        [&        -  [(        5      U l        U R*                  (       d  Sn[-        U5      e[        R.                  " U R*                  X25        GOBSS Kn[3        5       nUR4                  n[        R                  [        R                  [        R6                  4Ul        [        R6                  Ul        UR1                  SUUR8                  UR:                  -  UR<                  UR>                  -  5      U l        [        R@                  " [        R                  RC                  U R0                  5      5      U l        U R0                  RE                  U5        U" U R*                  X%R<                  URF                  -  5      S:w  a  Sn[I        U5      e[K        S [M        [N        5      [P        [P        5      nU" U R*                  5      U l)        g )Nzkernel32.dllz)could not allocate memory for CPUID checkr   z*could not execute mprotect for CPUID check)*_IS_WINDOWS	_IS_64BITr   r    win_WINDOWS_64_OPCwindllkernel32_CDECL_32_OPC_POSIX_64_OPClenc_ubyter
   VirtualAllocrestyper   r	   argtypes_MEM_COMMIT_MEM_RESERVE_PAGE_EXECUTE_READWRITEaddrMemoryErrormemmovemmapr$   mprotectc_intMAP_PRIVATEMAP_ANONYMOUS	PROT_READ
PROT_WRITE	addressoffrom_bufferwrite	PROT_EXECRuntimeErrorr   r   rF   r   func_ptr)	selfopcsizecodemsgrn   libcro   	func_types	            r   __init__CPUID.__init__   s   ;y ";;~6%
 "==11##,9--C3x%,;,4DHH!!)	.DHH!!* --dK,68ODI 99A!#&&NN499d1 $%D}}H!'&//6<< PH%||H		  4#5#550	DI (()D)DTYY)OPDIIIOOD!		4$..)HIQNB"3''dGL$98XN	!$)),r   c                >    [        5       nU R                  X1U5        U$ )N)rF   rz   )r{   rH   rJ   structs       r   __call__CPUID.__call__   s    f3'r   c                   [         (       au  [        U R                  R                  l        [
        [        [        /U R                  R                  l        U R                  R                  U R                  S[        5        g g r   )r[   r   r]   VirtualFreerf   r
   r   r	   rg   rk   _MEM_RELEASE)r{   s    r   __del__CPUID.__del__   sQ    ;+1DHH  (-5x,IDHH  )HH  A|< r   )rk   rz   rn   r]   N)returnNone)r   )rH   intrJ   r   r   rF   )rN   rO   rP   rQ   r   r   r   rS   rM   r   r   rW   rW      s    ;-z
=r   rW   c                    [        5       n U " SS5      nU " SS5      nU " SS5      n[        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S	-  5      [        UR                  S
-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      [        UR                  S-  5      S.$ )Nr9   r   r+   l       i   rB   rC   i   i   i  @ i      i   r          )sse3ssse3fma
cmpxchg16bzsse4.1zsse4.2movbepopcnt	pclmulqdqavxbmi1bmi2avx2lzcnt)rW   boolrJ   rI   )cpuidcpuid1cpuid7cpuid81hs       r   _read_cpu_flagsr      s%   GE1a[F1a[FZ#H VZZ6*+fjjF+,FJJ'*+6::12vzzW-.vzzW-.fjjG,-vzzW-.&**/0FJJ'*+VZZ6*+VZZ6*+VZZ6*+hllf-. r   c                   U (       a$  [         R                  R                  S5      (       a  g U R                  S5       Vs/ s H  oR	                  S5      PM     nn[        5       n/ nU H5  nX;  a  SU< 3n[        U5      eX1   (       a  M$  UR                  U5        M7     U(       a-  SS KnUR                  SSR                  U5       S3[        S	S
9  g g s  snf )NPOLARS_SKIP_CPU_CHECK,+zunknown feature flag: r   z[Missing required CPU features.

The following required CPU features were not detected:
    z, a  
Continuing to use this version of Polars on this processor will likely result in a crash.
Install the `polars-lts-cpu` package instead of `polars` to run Polars with better compatibility.

Hint: If you are on an Apple ARM machine (e.g. M1) this is likely due to running Python under Rosetta.
It is recommended to install a native version of Python that does not run under Rosetta x86-64 emulation.

If you believe this warning to be a false positive, you can set the `POLARS_SKIP_CPU_CHECK` environment variable to bypass this check.
r9   )
stacklevel)r   environgetsplitlstripr   ry   appendwarningswarnjoinRuntimeWarning)feature_flagsfexpected_cpu_flagssupported_cpu_flagsmissing_featuresr   r   s          r   check_cpu_flagsr      s    BJJNN+BCC1>1D1DS1IJ1IA((3-1IJ)+'*1%0Cs##"%%##A&    
YY ! "  	 	
  Ks    C)r   str)r   zctypes.CDLL)r   zdict[str, bool])r   r   r   r   )
__future__r   r   r   r   r   r   r   r   r	   r
   typingr   namer[   sizeofr\   r   r$   rb   r^   ra   rh   ri   r   rj   	StructurerF   rW   r   r   rM   r   r   <module>r      s   0 #  	 T T T  ggoMM&//*a/	
E4$  6## G= G=T2"
r   