B «@`%tã @sÌdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z Gdd„dƒZ Gdd„dƒZ iZ Gdd„dƒZ Gd d „d eƒZGd d „d ƒZGd d„dƒZGdd„de e e eeeƒZdd„ZdS)aProvides the `CCompilerOpt` class, used for handling the CPU/hardware optimization, starting from parsing the command arguments, to managing the relation between the CPU baseline and dispatch-able features, also generating the required C headers and ending with compiling the sources with proper compiler's flags. `CCompilerOpt` doesn't provide runtime detection for the CPU features, instead only focuses on the compiler side, but it creates abstract C headers that can be used later for the final runtime dispatching process.éNc#@s2eZdZdZdZdZdZdZej   ej   ej   e ¡¡d¡ZiZdZdZeeddd d �eddd d �ed dd d �ed d dd �edddd �d�Zeddddddd�Zeedddd�edddd�ed dd!d�ed"d#d$d�ed%d&d'd�ed(d)d*d�ed+d,d-�ed.d/d0dd1�ed2d3d4d�ed5d3d4d�ed6d3d-�ed7d8d-�ed9d8d-�ed:d;ddd?d-�ed@dAdBdCddD�edEdCdFdGddD�edHdAdIdJddKdL�edMdJdNdOdP�edQdJdRdSddD�edTdUdVdWddD�eddXdY�eddZdd[�ed d\dd[�edd]dY�edd^d-�ed d_d-�ed"d`dd[�ed%dad-�ed(dad-�ed+dbd-�dc�Zddde„Zdfdg„ZdS)hÚ_ConfigaÊAn abstract class holds all configurable attributes of `CCompilerOpt`, these class attributes can be used to change the default behavior of `CCompilerOpt` in order to fit other requirements. Attributes ---------- conf_nocache : bool Set True to disable memory and file cache. Default is False. conf_noopt : bool Set True to forces the optimization to be disabled, in this case `CCompilerOpt` tends to generate all expected headers in order to 'not' break the build. Default is False. conf_cache_factors : list Add extra factors to the primary caching factors. The caching factors are utilized to determine if there are changes had happened that requires to discard the cache and re-updating it. The primary factors are the arguments of `CCompilerOpt` and `CCompiler`'s properties(type, flags, etc). Default is list of two items, containing the time of last modification of `ccompiler_opt` and value of attribute "conf_noopt" conf_tmp_path : str, The path of temporary directory. Default is auto-created temporary directory via ``tempfile.mkdtemp()``. conf_check_path : str The path of testing files. Each added CPU feature must have a **C** source file contains at least one intrinsic or instruction that related to this feature, so it can be tested against the compiler. Default is ``./distutils/checks``. conf_target_groups : dict Extra tokens that can be reached from dispatch-able sources through the special mark ``@targets``. Default is an empty dictionary. **Notes**: - case-insensitive for tokens and group names - sign '#' must stick in the begin of group name and only within ``@targets`` **Example**: .. code-block:: console $ "@targets #avx_group other_tokens" > group_inside.c >>> CCompilerOpt.conf_target_groups["avx_group"] = \ "$werror $maxopt avx2 avx512f avx512_skx" >>> cco = CCompilerOpt(cc_instance) >>> cco.try_dispatch(["group_inside.c"]) conf_c_prefix : str The prefix of public C definitions. Default is ``"NPY_"``. conf_c_prefix_ : str The prefix of internal C definitions. Default is ``"NPY__"``. conf_cc_flags : dict Nested dictionaries defining several compiler flags that linked to some major functions, the main key represent the compiler name and sub-keys represent flags names. Default is already covers all supported **C** compilers. Sub-keys explained as follows: "native": str or None used by argument option `native`, to detect the current machine support via the compiler. "werror": str or None utilized to treat warning as errors during testing CPU features against the compiler and also for target's policy `$werror` via dispatch-able sources. "maxopt": str or None utilized for target's policy '$maxopt' and the value should contains the maximum acceptable optimization by the compiler. e.g. in gcc `'-O3'` **Notes**: * case-sensitive for compiler names and flags * use space to separate multiple flags * any flag will tested against the compiler and it will skipped if it's not applicable. conf_min_features : dict A dictionary defines the used CPU features for argument option `'min'`, the key represent the CPU architecture name e.g. `'x86'`. Default values provide the best effort on wide range of users platforms. **Note**: case-sensitive for architecture names. conf_features : dict Nested dictionaries used for identifying the CPU features. the primary key is represented as a feature name or group name that gathers several features. Default values covers all supported features but without the major options like "flags", these undefined options handle it by method `conf_features_partial()`. Default value is covers almost all CPU features for *X86*, *IBM/Power64* and *ARM 7/8*. Sub-keys explained as follows: "implies" : str or list, optional, List of CPU feature names to be implied by it, the feature name must be defined within `conf_features`. Default is None. "flags": str or list, optional List of compiler flags. Default is None. "detect": str or list, optional List of CPU feature names that required to be detected in runtime. By default, its the feature name or features in "group" if its specified. "implies_detect": bool, optional If True, all "detect" of implied features will be combined. Default is True. see `feature_detect()`. "group": str or list, optional Same as "implies" but doesn't require the feature name to be defined within `conf_features`. "interest": int, required a key for sorting CPU features "headers": str or list, optional intrinsics C header file "disable": str, optional force disable feature, the string value should contains the reason of disabling. "autovec": bool or None, optional True or False to declare that CPU feature can be auto-vectorized by the compiler. By default(None), treated as True if the feature contains at least one applicable flag. see `feature_can_autovec()` "extra_checks": str or list, optional Extra test case names for the CPU feature that need to be tested against the compiler. Each test case must have a C file named ``extra_xxxx.c``, where ``xxxx`` is the case name in lower case, under 'conf_check_path'. It should contain at least one intrinsic or function related to the test case. If the compiler able to successfully compile the C file then `CCompilerOpt` will add a C ``#define`` for it into the main dispatch header, e.g. ```#define {conf_c_prefix}_XXXX`` where ``XXXX`` is the case name in upper case. **NOTES**: * space can be used as separator with options that supports "str or list" * case-sensitive for all values and feature name must be in upper-case. * if flags aren't applicable, its will skipped rather than disable the CPU feature * the CPU feature will disabled if the compiler fail to compile the test file FNZchecksZNPY_ZNPY__z -march=nativez-O3z-Werror)ÚnativeÚoptÚwerrorz-xHostz/QxHostz/O3z/Werrorz/O2z/WX)ÚgccÚclangÚiccÚiccwÚmsvczSSE SSE2z SSE SSE2 SSE3ÚzVSX VSX2zNEON NEON_FP16 NEON_VFPV4 ASIMD)Úx86Úx64Úppc64Úppc64leÚarmhfÚaarch64éz xmmintrin.hÚSSE2)ÚinterestÚheadersÚimplieséÚSSEz emmintrin.h)rrréz pmmintrin.héÚSSE3z tmmintrin.héÚSSSE3z smmintrin.héÚSSE41zpopcntintrin.héÚPOPCNT)rréÚSSE42z immintrin.h)rrrÚimplies_detecté ÚAVXz x86intrin.hé é é ÚF16Cé éz FMA3 AVX2ZAVX512F_REDUCE)rrr$Ú extra_checkséÚAVX512Fé(ÚAVX512CDzAVX512ER AVX512PFÚ AVX512_KNL)rrÚgroupÚdetectr$é)z)AVX5124FMAPS AVX5124VNNIW AVX512VPOPCNTDQÚ AVX512_KNMé*zAVX512VL AVX512BW AVX512DQÚ AVX512_SKXzAVX512BW_MASK AVX512DQ_MASK)rrr3r4r$r-é+Z AVX512VNNIÚ AVX512_CLX)rrr3r4é,zAVX512IFMA AVX512VBMIÚ AVX512_CNLé-zAVX512_CLX AVX512_CNLz(AVX512VBMI2 AVX512BITALG AVX512VPOPCNTDQÚ AVX512_ICLz altivec.h)rrÚVSX)rrr$ÚVSX2z arm_neon.hÚNEONÚ NEON_FP16zNEON_FP16 NEON_VFPV4ÚASIMDÚASIMDHP)rrrrrr!r#r&ÚXOPÚFMA4r*ÚFMA3ÚAVX2r/r1r2r6r8r:r<r>r?r@ÚVSX3rArBÚ NEON_VFPV4rCrDÚASIMDDPÚASIMDFHMcCs|jr iS|jp|j}|jp |j}|rÚ|rÚttdd�tdd�tdd�tdd�tdd�tdd�tdd�td d�td d�td d�td d�td d�tdd�tdd�tdd�tdd�tdd�tdd�tdd�tdd�tdd�d�S|�r”|j�r”ttdd�tdd�tdd�tdd�tdd�itdd�td d�itdd�tdd�tddd�tddd�tddd�td dd�td!d�td"d�td#d�td$d�td%d�td&d�d�S|�rN|j�rNttd'd�td(d�td)d�td*d�td+d�itd,d�td-d�itdd�tdd�tdd.d�tdd.d�tdd/d�td d/d�td0d�td1d�td2d�td3d�td4d�td5d�d�S|�rä|j�rättd'd�td(d�iiitd6d7�itd-d�itd8d7�td8d7�tdd9d�td:d9d�td;dd�td>d�tdz!Intel Compiler doesn't support it)Údisablez F16C AVX2z-march=core-avx2)rrMrGz AVX2 AVX512CDz-march=common-avx512z AVX2 AVX512Fz-xKNLz-xKNMz-xSKYLAKE-AVX512z -xCASCADELAKEz -xCANNONLAKEz-xICELAKE-CLIENTz /arch:SSEz /arch:SSE2z /arch:SSE3z /arch:SSSE3z /arch:SSE4.1z /arch:SSE4.2z /arch:AVXz/arch:CORE-AVX2z/Qx:COMMON-AVX512z/Qx:KNLz/Qx:KNMz/Qx:SKYLAKE-AVX512z/Qx:CASCADELAKEz/Qx:CANNONLAKEz/Qx:ICELAKE-CLIENTz nmmintrin.h)rz ammintrin.hz /arch:AVX2z F16C FMA3zAVX2 AVX512CD AVX512_SKXz /arch:AVX512zAVX512F AVX512_SKXz MSVC compiler doesn't support itr@r z-mvsxz -mcpu=power8F)rMr$z-mcpu=power9 -mtune=power9)r?r@rIz-maltivec -mvsxr?rMz-mpower8-vectorz-mpower9-vectorrIzNEON_FP16 NEON_VFPV4 ASIMDT)rÚautoveczNEON NEON_VFPV4 ASIMDzNEON NEON_FP16 ASIMDzNEON NEON_FP16 NEON_VFPV4z-march=armv8.2-a+fp16z-march=armv8.2-a+dotprodz-march=armv8.2-a+fp16fml)rArBrJrCrDrKrLz -mfpu=neonz"-mfpu=neon-fp16 -mfp16-format=ieeez-mfpu=neon-vfpv4z'-mfpu=neon-fp-armv8 -march=armv8-a+simd) Úcc_nooptÚ cc_on_x86Ú cc_on_x64Ú cc_is_gccÚ cc_is_clangÚdictÚ cc_is_iccÚ cc_is_iccwÚ cc_is_msvcÚ cc_on_ppc64leÚ cc_on_ppc64Ú cc_on_aarch64Ú cc_on_armhf)ÚselfZon_x86Zis_unixZon_powerÚpartial©r_úA/tmp/pip-unpacked-wheel-ecq9wray/numpy/distutils/ccompiler_opt.pyÚconf_features_partial*s>         z_Config.conf_features_partialcsb|jdkr@ddl}ddl‰| ¡‰‡‡fdd„}t |¡ˆ|_|jdkr^tj  t ¡|j g|_dS)Nrcs(yˆ ˆ¡Wntk r"YnXdS)N)ÚrmtreeÚIOErrorr_)ÚshutilÚtmpr_r`Úrm_tempsz!_Config.__init__..rm_temp) Ú conf_tmp_pathÚtempfilerdÚmkdtempÚatexitÚregisterÚconf_cache_factorsÚosÚpathÚgetmtimeÚ__file__Ú conf_nocache)r]rhrfr_)rdrer`Ú__init__s    z_Config.__init__)Ú__name__Ú __module__Ú __qualname__Ú__doc__rqÚ conf_nooptrlrgrmrnÚjoinÚdirnameÚrealpathrpÚconf_check_pathÚconf_target_groupsÚ conf_c_prefixÚconf_c_prefix_rUÚ conf_cc_flagsÚconf_min_featuresÚ conf_featuresrarrr_r_r_r`r s¾"                      Wrc@s”eZdZdZdd„Zdd„Zdd„Zdd „Zed d „ƒZ ed d „ƒZ eddœdd„ƒZ edd„ƒZ edd„ƒZ ddd„Ze d¡Zeddd„ƒZdS)Ú _Distutilsa¾A helper class that provides a collection of fundamental methods implemented in a top of Python and NumPy Distutils. The idea behind this class is to gather all methods that it may need to override in case of reuse 'CCompilerOpt' in environment different than of what NumPy has. Parameters ---------- ccompiler : `CCompiler` The generate instance that returned from `distutils.ccompiler.new_compiler()`. cCs ||_dS)N)Ú _ccompiler)r]Ú ccompilerr_r_r`rrsz_Distutils.__init__cKsDt|tƒst‚t|tƒst‚| dg¡|}|jj|fd|i|—ŽS)zWrap CCompiler.compile()Zextra_postargs)Ú isinstanceÚlistÚAssertionErrorÚpoprƒÚcompile)r]ÚsourcesrMÚkwargsr_r_r`Ú dist_compile"s z_Distutils.dist_compilec CsÎt|tƒst‚ddlm}|j}t|ddƒ}|rdt|jddƒ}|dkrVt|d|jƒnt|d|j ƒd}y|j |g||j d �d }Wn4|k r¸}z|j t|ƒd d �Wdd}~XYnX|rÊt|d|ƒ|S) zgReturn True if 'CCompiler.compile()' able to compile a source file with certain flags. r)Ú CompileErrorÚspawnNÚ compiler_typer )r F)Ú output_dirT)Ústderr) r…Ústrr‡Údistutils.errorsr�rƒÚgetattrÚsetattrÚ_dist_test_spawn_pathsÚ_dist_test_spawnrŒrgÚdist_log) r]ÚsourcerMr�ÚccZbk_spawnÚcc_typeÚtestÚer_r_r`Ú dist_test+s&  $ z_Distutils.dist_testcCsît|dƒr|jSt|jddƒ}|dkr,d}n |dkr:d}ndd lm}|ƒ}t|jd t|jd dƒƒ}|rp|d krŽt|d ƒr„|d}q’t|ƒ}n|}t|d ƒr¼t|ƒdkr¼d |dd…¡}n t j   dd¡}|t j   dd¡7}|||f|_|jS)a! Return a tuple containing info about (platform, compiler, extra_args), required by the abstract class '_CCompiler' for discovering the platform environment. This is also used as a cache factor in order to detect any changes happening from outside. Ú _dist_infor�r )ZintelemZintelemwÚx86_64)ÚintelZintelwZinteler r)Ú get_platformÚcompilerÚ compiler_soÚunixÚ__iter__rú NÚCFLAGSÚCPPFLAGS) ÚhasattrrŸr”rƒÚdistutils.utilr¢r’ÚlenrxrmÚenvironÚget)r]r›Úplatformr¢Zcc_infor£Ú extra_argsr_r_r`Ú dist_infoEs*       z_Distutils.dist_infocGsddlm}|tj|Žƒ‚dS)zRaise a compiler errorr)r�N)r“r�r‚Ú _dist_str)Úargsr�r_r_r`Ú dist_errorjs z_Distutils.dist_errorcGsddlm}|tj|Žƒ‚dS)zRaise a distutils errorr)ÚDistutilsErrorN)r“rµr‚r²)r³rµr_r_r`Ú dist_fatalps z_Distutils.dist_fatalF)r‘cGs4ddlm}tj|Ž}|r&| |¡n | |¡dS)zPrint a console messager)ÚlogN)Znumpy.distutilsr·r‚r²ÚwarnÚinfo)r‘r³r·Úoutr_r_r`r˜vs    z_Distutils.dist_logc CsLddlm}y |||ƒStk rF}ztj|dd�Wdd}~XYnXdS)zALoad a module from file, required by the abstract class '_Cache'.r)Únpy_load_moduleT)r‘N)Z numpy.compatr»Ú Exceptionr‚r˜)Únamernr»r�r_r_r`Údist_load_module€s    z_Distutils.dist_load_modulecsJ‡fdd„‰t ¡d}d|j|jf}d ‡fdd„|˜Dƒ¡}||S)z+Return a string to print by log and errors.csNt|tƒsFt|dƒrFg}x|D]}| ˆ|ƒ¡qWdd |¡dSt|ƒS)Nr¦ú(r§ú))r…r’rªÚappendrx)ÚargÚretÚa)Úto_strr_r`rÅ�s  z$_Distutils._dist_str..to_strrzCCompilerOpt.%s[%d] : r§csg|] }ˆ|ƒ‘qSr_r_)Ú.0rÄ)rÅr_r`ú ˜sz(_Distutils._dist_str..)ÚinspectÚstackÚfunctionÚlinenorx)r³rÉÚstartrºr_)rÅr`r²Šs    z_Distutils._dist_strNc CsRt|jdƒs| |¡dSt d¡}z|jjtjd<| |¡Wd|tjd<XdS)zŠ Fix msvc SDK ENV path same as distutils do without it we get c1: fatal error C1356: unable to find mspdbcore.dll Ú_pathsNrn)rªrƒr—rmÚgetenvrÍr­)r]ÚcmdÚdisplayÚold_pathr_r_r`r–�s   z!_Distutils._dist_test_spawn_pathsz/.*(warning D9002|invalid argument for option).*c Cs°ddlm}y:tj|tjdd�}|rDt tj|¡rDt  d|d|¡WnJtj k rv}z|j }|j }Wdd}~XYn t k r�d}d}YnXdSt  d |d ||f¡dS) Nr)r�T)r‘Úuniversal_newlineszFlags in commandz/aren't supported by the compiler, output -> %sóéÚCommandz(failed with exit status %d output -> %s)r“r�Ú subprocessÚ check_outputÚSTDOUTÚreÚmatchr‚Ú_dist_warn_regexr´ÚCalledProcessErrorÚoutputÚ returncodeÚOSError)rÏrÐr�ÚoÚexcÚsr_r_r`r—´s$    z_Distutils._dist_test_spawn)N)N)rsrtrurvrrrŒržr±Ú staticmethodr´r¶r˜r¾r²r–rÙr‰rÛr—r_r_r_r`r‚s   %    r‚c@sHeZdZdZe d¡Zddd„Zdd„Zdd „Z d d „Z e d d „ƒZ dS)Ú_Cachea#An abstract class handles caching functionality, provides two levels of caching, in-memory by share instances attributes among each other and by store attributes into files. **Note**: any attributes that start with ``_`` or ``conf_`` will be ignored. Parameters ---------- cache_path: str or None The path of cache file, if None then cache in file will disabled. *factors: The caching factors that need to utilize next to `conf_cache_factors`. Attributes ---------- cache_private: set Hold the attributes that need be skipped from "in-memory cache". cache_infile: bool Utilized during initializing this class, to determine if the cache was able to loaded from the specified cache path in 'cache_path'. z ^(_|conf_)NcGsfi|_tƒ|_d|_|jr(| d¡dS|j||jžŽ}|ròtj   |¡râ| d|¡|  d|¡}|st|jddd�nnt |dƒrˆt |d ƒs˜|jd dd�nJ||j krØ| d ¡x"|j ¡D]\}}t|||ƒq¸Wd|_n | d ¡t |j||¡|j�sZt |¡}|�rZ| d ¡xD|j ¡D]6\}}||jk�s t |j|¡�rH�q t|||ƒ�q W|t|<dS)NFzcache is disabled by `Config`zload cache from file ->Úcachez)unable to load the cache file as a moduleT)r‘ÚhashÚdatazinvalid cache filezhit the file cachezmiss the file cachezhit the memory cache)Úcache_meÚsetÚ cache_privateÚ cache_infilerqr˜Ú cache_hashrlrmrnÚexistsr¾rªrærçÚitemsr•rjrkÚ _cache_writeÚ _share_cacher®Ú__dict__rÙrÚÚ _cache_ignore)r]Ú cache_pathÚfactorsÚchashZ cache_modÚattrÚvalZ other_cacher_r_r`rrêsF             z_Cache.__init__cCsdS)Nr_)r]r_r_r`Ú__del__sz_Cache.__del__c Csª| d|¡x0t|j ¡ƒD]}t |j|¡r|j |¡qWtj   |¡}tj   |¡s`t  |¡t j|jdd�}t|dƒ�&}| t d¡ |¡¡| |¡WdQRXdS)Nzwrite cache to path ->T)ÚcompactÚwz¿ # AUTOGENERATED DON'T EDIT # Please make changes to the code generator (distutils/ccompiler_opt.py) hash = {} data = \ )r˜r†rñÚkeysrÙrÚròrˆrmrnryríÚmakedirsÚpprintÚpformatÚopenÚwriteÚtextwrapÚdedentÚformat)r]rórìröÚdÚ repr_dictÚfr_r_r`rïs     z_Cache._cache_writecGsLd}xB|D]:}x4t|ƒD](}t|ƒ|d>|d>|}|dM}qWq W|S)Nrrélÿÿ)r’Úord)r]rôrõrÚcharr_r_r`rì0s  z_Cache.cache_hashcs‡fdd„}|S)zr A static method that can be treated as a decorator to dynamically cache certain methods. csNtˆjf|| ¡| ¡˜ƒ}||jkr0|j|Sˆ|f|ž|Ž}||j|<|S)N)r’rsrûÚvaluesrè)r]r³r‹Ú cache_keyZccb)Úcbr_r`Ú cache_wrap_me@s   z _Cache.me..cache_wrap_mer_)r r r_)r r`Úme:s z _Cache.me)N) rsrtrurvrÙr‰ròrrrørïrìrãrr_r_r_r`räÍs  , räc@szeZdZdZdd„Zejdd„ƒZdd„Ze   d¡Z e   d ¡Z e   d ¡Z e   d ¡Zd d „Ze   d¡Ze   d¡Zdd„ZdS)Ú _CCompilerayA helper class for `CCompilerOpt` containing all utilities that related to the fundamental compiler's functions. Attributes ---------- cc_on_x86 : bool True when the target architecture is 32-bit x86 cc_on_x64 : bool True when the target architecture is 64-bit x86 cc_on_ppc64 : bool True when the target architecture is 64-bit big-endian PowerPC cc_on_armhf : bool True when the target architecture is 32-bit ARMv7+ cc_on_aarch64 : bool True when the target architecture is 64-bit Armv8-a+ cc_on_noarch : bool True when the target architecture is unknown or not supported cc_is_gcc : bool True if the compiler is GNU or if the compiler is unknown cc_is_clang : bool True if the compiler is Clang cc_is_icc : bool True if the compiler is Intel compiler (unix like) cc_is_iccw : bool True if the compiler is Intel compiler (msvc like) cc_is_nocc : bool True if the compiler isn't supported directly, Note: that cause a fail-back to gcc cc_has_debug : bool True if the compiler has debug flags cc_has_native : bool True if the compiler has native flags cc_noopt : bool True if the compiler has definition 'DISABLE_OPT*', or 'cc_on_noarch' is True cc_march : str The target architecture name, or "unknown" if the architecture isn't supported cc_name : str The compiler name, or "unknown" if the compiler isn't supported cc_flags : dict Dictionary containing the initialized flags of `_Config.conf_cc_flags` cCsJt|dƒrdSd}d}d}| ¡}|\}}}x0|||fD]"}x|D]\} } t|| dƒqBWq8WxR||f||ffD]>\} } x4| D],\} } | rœt | | tj¡sœq~t|| dƒPq~WqpWx2|D]*\} } | rÖt | |tj¡sÖq¸t|| dƒq¸W|j�r |jd|›d�dd �d|_|j �r&|jd dd �d|_|j �rJ|jd |›d�dd �d|_ d |_ x&d D]} t |d| ƒ�rV| |_ P�qVWd |_x&dD]}t |d|ƒ�r„||_P�q„Wi|_|j |j¡}|dk�rÔ| d|j¡xj| ¡D]^\}}g|j|<}|�rÞt|tƒ�s t‚| ¡}x&|D]}| |g¡�r| |¡�qW�qÞWd|_dS)NÚ cc_is_cached))rRz.*(x|x86_|amd)64.*)rQz.*(win32|x86|i386|i686).*)rYz.*(powerpc|ppc)64(el|le).*)rZz.*(powerpc|ppc)64.*)r[z.*(aarch64|arm64).*)r\z.*arm.*)Ú cc_on_noarchr ))rSz.*(gcc|gnu\-g).*)rTz .*clang.*)rWz.*(intelw|intelemw|iccw).*)rVz.*(intel|icc).*)rXz.*msvc.*)Ú cc_is_noccr ))Ú cc_has_debugz$.*(O0|Od|ggdb|coverage|debug:full).*)Ú cc_has_nativez".*(-march=native|-xHost|/QxHost).*)rPz.*DISABLE_OPT.*FTz]unable to detect CPU architecture which lead to disable the optimization. check dist_info:<< z >>)r‘z&Optimization is disabled by the Configzªunable to detect compiler type which leads to treating it as GCC. this is a normal behavior if you're using gcc-like compiler such as MinGW or IBM/XLC.check dist_info:<< Úunknown)r r rrrrZcc_on_)rrr rr Zcc_is_z=undefined flag for compiler '%s', leave an empty dict instead)rªr±r•rÙrÚÚ IGNORECASErr˜rPrwrrSÚcc_marchr”Úcc_nameÚcc_flagsrr®r¶rîr…r’r‡ÚsplitÚ cc_test_flagsrÁr)r]Z detect_archZdetect_compilerZ detect_argsr±r¯Z compiler_infor°ÚsectionröZrgexr4ZsearchinÚarchr½Zcompiler_flagsrMZnflagsrr_r_r`rryst             z_CCompiler.__init__cCsLt|tƒst‚| d|¡tj |jd¡}| ||¡}|sH|jddd�|S)z@ Returns True if the compiler supports 'flags'. z testing flagsz test_flags.cztesting failedT)r‘) r…r†r‡r˜rmrnrxr{rž)r]rMÚ test_pathrœr_r_r`rás  z_CCompiler.cc_test_flagscCsDt|tƒst‚|js |js |jr*| |¡S|js6|jr@|  |¡S|S)a” Remove the conflicts that caused due gathering implied features flags. Parameters ---------- 'flags' list, compiler flags flags should be sorted from the lowest to the highest interest. Returns ------- list, filtered from any conflicts. Examples -------- >>> self.cc_normalize_flags(['-march=armv8.2-a+fp16', '-march=armv8.2-a+dotprod']) ['armv8.2-a+fp16+dotprod'] >>> self.cc_normalize_flags( ['-msse', '-msse2', '-msse3', '-mssse3', '-msse4.1', '-msse4.2', '-mavx', '-march=core-avx2'] ) ['-march=core-avx2'] ) r…r†r‡rSrTrVÚ_cc_normalize_unixrXrWÚ_cc_normalize_win)r]rMr_r_r`Úcc_normalize_flagsîs    z_CCompiler.cc_normalize_flagsz^(-mcpu=|-march=|-x[A-Z0-9\-])z7^(?!(-mcpu=|-march=|-x[A-Z0-9\-]))(?!-m[a-z0-9\-\.]*.$)z^(-mfpu|-mtune)z[0-9.]csZ‡fdd„}t|ƒdkr|SxÖtt|ƒƒD]Æ\}}t ˆj|¡sBq*|d|d …}|| d…}ttˆjj |ƒƒ}||ƒ\}} } |dkrÔt| ƒdkrÔx*|D]"} || ƒ\} } }|| krœ|| } qœW| dd  | ¡}||g}|dkrî||7}Pq*Wg}t ƒ}xVt|ƒD]J}t ˆj |¡}|�s"n"|d|k�r6�qn|  |d¡| d|¡�qW|S)Nc s@| d¡}tdd t ˆj|d¡¡ƒ}||d|dd…fS)Nú+Ú0r rr)rÚfloatrxrÙÚfindallÚ_cc_normalize_arch_ver)rÚtokensÚver)r]r_r`Ú ver_flagss z0_CCompiler._cc_normalize_unix..ver_flagsrrr")r¬Ú enumerateÚreversedrÙrÚÚ_cc_normalize_unix_mrgxr†ÚfilterÚ_cc_normalize_unix_frgxÚsearchrxréÚ_cc_normalize_unix_krgxÚaddÚinsert)r]rMr)ÚiZcur_flagZ lower_flagsZ upper_flagsZfilterdr(rZsubflagsZxflagZxverÚ_Z xsubflagsZ final_flagsÚmatchedrrÚr_)r]r`rs@    z_CCompiler._cc_normalize_unixz^(?!(/arch\:|/Qx\:))z ^(/arch|/Qx:)cCs^xXtt|ƒƒD]H\}}t |j|¡s&q|d7}tt|jj|d| …ƒƒ|| d…SW|S)Nr) r*r+rÙrÚÚ_cc_normalize_win_mrgxr†r-Ú_cc_normalize_win_frgxr/)r]rMr3rr_r_r`r Tsz_CCompiler._cc_normalize_winN)rsrtrurvrrrärrr!rÙr‰r,r.r0r&rr7r6r r_r_r_r`rLs$,h 1rc@sºeZdZdZdd„Zd%dd„Zdd„Zd&d d „Zd'd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z ejdd„ƒZejd(dd„ƒZejd)dd„ƒZejdd„ƒZejd d!„ƒZd*d#d$„ZdS)+Ú_FeatureaâA helper class for `CCompilerOpt` that managing CPU features. Attributes ---------- feature_supported : dict Dictionary containing all CPU features that supported by the platform, according to the specified values in attribute `_Config.conf_features` and `_Config.conf_features_partial()` feature_min : set The minimum support of CPU features, according to the specified values in attribute `_Config.conf_min_features`. c st|dƒrdS| ¡|_}x¢t| ¡ƒD]’}||‰|j|}ˆ ‡fdd„| ¡Dƒ¡ˆ d¡}|dk rŽ|  |¡|j d||dd�q*x,dD]$}ˆ |¡}t |t ƒr”|  ¡ˆ|<q”Wq*Wtƒ|_|j |jd ¡}x*| ¡  ¡D]}||jkræ|j |¡qæWd|_dS) NÚfeature_is_cachedcsi|]\}}|ˆkr||“qSr_r_)rÆÚkÚv)Úfeaturer_r`ú ssz%_Feature.__init__..rNzfeature '%s' is disabled,T)r‘)rr3r4rrMr-r )rªraÚfeature_supportedr†rûr�Úupdaterîr®rˆr˜r…r’rréÚ feature_minr€rÚupperr1r9) r]Z pfeaturesÚ feature_nameZcfeatureÚdisabledÚoptionZovalZmin_fÚFr_)r<r`rrls4        z_Feature.__init__NcCsx|dks t|tƒst|dƒs t‚|dks6t|tƒs6t‚|dkrH|j ¡}tƒ}x$|D]}|j||d�rT|  |¡qTW|S)a4 Returns a set of CPU feature names that supported by platform and the **C** compiler. Parameters ---------- 'names': sequence or None, optional Specify certain CPU features to test it against the **C** compiler. if None(default), it will test all current supported features. **Note**: feature names must be in upper-case. 'force_flags': list or None, optional If None(default), default compiler flags for every CPU feature will be used during the test. Nr¦)Ú force_flags) r…r’rªr‡r†r>rûréÚfeature_is_supportedr1)r]ÚnamesrFZsupported_namesrr_r_r`Ú feature_namesŽs   z_Feature.feature_namescCs| ¡s t‚||jkS)zÒ Returns True if a certain feature is exist and covered within `_Config.conf_features`. Parameters ---------- 'name': str feature name in uppercase. )Úisupperr‡r�)r]r½r_r_r`Úfeature_is_exist¬s z_Feature.feature_is_existFcs‡fdd„}t|||d�S)az Sort a list of CPU features ordered by the lowest interest. Parameters ---------- 'names': sequence sequence of supported feature names in uppercase. 'reverse': bool, optional If true, the sorted features is reversed. (highest interest) Returns ------- list, sorted CPU features csBt|tƒrˆj|dSt‡fdd„|Dƒƒ}|t|ƒd7}|S)Nrcsg|]}ˆj|d‘qS)r)r>)rÆr)r]r_r`rÇÌsz<_Feature.feature_sorted..sort_cb..r)r…r’r>Úmaxr¬)r:Zrank)r]r_r`Úsort_cbÈs  z(_Feature.feature_sorted..sort_cb)ÚreverseÚkey)Úsorted)r]rHrNrMr_)r]r`Úfeature_sorted¹s z_Feature.feature_sortedcsptƒf‡‡fdd„ ‰t|tƒr.ˆ|ƒ}|g}n0t|dƒs>> self.feature_implies("SSE3") {'SSE', 'SSE2'} >>> self.feature_implies("SSE2") {'SSE'} >>> self.feature_implies("SSE2", keep_origins=True) # 'SSE2' found here since 'SSE' and 'SSE2' imply each other {'SSE', 'SSE2'} csXtƒ}ˆj|}xB| dg¡D]2}| |¡||kr6q| |¡| ˆ||ƒ¡}qW|S)Nr)rér>r®r1Úunion)r½Z_callerrrr3)Ú get_impliesr]r_r`rSës   z-_Feature.feature_implies..get_impliesr¦)rér…r’rªr‡rRÚdifference_update)r]rHÚ keep_originsrÚnr_)rSr]r`Úfeature_impliesÓs   z_Feature.feature_impliescCs.t|tƒrt|fƒ}nt|ƒ}| | |¡¡S)z/same as feature_implies() but combining 'names')r…r’rérRrW)r]rHr_r_r`Úfeature_implies_cs  z_Feature.feature_implies_ccs^t|tƒst|dƒst‚|j|dd�‰‡fdd„|Dƒ}t|ƒdkrZ|j|dd�dd …}|S) a Return list of features in 'names' after remove any implied features and keep the origins. Parameters ---------- 'names': sequence sequence of CPU feature names in uppercase. Returns ------- list of CPU features sorted as-is 'names' Examples -------- >>> self.feature_ahead(["SSE2", "SSE3", "SSE41"]) ["SSE41"] # assume AVX2 and FMA3 implies each other and AVX2 # is the highest interest >>> self.feature_ahead(["SSE2", "SSE3", "SSE41", "AVX2", "FMA3"]) ["AVX2"] # assume AVX2 and FMA3 don't implies each other >>> self.feature_ahead(["SSE2", "SSE3", "SSE41", "AVX2", "FMA3"]) ["AVX2", "FMA3"] r¦T)rUcsg|]}|ˆkr|‘qSr_r_)rÆrV)rr_r`rÇ+sz*_Feature.feature_ahead..r)rNNr)r…r’rªr‡rWr¬rQ)r]rHZaheadr_)rr`Ú feature_ahead s  z_Feature.feature_aheadcs”t|tƒst|dƒst‚g}xr|D]j‰ˆ ˆ¡‰‡‡‡fdd„|Dƒ}|r‚ˆ |ˆg¡}ˆ|dd…krlq"| |dd…d¡| ˆ¡q"W|S)am same as 'feature_ahead()' but if both features implied each other and keep the highest interest. Parameters ---------- 'names': sequence sequence of CPU feature names in uppercase. Returns ------- list of CPU features sorted as-is 'names' Examples -------- >>> self.feature_untied(["SSE2", "SSE3", "SSE41"]) ["SSE2", "SSE3", "SSE41"] # assume AVX2 and FMA3 implies each other >>> self.feature_untied(["SSE2", "SSE3", "SSE41", "FMA3", "AVX2"]) ["SSE2", "SSE3", "SSE41", "AVX2"] r¦cs&g|]}|ˆkrˆˆ |¡kr|‘qSr_)rW)rÆÚnn)rrVr]r_r`rÇPsz+_Feature.feature_untied..rNr)r…r’rªr‡rWrQÚremoverÁ)r]rHÚfinalZtiedr_)rrVr]r`Úfeature_untied2s   z_Feature.feature_untiedcs^‡‡fdd„‰t|tƒs$t|ƒdkr8ˆ|ƒ}| ¡|Sˆ |¡}‡fdd„|Dƒ}ˆ |¡S)zÝ same as `feature_implies_c()` but stop collecting implied features when feature's option that provided through parameter 'keyisfalse' is False, also sorting the returned features. csVˆ |¡}ˆj|dd�}x8t|ƒD],\}}ˆj| ˆd¡s"|d|d…}Pq"W|S)NT)rNr)rXrQr*r>r®)Ztnamesr3rV)Ú keyisfalser]r_r`Útilbs z%_Feature.feature_get_til..tilrcsh|]}ˆ|ƒD]}|’qqSr_r_)rÆrVÚt)r_r_r`ú ssz+_Feature.feature_get_til..)r…r’r¬rNrYrQ)r]rHr^r_)r^r]r_r`Úfeature_get_til[s  z_Feature.feature_get_tilc CsF| |d¡}g}x0|D](}|j|}|| d| d|g¡¡7}qW|S)z€ Return a list of CPU features that required to be detected sorted from the lowest to highest interest. r$r4r3)rbr>r®)r]rHr4rVrr_r_r`Úfeature_detectvs    z_Feature.feature_detectcCsZ| | |¡¡}g}x:|D]2}|j|}| dg¡}|r| |¡sDq||7}qW| |¡S)zi Return a list of CPU features flags sorted from the lowest to highest interest. rM)rQrXr>r®rr!)r]rHrMrVrrr_r_r`Ú feature_flags‚s    z_Feature.feature_flagscCs†|dkr| |¡}| d|d |¡f¡tj |jd| ¡¡}tj |¡sZ| d|¡|  |||j d¡}|s‚|jddd �|S) aX Test a certain CPU feature against the compiler through its own check file. Parameters ---------- 'name': str Supported CPU feature name. 'force_flags': list or None, optional If None(default), the returned flags from `feature_flags()` will be used. Nz$testing feature '%s' with flags (%s)r§zcpu_%s.czfeature test file is not existrztesting failedT)r‘) rdr˜rxrmrnr{Úlowerrír¶ržr)r]r½rFrrœr_r_r`Ú feature_test’s   z_Feature.feature_testcCsh| ¡s t‚|dks"t|tƒs"t‚||jk}|rdx"| |¡D]}| ||¡srWrf)r]r½rFÚ supportedÚimplr_r_r`rGµs    z_Feature.feature_is_supportedcsVt|tƒst‚ˆj|}| dd¡}|dkrR‡fdd„| dg¡Dƒ}|oPt|ƒ}|S)zM check if the feature can be auto-vectorized by the compiler rONcsg|]}ˆ |g¡‘qSr_)r)rÆr)r]r_r`rÇÙsz0_Feature.feature_can_autovec..rM)r…r’r‡r>r®Úany)r]r½rÚcanZ valid_flagsr_)r]r`Úfeature_can_autovecÏs   z_Feature.feature_can_autovecc CsÔt|tƒst‚|j|}| dg¡}|s,gS| d||¡| |¡}g}g}xl|D]d}tj  |j d|  ¡¡}tj  |¡sˆ|  d|¡| |||jd¡} | r®| |¡qT| |¡qTW|rÐ|jd|dd�|S) zÏ Return a list of supported extra checks after testing them against the compiler. Parameters ---------- names: str CPU feature name in uppercase. r-z%Testing extra checks for feature '%s'z extra_%s.czextra check file does not existrztesting failed for checksT)r‘)r…r’r‡r>r®r˜rdrmrnrxr{rerír¶ržrrÁ) r]r½rr-rMÚ availableZ not_availableZchkrÚ is_supportedr_r_r`Úfeature_extra_checksÞs*        z_Feature.feature_extra_checksrcsÂ| ¡s t‚|j |¡}|dk s$t‚d|d|j|fg}|dd„| dg¡Dƒ7}| dg¡}|| |¡7}x.|D]&}|d|j|fd |j|fd g7}qtWˆd kr¸‡fd d„|Dƒ}d  |¡S)a" Generate C preprocessor definitions and include headers of a CPU feature. Parameters ---------- 'feature_name': str CPU feature name in uppercase. 'tabs': int if > 0, align the generated strings to the right depend on number of tabs. Returns ------- str, generated C preprocessor Examples -------- >>> self.feature_c_preprocessor("SSE3") /** SSE3 **/ #define NPY_HAVE_SSE3 1 #include Nz /** %s **/z#define %sHAVE_%s 1cSsg|] }d|‘qS)z #include <%s>r_)rÆÚhr_r_r`rÇ$sz3_Feature.feature_c_preprocessor..rr3z#ifndef %sHAVE_%sz #define %sHAVE_%s 1z#endifrcsg|]}dˆ|‘qS)ú r_)rÆÚl)Útabsr_r`rÇ3sÚ )rJr‡r>r®r}rnrx)r]rBrrr<ZpreprZ extra_defsZedefr_)rrr`Úfeature_c_preprocessors"        z_Feature.feature_c_preprocessor)NN)F)F)N)N)r)rsrtrurvrrrIrKrQrWrXrYr]rbrcrärrdrfrGrkrnrtr_r_r_r`r8^s& "   1&)  " 'r8c@sŒeZdZdZdd„Zdd„Ze d¡Zdd„Z e d ¡Z d d „Z d d „Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS)Ú_ParseaçA helper class that parsing main arguments of `CCompilerOpt`, also parsing configuration statements in dispatch-able sources. Parameters ---------- cpu_baseline: str or None minimal set of required CPU features or special options. cpu_dispatch: str or None dispatched set of additional CPU features or special options. Special options can be: - **MIN**: Enables the minimum CPU features that utilized via `_Config.conf_min_features` - **MAX**: Enables all supported CPU features by the Compiler and platform. - **NATIVE**: Enables all CPU features that supported by the current machine. - **NONE**: Enables nothing - **Operand +/-**: remove or add features, useful with options **MAX**, **MIN** and **NATIVE**. NOTE: operand + is only added for nominal reason. NOTES: - Case-insensitive among all CPU features and special options. - Comma or space can be used as a separator. - If the CPU feature is not supported by the user platform or compiler, it will be skipped rather than raising a fatal error. - Any specified CPU features to 'cpu_dispatch' will be skipped if its part of CPU baseline features - 'cpu_baseline' force enables implied features. Attributes ---------- parse_baseline_names : list Final CPU baseline's feature names(sorted from low to high) parse_baseline_flags : list Compiler flags of baseline features parse_dispatch_names : list Final CPU dispatch-able feature names(sorted from low to high) parse_target_groups : dict Dictionary containing initialized target groups that configured through class attribute `conf_target_groups`. The key is represent the group name and value is a tuple contains three items : - bool, True if group has the 'baseline' option. - list, list of CPU features. - list, list of extra compiler flags. c sªtdˆjgfˆjˆjgfˆjdgfˆjdgfˆjddgfd�ˆ_tˆdƒrNdSgˆ_ gˆ_ gˆ_ iˆ_ ˆj rtd}}ˆ d¡|dk rºˆ d|¡}ˆ |¡}ˆ |¡ˆ_ ˆ ˆ |¡¡ˆ_ ˆ d¡|dk �r$ˆ d|¡}‡fdd „|Dƒ}| |¡}ˆ ˆ |¡¡ˆ_ t|ƒd k�r$ˆ d |d ¡ˆ d ¡xpˆj ¡D]b\}}ˆ d|¡| ¡}|�rf| ¡�szdggfˆj |<�q:ˆ |¡\} } } | | | fˆj |<�q:Wdˆ_dS)NÚMAXOPT)Z KEEP_BASELINEZ KEEP_SORTrvZWERRORZAUTOVECÚparse_is_cachedzcheck requested baselineÚ cpu_baselinez&check requested dispatch-able featuresÚ cpu_dispatchcsh|]}|ˆjkr|’qSr_)Úparse_baseline_names)rÆr)r]r_r`ra–sz"_Parse.__init__..rz skip featureszsince its part of baselinezinitialize targets groupszparse target groupFT)rUÚ_parse_policy_not_keepbaseÚ_parse_policy_keepsortÚ_parse_policy_not_keepsortÚ_parse_policy_maxoptÚ_parse_policy_werrorÚ_parse_policy_autovecÚ_parse_policiesrªrzÚparse_baseline_flagsÚparse_dispatch_namesÚparse_target_groupsrPr˜Ú_parse_arg_featuresrIrdrQrXÚ differencer¬r|rîrAÚstripÚ_parse_target_tokensrw) r]rxryÚbaseline_namesZ cpu_dispatch_Zconflict_baselineZ group_namer'Z GROUP_NAMEÚ has_baselineÚfeaturesÚ extra_flagsr_)r]r`rres`             z_Parse.__init__c Csü| d|¡t|ƒ� }d}d}d}d}d}d}x€t|ƒD]t\} } | |krT| d¡P|dkr||  |¡}|dkrpq8|t|ƒ7}|| 7}|  |¡}|dkr8|t|ƒt| ƒ7}Pq8WWdQRX|dkrÐ| d |¡|dkræ| d |¡|||…}| |¡S) aÕ Fetch and parse configuration statements that required for defining the targeted CPU features, statements should be declared in the top of source in between **C** comment and start with a special mark **@targets**. Configuration statements are sort of keywords representing CPU features names, group of statements and policies, combined together to determine the required optimization. Parameters ---------- source: str the path of **C** source file. Returns ------- - bool, True if group has the 'baseline' option - list, list of CPU features - list, list of extra compiler flags z!looking for '@targets' inside -> r ièz@targetséÿÿÿÿz*/zreached the max of linesNz(expected to find '%s' within a C commentzexpected to end with '%s')r˜rÿr*r¶Úfindr¬rˆ) r]r™Úfdr'Z max_to_reachZ start_withZ start_posZend_withZend_posÚ current_lineÚliner_r_r`Ú parse_targets·s8       z_Parse.parse_targetsz \s|[,]|([+-])c Cs>t|tƒs| d|¡tƒ}ttdt |j|¡ƒƒ}d}xþ|D]ö}|ddkr\| |d¡|dkrjd}q@|dkrxd}q@|  ¡}tƒ}|d kr�n†|d krÀ|j d } | s²| |d ¡|j | d �}nV|dkrÔ|j   ¡}nB|dkrä|j}n2||j krú| |¡n| |¡�s| |d|¡|�r(| |¡}n | |¡}d}q@W|S)Nzexpected a string in '%s'Tr)ú#ú$zYtarget groups and policies aren't allowed from arguments, only from dispatch-able sourcesr"ú-FÚNONEZNATIVErz-native option isn't supported by the compiler)rFÚMAXZMINz&, '%s' isn't a known feature or option)r…r’r¶rér†r-rÙrÚ_parse_regex_argrArrIr>rûr@r1rKrRr†) r]Zarg_nameZ req_featuresZfinal_featuresr'rÁÚtokÚTOKZ features_torr_r_r`r…îsN           z_Parse._parse_arg_featuresz\s|[*,/]|([()])cCs t|tƒst‚g}g}d}tƒ}tƒ}d}ttdt |j|¡ƒƒ}|sP|  d¡�x¼|D�]²}|  ¡} |d} | dkr‚|  d¡qX| dkr®|dk rœ|  d¡|  |  | ¡¡qX| dkrà|dk rÈ|  d ¡|  | |||¡\}}}qX| d k�r|dk �rþ|  d ¡tƒ}qX| d k�r~|dk�r$|  d ¡| |¡} | dk�rH|  t|ƒ¡n0t| ƒdk�r^| d} | �rx| |k�rx| | ¡d}qX| dk�r¢|dk �rœ|  d¡d}qX|dk �r¸|  | ¡qX| | ¡�sÒ|  d| ¡| |jk�pæ| |jk} | �r| |krX| | ¡qX|  | ¡qXW|dk �r$|  d ¡|�r8| d|d¡| |¡}x\t|ƒD]P} |j| \}}}x8|D]0}||k�rx�qf| d| |f¡|  |¡�qfW�qLWx`|j ¡D]R\} \}}}d}| |k�rÜ|}| d| ¡n|}|�sê�q¬||||ƒ\}}}�q¬W|||fS)NFzexpected one token at leastr)r"r•ze+/- are 'not' allowed from target's groups or @targets, only from cpu_baseline and cpu_dispatch parmsr”zCpolicies aren't allowed inside multi-target '()', only CPU featuresr“zHtarget groups aren't allowed inside multi-target '()', only CPU featuresr¿z"unclosed multi-target, missing ')'rÀz$multi-target opener '(' wasn't foundrZBASELINEz/baseline isn't allowed inside multi-target '()'Tzinvalid target name '%s'z skip targetsz.not part of baseline or dispatch-able featureszpolicy '%s' force enables '%s'zpolicy '%s' is ON)r…r’r‡rér†r-rÙrÚ_parse_regex_targetr¶rAr1Ú_parse_token_policyÚ_parse_token_groupÚ_parse_multi_targetÚtupler¬rÁrKrzrƒr˜r]r�rî)r]r'Ú final_targetsrŒrŠÚskippedZpoliciesZ multi_targetr™ršÚchÚtargetsÚ is_enabledÚpr4ÚdepsrZhaveZnhaveÚfuncr_r_r`rˆ%sª                          z_Parse._parse_target_tokenscCsZt|ƒdks |dd…|dkr*| d¡|dd…}||jkrV| d||j ¡¡|S)zvalidate policy tokenrr�Nrz*'$' must stuck in the begin of policy namez6'%s' is an invalid policy name, available policies are)r¬r¶r�rû)r]Útokenr_r_r`rœ™s     z_Parse._parse_token_policycs°t|ƒdks |dd…|dkr*| d¡|dd…}|j |ddgf¡\}}}|dkrr| d|d|j ¡¡|rzd }ˆ‡fd d „|Dƒ7‰ˆ‡fd d „|Dƒ7‰|ˆˆfS) zvalidate group tokenrr�Nrz)'#' must stuck in the begin of group nameFz&'%s' is an invalid target group name, zavailable target groups areTcsg|]}|ˆkr|‘qSr_r_)rÆr)r r_r`rÇ·sz-_Parse._parse_token_group..csg|]}|ˆkr|‘qSr_r_)rÆr)rŒr_r`rǸs)r¬r¶r„r®rû)r]r¨rŠr rŒZ ghas_baselineZgtargetsZ gextra_flagsr_)rŒr r`r�¥s    z_Parse._parse_token_groupcsr|sˆ d¡t‡fdd„|Dƒƒs0ˆ d|¡t‡fdd„|DƒƒsJdSˆ |¡}|s\dSˆ |¡}t|ƒ}|S)z9validate multi targets that defined between parentheses()zempty multi-target '()'csg|]}ˆ |¡‘qSr_)rK)rÆÚtar)r]r_r`rÇÁsz._Parse._parse_multi_target..z#invalid target name in multi-targetcs g|]}|ˆjkp|ˆjk‘qSr_)rzrƒ)rÆr©)r]r_r`rÇÅsN)r¶ÚallrYrQrŸ)r]r£r_)r]r`rž»s      z_Parse._parse_multi_targetcs|g}x\|dd…D]L}d}t|tƒr0|ˆjk}nt‡fdd„|Dƒƒ}|r| |¡| |¡qW|rrˆ d|¡|||fS)zskip all baseline featuresNFcsg|]}|ˆjk‘qSr_)rz)rÆr)r]r_r`rÇÞsz5_Parse._parse_policy_not_keepbase..zskip baseline features)r…r’rzrªrÁr[r˜)r]rŠr rŒr¡r©Úis_baser_)r]r`r{Ôs      z!_Parse._parse_policy_not_keepbasecCs| d|d¡|||fS)z$leave a notice that $keep_sort is onz/policy 'keep_sort' is on, dispatch-able targetszo are 'not' sorted depend on the highest interest butas specified in the dispatch-able source or the extra group)r˜)r]rŠr rŒr_r_r`r|ês z_Parse._parse_policy_keepsortcCs|j|dd�}|||fS)z%sorted depend on the highest interestT)rN)rQ)r]rŠr rŒr_r_r`r}ósz!_Parse._parse_policy_not_keepsortcCsT|jr| d¡n8|jr$| d¡n&|jd}|sB|jddd�n||7}|||fS)z&append the compiler optimization flagsz3debug mode is detected, policy 'maxopt' is skipped.z5optimization is disabled, policy 'maxopt' is skipped.rzOcurrent compiler doesn't support optimization flags, policy 'maxopt' is skippedT)r‘)rr˜rPr)r]rŠr rŒrMr_r_r`r~øs    z_Parse._parse_policy_maxoptcCs:|jd}|s|jddd�n| d¡||7}|||fS)z#force warnings to treated as errorsrzTcurrent compiler doesn't support werror flags, warnings will 'not' treated as errorsT)r‘z'compiler warnings are treated as errors)rr˜)r]rŠr rŒrMr_r_r`r s   z_Parse._parse_policy_werrorcsxg}xX|dd…D]H}t|tƒr,ˆ |¡}nt‡fdd„|Dƒƒ}|s| |¡| |¡qW|rnˆ d|¡|||fS)z=skip features that has no auto-vectorized support by compilerNcsg|]}ˆ |¡‘qSr_)rk)rÆr`)r]r_r`rÇsz0_Parse._parse_policy_autovec..z!skip non auto-vectorized features)r…r’rkrªr[rÁr˜)r]rŠr rŒr¡r©rjr_)r]r`r€s      z_Parse._parse_policy_autovecN)rsrtrurvrrr’rÙr‰r˜r…r›rˆrœr�ržr{r|r}r~rr€r_r_r_r`ru6s .R6 6 t   ruc@sjeZdZdZddd„Zdd„Zd d „Zd d „Zd d„Zddd„Z dd„Z ddd„Z ddd„Z ddd„Z dS)Ú CCompilerOptz° A helper class for `CCompiler` aims to provide extra build options to effectively control of compiler optimizations that are directly related to CPU features. ÚminrLNcCsžt |¡t ||¡t ||| ¡||¡t |¡t |¡|jsZ|jrZ|  d¡d}t  |||¡||_ ||_ t |diƒ|_|j d¡t|dƒ|_dS)NzSnative flag is specified through environment variables. force cpu-baseline='native'rÚsources_statusÚ hit_cache)rrrr‚rär±rr8rPrr˜ruÚ_requested_baselineÚ_requested_dispatchr”r®rêr1rªr¯)r]r„rxryrór_r_r`rr0s      zCCompilerOpt.__init__cCs |jo |jS)zF Returns True if the class loaded from the cache file )rër¯)r]r_r_r`Ú is_cachedJszCCompilerOpt.is_cachedcCs|jS)zE Returns a list of final CPU baseline compiler flags )r‚)r]r_r_r`Úcpu_baseline_flagsPszCCompilerOpt.cpu_baseline_flagscCs|jS)zC return a list of final CPU baseline feature names )rz)r]r_r_r`Úcpu_baseline_namesVszCCompilerOpt.cpu_baseline_namescCs|jS)zC return a list of final CPU dispatch feature names )rƒ)r]r_r_r`Úcpu_dispatch_names\szCCompilerOpt.cpu_dispatch_namescKs,i}| ¡}| dg¡}xÚ|D]Ò}tj |¡}|r\| |¡sJtj ||¡}||kr\| |¡| |¡\} } } |  ||| | ¡} xB| D]:} |j ||| | d�}t | |  | ¡ƒ}| |g¡ |¡q‚W| rât | |ƒ}| |g¡ |¡| | f|j |<qWg}x.| ¡D]"\}}||j|t|ƒf|Ž7}�qW|S)a½ Compile one or more dispatch-able sources and generates object files, also generates abstract C config headers and macros that used later for the final runtime dispatching process. The mechanism behind it is to takes each source file that specified in 'sources' and branching it into several files depend on special configuration statements that must be declared in the top of each source which contains targeted CPU features, then it compiles every branched source with the proper compiler flags. Parameters ---------- sources : list Must be a list of dispatch-able sources file paths, and configuration statements must be declared inside each file. src_dir : str Path of parent directory for the generated headers and wrapped sources. If None(default) the files will generated in-place. **kwargs : any Arguments to pass on to the `CCompiler.compile()` Returns ------- list : generated object files Raises ------ CompileError Raises by `CCompiler.compile()` on compiling failure. DistutilsError Some errors during checking the sanity of configuration statements. See Also -------- parse_targets : Parsing the configuration statements of dispatch-able sources. Ú include_dirs)Únochange)r³Ú setdefaultrmrnryÚ startswithrxrÁr’Ú_generate_configÚ _wrap_targetrŸrdr®rîrŒr†)r]rŠÚsrc_dirr‹Z to_compileÚbaseline_flagsr¶Úsrcr�rŠr£rŒr·r©Ztar_srcrMZobjectsZsrcsr_r_r`Ú try_dispatchbs0*       zCCompilerOpt.try_dispatchc sbˆ d|¡ˆ ¡}ˆ ¡}t|ƒ}t|ƒ}tj |¡}tj |¡sfˆjd|›d�dd�t |¡t |dƒ�è}d  ‡fdd „|Dƒ¡}d  ‡fd d „|Dƒ¡} |  t   d ¡jˆjd   |¡d   |¡|||| d �¡d} x"|D]} | ˆj| dd�d7} qÞWd} x4|D],} | t   d¡jˆj| ˆj| dd�d�7} �qW|  t   d¡jˆj| | d�¡WdQRXdS)ax Generate the dispatch header which contains the #definitions and headers for platform-specific instruction-sets for the enabled CPU baseline and dispatch-able features. Its highly recommended to take a look at the generated header also the generated source files via `try_dispatch()` in order to get the full picture. z"generate CPU dispatch header: (%s)zdispatch header dir z does not exist, creating itT)r‘rúz \ csg|]}dˆj|f‘qS)z3 %sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__)))r})rÆr)r]r_r`rÇÍsz9CCompilerOpt.generate_dispatch_header..csg|]}dˆj|f‘qS)z3 %sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__)))r})rÆr)r]r_r`rÇÓsaà /* * AUTOGENERATED DON'T EDIT * Please make changes to the code generator (distutils/ccompiler_opt.py) */ #define {pfx}WITH_CPU_BASELINE "{baseline_str}" #define {pfx}WITH_CPU_DISPATCH "{dispatch_str}" #define {pfx}WITH_CPU_BASELINE_N {baseline_len} #define {pfx}WITH_CPU_DISPATCH_N {dispatch_len} #define {pfx}WITH_CPU_EXPAND_(X) X #define {pfx}WITH_CPU_BASELINE_CALL(MACRO_TO_CALL, ...) \ {baseline_calls} #define {pfx}WITH_CPU_DISPATCH_CALL(MACRO_TO_CALL, ...) \ {dispatch_calls} r§)ÚpfxZ baseline_strZ dispatch_strÚ baseline_lenÚ dispatch_lenÚbaseline_callsÚdispatch_callsr r)rrrsz† #ifdef {pfx}CPU_TARGET_{name} {pre} #endif /*{pfx}CPU_TARGET_{name}*/ )rÀr½Úprez¢ /******* baseline features *******/ {baseline_pre} /******* dispatch features *******/ {dispatch_pre} )rÀÚ baseline_preÚ dispatch_preN)r˜r´rµr¬rmrnryrírürÿrxrrrrr}rtr~) r]Z header_pathr‰Údispatch_namesrÁrÂÚ header_dirrrÃrÄrÆr½rÇr_)r]r`Úgenerate_dispatch_header²sJ                z%CCompilerOpt.generate_dispatch_headerFc Cs8g}g}g}g}| d|f¡| d¡| d|f¡| d¡| d|f¡| d|jr^dn|jf¡| d|jrxdn|jf¡|jr”| d ¡n| d t|jƒf¡| ¡}| d |rÄd   |¡nd f¡|  ¡}| d|rèd   |¡nd f¡g}x|D]} ||  | ¡7}qúW| d|�r&d   |¡nd f¡|j�rB| d ¡n| d t|j ƒf¡|  ¡} | d | �rtd   | ¡nd f¡i} x>|j ¡D]0\} \} }x |D]}|  |g¡ | ¡�qžW�qŒW|�rÌ| �sDd}xN| | ¡D]@}| |}t|tƒ�rø|n dd   |¡} || dt|ƒ7}�qÜW| d|�r8|dd…nd f¡�n(| d¡�x| | ¡D�] }| |}t|tƒ�rz|n dd   |¡}d   | |¡¡}d   | | |¡¡¡}d   | |¡¡}g}x.t|tƒ�rÖ|fn|D]} ||  | ¡7}�qÚW|�rd   |¡nd }| d¡| ||f¡| d|f¡| d|f¡| d|f¡x|D]}| d|f¡�qNW�q\Wg}dd„|Dƒ}dd„|Dƒ}d}tt|ƒt|ƒƒ}xŠ|D]‚\}}|�sÄ| d¡�q¨|d |t|ƒ7}| ||d¡x<|D]4\}}|d |t|ƒ7}| ||d|¡�qðW�q¨Wd  |¡S)NÚPlatform)r r z CPU baselinez CPU dispatchZ ArchitectureÚ unsupportedZCompilerz unix-like)Ú Requestedzoptimization disabledrÍZEnabledr§ÚnoneZFlagsz Extra checksr z(%s)z[%d] Ú Generatedr�)rÏr ZDetectcSsg|]\}}t|ƒ‘qSr_)r¬)rÆZsecsr4r_r_r`rÇb sz'CCompilerOpt.report..cSs&g|]\}}|D]\}}t|ƒ‘qqSr_)r¬)rÆr4ÚrowsÚcolr_r_r`rÇc sz z: rs)rÁrrrrrPÚreprr°r´rxr³rnr±rµr®rîr¸rQr…r’r¬rdrWrcrL) r]ÚfullÚreportZ platform_rowsZ baseline_rowsZ dispatch_rowsr‰r½r-r½rÈZtarget_sourcesr™r4r£r©Ú generatedrŠÚ pretty_namerMrr4r¾ÚtextZsecs_lenZcols_lenÚtabÚpadÚsecrÐrÑr÷r_r_r`rÔ sš        $    "zCCompilerOpt.reportc st|ttfƒst‚t|tƒr&|}}nd |¡}d |¡}tj |tj |¡¡}djtj  |¡|  ¡fžŽ}|r€tj  |¡r€|S|  d|¡|  | |¡¡}d|j‰‡fdd„|Dƒ} d | ¡} t|d ƒ�.} |  t d ¡j|j|tj |¡| d �¡WdQRX|S) NÚ.Ú__z {0}.{2}{1}zwrap dispatch-able target -> z#define %sCPU_TARGET_csg|] }ˆ|‘qSr_r_)rÆr)Ú target_joinr_r`rÇ„ sz-CCompilerOpt._wrap_target..rsrúaR /** * AUTOGENERATED DON'T EDIT * Please make changes to the code generator (distutils/ccompiler_opt.py) */ #define {pfx}CPU_TARGET_MODE #define {pfx}CPU_TARGET_CURRENT {target_name} {target_defs} #include "{path}" )rÀÚ target_namernÚ target_defs)r…r’rŸr‡rxrmrnÚbasenamerÚsplitextrerír˜rQrXr~rÿrrrÚabspath) r]r�Ú dispatch_srcÚtargetr·Zext_namerÞZ wrap_pathr‹rßr�r_)rÝr`r»r s(         zCCompilerOpt._wrap_targetc CsZtj |¡ dd¡}tj ||¡}| ||¡}yFt|ƒ�4}| ¡ d¡}t |ƒdkrht |dƒ|krhdSWdQRXWnt k rˆYnX|  d|¡g} xd|D]\} t | tƒr´| } nd d d „| Dƒ¡} | | ¡} d  d d „| Dƒ¡} |  d |j| | f¡q Wd | ¡} |�rd|j} nd} t|dƒ�&}| t d¡j|j| | |d�¡WdQRXdS)Nz.cz.hz cache_hash:rrTzgenerate dispatched config -> rÜcSsg|]}|‘qSr_r_)rÆr`r_r_r`rÇ« sz1CCompilerOpt._generate_config..z&&cSsg|] }d|‘qS)zCHK(%s)r_)rÆrr_r_r`rÇ® sz2 %sCPU_DISPATCH_EXPAND_(CB((%s), %s, __VA_ARGS__))z \ z( %sCPU_DISPATCH_EXPAND_(CB(__VA_ARGS__))r rúaZ // cache_hash:{cache_hash} /** * AUTOGENERATED DON'T EDIT * Please make changes to the code generator (distutils/ccompiler_opt.py) */ #ifndef {pfx}CPU_DISPATCH_EXPAND_ #define {pfx}CPU_DISPATCH_EXPAND_(X) X #endif #undef {pfx}CPU_DISPATCH_BASELINE_CALL #undef {pfx}CPU_DISPATCH_CALL #define {pfx}CPU_DISPATCH_BASELINE_CALL(CB, ...) \ {baseline_calls} #define {pfx}CPU_DISPATCH_CALL(CHK, CB, ...) \ {dispatch_calls} )rÀrÃrÄrìF)rmrnràÚreplacerxrìrÿÚreadlinerr¬Úintrcr˜r…r’rcrÁr~rrrr)r]r�rãr£rŠZ config_pathrìrZ last_hashrÄr©rÞZ req_detectrÃr�r_r_r`rº˜ sB         zCCompilerOpt._generate_config)r­rLN)N)F)F)F)rsrtrurvrrr²r³r´rµr¿rÊrÔr»rºr_r_r_r`r¬*s  PS m &r¬cKs.t|f|Ž}tj |¡r | ¡s*| |¡|S)aÏ Create a new instance of 'CCompilerOpt' and generate the dispatch header which contains the #definitions and headers of platform-specific instruction-sets for the enabled CPU baseline and dispatch-able features. Parameters ---------- compiler : CCompiler instance dispatch_hpath : str path of the dispatch header **kwargs: passed as-is to `CCompilerOpt(...)` Returns ------- new instance of CCompilerOpt )r¬rmrnrír²rÊ)r£Zdispatch_hpathr‹rr_r_r`Únew_ccompiler_optÓ s  rè)rvÚsysÚiormrÙrrýrÈrjrÖrr‚rðräÚobjectrr8rur¬rèr_r_r_r`Ú s4H ;[w,