U
    ,‰dó  ã                   @   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)ÚllZaddress_of_symbolÚ
add_symbol)ÚsymbolÚaddr© r
   ú8/tmp/pip-unpacked-wheel-eu7e0c37/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)ÚcodegenZcreate_libraryZcreate_ir_moduler   ZIntTypeÚConstantÚFunctionTypeZFunctionÚargsZappend_basic_blockZ	IRBuilderÚtruncZashrÚmulÚand_ZlshrÚaddZshlZzextÚretZadd_ir_moduleÚfinalize)Úcontextr   ZlibraryZir_modZi64Zi128Z
lower_maskZ_32Z_64Zfn_typeÚfnÚaÚbZbbZbuilderÚalÚblZahZbhZ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)Úselfr%   r
   r
   r   Úinstalll   s    
z_Installer.installN)Ú__name__Ú
__module__Ú__qualname__r/   r2   r
   r
   r
   r   r.   h   s   r.   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__fixunsdfdiZfptouiZ__fixunssfdiZfptouifr   Z__multi3)r   ZMACHINE_BITSr   Ú	c_helpersÚsysÚplatformÚ
startswithr   r   r-   Z_multi3_libZget_pointer_to_functionÚAssertionErrorr   Z	INTR_MATHr   r   )r1   r%   Zis32bitr9   ZftolÚptrÚfnamer
   r
   r   r0   |   s    



z"_ExternalMathFunctions._do_installN)r3   r4   r5   Ú__doc__r0   r
   r
   r
   r   r6   v   s   r6   )r@   r:   Zllvmliter   Zllvmlite.bindingZbindingr   Z
numba.corer   r   Znumbar   r   r   r-   Úobjectr.   r6   Zc_math_functionsr
   r
   r
   r   Ú<module>   s   
I%