U
    ú¾|eó  ã                   @   s‚   d Z ddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ dd„ Zdd	„ Zd
d„ ZG dd„ deƒZG dd„ deƒZeƒ ZdS )zD
Register external C functions necessary for Numba code generation.
é    N)Úir)ÚutilsÚ
intrinsics)Ú
_helperlibc                 C   s   t  | ¡st  | |¡ dS )z1Add missing symbol into LLVM internal symtab
    N)ÚllÚaddress_of_symbolÚ
add_symbol)ÚsymbolÚaddr© r   úQ/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/externals.pyÚ_add_missing_symbol   s    
r   c                 C   s,   ddl m}m}m} t|j| ƒ}|||ƒjS )zr
    Under Windows, look up a symbol inside the C runtime
    and return the raw pointer value as an integer.
    r   )ÚcdllÚcastÚc_void_p)Úctypesr   r   r   ÚgetattrÚmsvcrtÚvalue)r	   r   r   r   Úfr   r   r   Ú_get_msvcrt_symbol   s    r   c              
   C   s@  |   ¡ }| d¡}| d¡}t d¡}t d¡}t |d¡}t |d¡}t |d¡}t |||g¡}	tj||	dd}
|
j\}}|
 	¡ }t 
|¡}| ||¡}| ||¡}| | ||¡|¡}| | ||¡|¡}| | ||¡| ||¡¡}| ||¡}| ||¡}| || | ||¡| ||¡¡¡}| || ||¡¡}| ||¡}| ||¡}| ||¡}| || | ||¡| ||¡¡¡}| || ||¡¡}| || ||¡¡}| || | ||¡| ||¡¡¡}| || ||¡¡}| || ||¡¡}| ||¡}| || | ||¡|¡¡}| |¡ | |¡ | ¡  |S )zo
    Compile the multi3() helper function used by LLVM
    for 128-bit multiplication on 32-bit platforms.
    Úmulti3é@   é€   l   ÿÿ é    )Úname)ÚcodegenÚcreate_libraryÚcreate_ir_moduler   ÚIntTypeÚConstantÚFunctionTypeÚFunctionÚargsÚappend_basic_blockÚ	IRBuilderÚtruncÚashrÚmulÚand_ÚlshrÚaddÚshlÚzextÚretÚadd_ir_moduleÚfinalize)Úcontextr   ÚlibraryÚir_modZi64Zi128Ú
lower_maskZ_32Z_64Zfn_typeÚfnÚaÚbÚbbÚbuilderÚalÚblZahÚbhÚrlÚtZrhÚrr   r   r   Úcompile_multi3   sV    






ÿ
ÿ
ÿ

r@   c                   @   s   e Zd ZdZdd„ ZdS )Ú
_InstallerFc                 C   s   | j s|  |¡ d| _ dS )z˜
        Install the functions into LLVM.  This only needs to be done once,
        as the mappings are persistent during the process lifetime.
        TN)Ú
_installedÚ_do_install)Úselfr1   r   r   r   Úinstalll   s    
z_Installer.installN)Ú__name__Ú
__module__Ú__qualname__rB   rE   r   r   r   r   rA   h   s   rA   c                   @   s   e Zd ZdZdd„ ZdS )Ú_ExternalMathFunctionszd
    Map the math functions from the C runtime library into the LLVM
    execution environment.
    c                 C   s¬   t jdk}tj}tj d¡r4|r4tdƒ}td|ƒ n,tj d¡r`|r`td|d ƒ td|d	 ƒ |rŒt	|ƒ| _
| j
 d
¡}|s‚t‚td|ƒ tjD ]}t ||| ¡ q’d S )Nr   Úwin32Z_ftolZ_ftol2ÚlinuxZ__fixunsdfdiÚfptouiZ__fixunssfdiÚfptouifr   Z__multi3)r   ÚMACHINE_BITSr   Ú	c_helpersÚsysÚplatformÚ
startswithr   r   r@   Z_multi3_libÚget_pointer_to_functionÚAssertionErrorr   Z	INTR_MATHr   r   )rD   r1   Úis32bitrO   ÚftolÚptrÚfnamer   r   r   rC   |   s    



z"_ExternalMathFunctions._do_installN)rF   rG   rH   Ú__doc__rC   r   r   r   r   rI   v   s   rI   )rY   rP   Úllvmliter   Úllvmlite.bindingÚbindingr   Ú
numba.corer   r   Únumbar   r   r   r@   ÚobjectrA   rI   Úc_math_functionsr   r   r   r   Ú<module>   s   
I%