o
    ºió  ã                   @   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 dS )z1Add missing symbol into LLVM internal symtab
    N)ÚllÚaddress_of_symbolÚ
add_symbol)ÚsymbolÚaddr© r   úQ/home/ubuntu/veenaModal/venv/lib/python3.10/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_modÚi64Úi128Ú
lower_maskÚ_32Ú_64Úfn_typeÚfnÚaÚbÚbbÚbuilderÚalÚblÚahÚbhÚrlÚtÚrhÚrr   r   r   Úcompile_multi3   sV   






ÿ
ÿ
ÿ

rG   c                   @   ó   e Zd ZdZdd„ ZdS )Ú
_InstallerFc                 C   s   | j s|  |¡ d| _ dS 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__rJ   rM   r   r   r   r   rI   h   s    rI   c                   @   rH   )Ú_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¡r|rtdƒ}td|ƒ ntj d¡r0|r0td|d ƒ td|d	 ƒ |rFt	|ƒ| _
| j
 d
¡}|sAJ ‚td|ƒ tjD ]
}t ||| ¡ qId S )Nr   Úwin32Ú_ftolÚ_ftol2ÚlinuxÚ__fixunsdfdiÚfptouiÚ__fixunssfdiÚfptouifr   Ú__multi3)r   ÚMACHINE_BITSr   Ú	c_helpersÚsysÚplatformÚ
startswithr   r   rG   Ú_multi3_libÚget_pointer_to_functionr   Ú	INTR_MATHr   r   )rL   r1   Úis32bitr\   ÚftolÚptrÚfnamer   r   r   rK   |   s    



ûz"_ExternalMathFunctions._do_installN)rN   rO   rP   Ú__doc__rK   r   r   r   r   rQ   v   s    rQ   )rg   r]   Úllvmliter   Úllvmlite.bindingÚbindingr   Ú
numba.corer   r   Únumbar   r   r   rG   ÚobjectrI   rQ   Úc_math_functionsr   r   r   r   Ú<module>   s    
I
%