o 6a.z @sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z GdddZ GdddZ iZ GdddZ Gd d d ZGd d d ZGd ddZGddde e e eeeZddZdS)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 @seZdZdZdZdZdZdZej ej ej e dZiZdZdZeeddd d eddd d ed dd d ed ddd edddd dZedddddddZedridedddddedddd d!ed"dd#d d$ed%d!d&d d'ed(d$d)d d*ed+d'd,d d-ed.d*d/d0ed1d-d2dd3d4ed5d0d6d d7ed8d0d6d d9ed:d0d/d;edd9d/d?ed@dAddBdCdDedEd?d/dFedGdDdHdFddIdJedKdFdLdJddIdMedNdDdOdMddPdQdRedSdMdTdRdUdVedWdMdXdVddIdYedZd[d\dYddId]edd^d_d`daedd]ddbdced"daddbddeddedfdgedddd/dhed"dgd/died%djddbdked(did/dled+did/dmed.dkd/ZdndoZdpdqZdS)s_ConfigaAn 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 FNchecksNPY_NPY__z -march=nativez-O3z-Werror)nativeoptwerrorz--Werror-implicit-function-declaration -Werrorz-xHostz/QxHostz/O3z/Werrorz/O2z/WX)gccclangicciccwmsvczSSE SSE2z SSE SSE2 SSE3zVSX VSX2zNEON NEON_FP16 NEON_VFPV4 ASIMDx86x64ppc64ppc64learmhfaarch64SSEz xmmintrin.hSSE2)interestheadersimpliesz emmintrin.h)rrrSSE3z pmmintrin.hSSSE3z tmmintrin.hSSE41z smmintrin.hPOPCNTzpopcntintrin.hSSE42)rrAVXz immintrin.h)rrrimplies_detectXOP z x86intrin.hFMA4 F16C FMA3 AVX2 AVX512Fz FMA3 AVX2AVX512F_REDUCE)rrr) extra_checksAVX512CD AVX512_KNL(zAVX512ER AVX512PF)rrgroupdetectr) AVX512_KNM)z)AVX5124FMAPS AVX5124VNNIW AVX512VPOPCNTDQ AVX512_SKX*zAVX512VL AVX512BW AVX512DQzAVX512BW_MASK AVX512DQ_MASK)rrr<r=r)r7 AVX512_CLX+ AVX512VNNI)rrr<r= AVX512_CNL,zAVX512IFMA AVX512VBMI AVX512_ICL-zAVX512_CLX AVX512_CNLz(AVX512VBMI2 AVX512BITALG AVX512VPOPCNTDQVSXz altivec.hVSX_ASM)rrr7VSX2)rrr)VSX3NEONz arm_neon.h)rr NEON_FP16 NEON_VFPV4ASIMDzNEON_FP16 NEON_VFPV4ASIMDHPASIMDDPASIMDFHMc CsZ|jriS|jp |j}|jp|j}|r|rtdoidtdddtdddtdddtd dd td dd td ddtdddtdddtdddtdddtdddtdddtdddtdddtddd td!dd"td#dd$td%dd&td'dd(td)dd*td+dS|r |jr tdoidtdddtdddtdddtd dd td dd idtdddtdddidtd,d-dtd,d-dtd.d/d0dtdd/d0dtd1d2d0dtd3d2d0d td4dd"td5dd$td6dd&td7dd(td8dd*td9dS|r|jrtdoidtd:ddtd;ddtddd idtd?ddtd@ddidtd,d-dtd,d-dtd.dAd0dtddAd0dtd1dBd0dtd3dBd0d tdCdd"tdDdd$tdEdd&tdFdd(tdGdd*tdHdS|r|jrtdoidtd:ddtd;ddidid id tdIdJdidtd@ddidtdKdJdtdKdJdtd.dLd0dtdMdLd0dtdNdOd0dtdPdOd0d tdQd-d"tdQd-d$tdOdd&id(id*iS|j p$|j }|rYtt|j r0dRndSdTd0tdUdVdWtdXdVdWdY}|jrWdZ|d[d\<d]|dRd\<d^|d_d\<|S|j r|rttd`dadbtdcdadbtdddadbtdedadbtdfdtdgdtdhddiS|j r|rttdjdtdkdtdldtdmdtdfdtdgdtdhddiSiS)pa7Return a dictionary of supported CPU features by the platform, and accumulate the rest of undefined options in `conf_features`, the returned dict has same rules and notes in class attribute `conf_features`, also its override any options that been set in 'conf_features'. rz-msse)flagsrz-msse2rz-msse3rz-mssse3r!z-msse4.1r#z-mpopcntr%z-msse4.2r'z-mavxr.z-mf16cr*z-mxopr,z-mfma4r0z-mfmar2z-mavx2r4z -mavx512fr8z -mavx512cdr:z-mavx512er -mavx512pfr>z/-mavx5124fmaps -mavx5124vnniw -mavx512vpopcntdqr@z -mavx512vl -mavx512bw -mavx512dqrBz -mavx512vnnirEz-mavx512ifma -mavx512vbmirGz.-mavx512vbmi2 -mavx512bitalg -mavx512vpopcntdqz!Intel Compiler doesn't support it)disablez F16C AVX2z-march=core-avx2)rrTz 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 itrKrz-mvsxz -mcpu=power8F)rTr)z-mcpu=power9 -mtune=power9)rIrKrLz-maltivec -mvsxrIrTz-mpower8-vectorz-mpower9-vectorrLzNEON_FP16 NEON_VFPV4 ASIMDT)rautoveczNEON 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)rMrNrOrPrQrRrSz -mfpu=neonz"-mfpu=neon-fp16 -mfp16-format=ieeez-mfpu=neon-vfpv4z'-mfpu=neon-fp-armv8 -march=armv8-a+simdN) cc_noopt cc_on_x86 cc_on_x64 cc_is_gcc cc_is_clangdict cc_is_icc cc_is_iccw cc_is_msvc cc_on_ppc64le cc_on_ppc64 cc_on_aarch64 cc_on_armhf)selfon_x86is_unixon_powerpartialrWrW?/usr/lib/python3/dist-packages/numpy/distutils/ccompiler_opt.pyconf_features_partial/s                                                         !         !"#$'   z_Config.conf_features_partialcsf|jdur ddl}ddl|fdd}t||_|jdur1tj t |j g|_dSdS)Nrcs&zWdStyYdSwN)rmtreeIOErrorrWshutiltmprWrjrm_temp s  z!_Config.__init__..rm_temp) conf_tmp_pathtempfilerpmkdtempatexitregisterconf_cache_factorsospathgetmtime__file__ conf_nocache)rertrrrWrorj__init__s     z_Config.__init__rW)__name__ __module__ __qualname____doc__r} conf_nooptrxrsryrzjoindirnamerealpathr|conf_check_pathconf_target_groups conf_c_prefixconf_c_prefix_r] conf_cc_flagsconf_min_features conf_featuresrkr~rWrWrWrjr s " "          %*.29;= ? @ BD F H JL Wrc@seZdZdZddZdddZgfddZd d Zed d Z ed dZ eddddZ eddZ eddZ dddZedZedddZdS) _DistutilsaA 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 ||_dSrl) _ccompiler)re ccompilerrWrWrjr~$s z_Distutils.__init__NcKsLt|tsJt|tsJ|dg|}|s|j}|j|fd|i|S)zWrap CCompiler.compile()extra_postargs) isinstancelistpoprcompile)resourcesrTrkwargsrWrWrj dist_compile's z_Distutils.dist_compilec Cst|tsJddlm}|j}t|dd}|r2t|jdd}|dvr+t|d|jnt|d|jd}z|j |g|||j d d }Wn|y^} z|j t| d d WYd} ~ nd} ~ ww|rgt|d||S) zgReturn True if 'CCompiler.compile()' able to compile a source file with certain flags. r CompileErrorspawnN compiler_typer)r F)macros output_dirTstderr) rstrdistutils.errorsrrgetattrsetattr_dist_test_spawn_paths_dist_test_spawnrrsdist_log) resourcerTrrccbk_spawncc_typetesterWrWrj dist_test0s,    z_Distutils.dist_testcCst|dr|jSt|jdd}|dvrd}n|dvrd}n dd lm}|}t|jd t|jd d}|r8|d krGt|d rB|d}nt|}n|}t|d r^t|dkr^d|dd}nt j dd}|t j dd7}|||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_inforr)intelemintelemwx86_64)intelintelwintelerr) get_platformcompiler compiler_sounix__iter__r NCFLAGSCPPFLAGS) hasattrrrrdistutils.utilrrlenrryenvironget)rerplatformrcc_infor extra_argsrWrWrj dist_infoJs*       z_Distutils.dist_infocGddlm}|tj|)zRaise a compiler errorrr)rrr _dist_str)argsrrWrWrj dist_erroro z_Distutils.dist_errorcGr)zRaise a distutils errorr)DistutilsError)rrrr)rrrWrWrj dist_fatalurz_Distutils.dist_fatalFrcGs6ddlm}tj|}|r||dS||dS)zPrint a console messager)logN)numpy.distutilsrrrwarninfo)rrroutrWrWrjr{s  z_Distutils.dist_logc CsNddlm}z|||WSty&}ztj|ddWYd}~dSd}~ww)zALoad a module from file, required by the abstract class '_Cache'.r)exec_mod_from_locationTrN) misc_utilr Exceptionrr)namerzrrrWrWrjdist_load_modules  z_Distutils.dist_load_modulecsNfddtd}d|j|jf}dfddg|RD}||S)z+Return a string to print by log and errors.csJt|ts!t|dr!g}|D] }||qdd|dSt|S)Nr(r))rrrappendr)argretato_strrWrjrs z$_Distutils._dist_str..to_strrzCCompilerOpt.%s[%d] : rcsg|]}|qSrWrW).0rrrWrj sz(_Distutils._dist_str..)inspectstackfunctionlinenor)rrstartrrWrrjrs  z_Distutils._dist_strc CsZt|jds ||dStd}z|jjtjd<||W|tjd<dS|tjd<w)z Fix msvc SDK ENV path same as distutils do without it we get c1: fatal error C1356: unable to find mspdbcore.dll _pathsNrz)rrrrygetenvrr)recmddisplayold_pathrWrWrjrs    z!_Distutils._dist_test_spawn_pathsz/.*(warning D9002|invalid argument for option).*c Csddlm}z$tj|tjdd}|r%ttj|r(t d|d|WdSWdSWdStj yC}z |j }|j }WYd}~nd}~wt yX}z |}d}WYd}~nd}~wwt d|d ||fdS) NrrT)runiversal_newlineszFlags in commandz/aren't supported by the compiler, output -> %sCommandz(failed with exit status %d output -> %s)rr subprocess check_outputSTDOUTrematchr_dist_warn_regexrCalledProcessErroroutput returncodeOSError)rrroexcsrrWrWrjrs<     z_Distutils._dist_test_spawnrl)rrrrr~rrr staticmethodrrrrrrrrrrrWrWrWrjrs,  %     rc@sHeZdZdZedZdddZddZdd 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_)NcGshi|_t|_d|_d|_|jr|ddS|jg||jR|_ ||_|rzt j |rz|d|| d|}|sD|jdddn6t|drNt|d sV|jd ddn$|j |jkru|d |jD] \}}t|||qfd|_n|d |jst|j }|r|d |jD]\}}||jvst|j|rqt|||q|t|j <t|jdS)NFzcache is disabled by `Config`zload cache from file ->cachez)unable to load the cache file as a moduleTrhashdatazinvalid cache filezhit the file cachezmiss the file cachezhit the memory cache)cache_meset cache_private cache_infile _cache_pathr}r cache_hashrx _cache_hashryrzexistsrrrritemsr _share_cacher__dict__rr _cache_ignorervrw cache_flush)re cache_pathfactors cache_modattrval other_cacherWrWrjr~sP             z_Cache.__init__cCs.tD]\}}||krt|dSqdSrl)r r r)rehrrWrWrj__del__s  z_Cache.__del__cCs|jsdS|d|j|j}|jD]}t|j|r$||qt j |j}t j |s7t |tj|dd}t|jd}|td|j||WddS1sawYdS)z) Force update the cache. Nzwrite cache to path ->T)compactwz # AUTOGENERATED DON'T EDIT # Please make changes to the code generator (distutils/ccompiler_opt.py) hash = {} data = \ )rrr copykeysrrr rryrzrrmakedirspprintpformatopenwritetextwrapdedentformatr)recdictrd repr_dictfrWrWrjr "s$      "z_Cache.cache_flushcGsDd}|D]}t|D]}t||d>|d>|}|dM}q q|S)Nrr$l)rord)rerchashr%charrWrWrjr>s  z_Cache.cache_hashcsfdd}|S)zr A static method that can be treated as a decorator to dynamically cache certain methods. csZtjg|||R}||jvr|j|S|g|Ri|}||j|<|Srl)rrrvaluesr)rerr cache_keyccbcbrWrj cache_wrap_meNs   z _Cache.me..cache_wrap_merW)r.r/rWr-rjmeHs  z _Cache.merl) rrrrrrr r~rr rrr0rWrWrWrjrs  - rc@szeZdZdZddZejddZddZe dZ e d Z e d Z e d Zd d Ze dZe dZddZdS) _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` cCst|drdSd}d}d}|}|\}}}|||fD]}|D] \} } t|| dqq||f||ffD]\} } | D]\} } | rHt| | tjsHq9t|| dq3|D]\} } | rat| |tjsaqRt|| dqR|jry|jd|ddd d|_|j r|jd dd d|_|j r |jd |ddd d|_ d |_ d D]} t |d| r| |_ nqd |_dD]}t |d|r||_nqi|_|j|j}|dur|d|j|D]*\}}g|j|<}|rt|tsJ|}|D]}||gr||qqd|_dS)N cc_is_cached))rZz.*(x|x86_|amd)64.*)rYz.*(win32|x86|i386|i686).*)raz.*(powerpc|ppc)64(el|le).*)rbz.*(powerpc|ppc)64.*)rcz.*(aarch64|arm64).*)rdz.*arm.*) cc_on_noarchr))r[z.*(gcc|gnu\-g).*)r\z .*clang.*)r_z.*(intelw|intelemw|iccw).*)r^z.*(intel|icc).*)r`z.*msvc.*) cc_is_noccr)) cc_has_debugz$.*(O0|Od|ggdb|coverage|debug:full).*) cc_has_nativez".*(-march=native|-xHost|/QxHost).*)rXz.*DISABLE_OPT.*FTz]unable to detect CPU architecture which lead to disable the optimization. check dist_info:<< z >>rz&Optimization is disabled by the Configzunable 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:<< unknownrcc_on_)r r r r r cc_is_z=undefined flag for compiler '%s', leave an empty dict instead)rrrrr IGNORECASEr3rrXrr4r[cc_marchrcc_namecc_flagsrrrr rrsplit cc_test_flagsrr2)re detect_archdetect_compiler detect_argsrr compiler_inforsectionrrgexr=searchinarchrcompiler_flagsrTnflagsr%rWrWrjr~s          z_CCompiler.__init__cCsLt|tsJ|d|tj|jd}|||}|s$|jddd|S)z@ Returns True if the compiler supports 'flags'. z testing flagsz test_flags.ctesting failedTr)rrrryrzrrr)rerT test_pathrrWrWrjr?s  z_CCompiler.cc_test_flagscCsDt|tsJ|js|js|jr||S|js|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'] ) rrr[r\r^_cc_normalize_unixr`r__cc_normalize_win)rerTrWrWrjcc_normalize_flagss    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.]csBfdd}t|dkr|Stt|D]`\}}tj|s q|d|d }|| d}ttjj |}||\}} } |dkrgt| dkrg|D]} || \} } }|| kr]|| } qL| dd | }||g}|dkrt||7}g}t }t|D] }tj |}|sn|d|vrq~| |d|d|q~|S)Nc s@|d}tddtj|d}||d|ddfS)N+0rrr)r>floatrrfindall_cc_normalize_arch_ver)r%tokensverrerWrj ver_flags,s z0_CCompiler._cc_normalize_unix..ver_flagsrrrO)r enumeratereversedrr_cc_normalize_unix_mrgxrfilter_cc_normalize_unix_frgxsearchrr_cc_normalize_unix_krgxaddinsert)rerTrWicur_flag lower_flags upper_flagsfilterdrUrGsubflagsxflagxver_ xsubflags final_flagsmatchedr%rrWrVrjrL+sD     z_CCompiler._cc_normalize_unixz^(?!(/arch\:|/Qx\:))z ^(/arch|/Qx:)cCs^tt|D]&\}}t|j|sq|d7}tt|jj|d| || dS|S)Nr) rXrYrr_cc_normalize_win_mrgxrr[_cc_normalize_win_frgxr])rerTrar%rWrWrjrMbs z_CCompiler._cc_normalize_winN)rrrrr~rr0r?rNrrrZr\r^rSrLrnrmrMrWrWrWrjr1Zs4,h  1 r1c@seZdZdZddZddgfddZddZd%d d Zd%d d ZddZ ddZ ddZ ddZ ddZ ejddZejdgfddZejdgfddZejddZejd d!Zd&d#d$ZdS)'_FeatureaA 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|drdS||_}t|D]G}|||j|}fdd|Dd}|durF| ||j d||ddqdD]}|}t |t rZ| |<qHqt|_|j|jd }| D] }||jvr{|j|qnd|_dS) Nfeature_is_cachedcsi|] \}}|vr||qSrWrW)rkvfeaturerWrj sz%_Feature.__init__..rUzfeature '%s' is disabled,Tr)rr<r=rrTr7r)rrkfeature_supportedrrrupdater rrrrrr>r feature_minrr;upperr_rp) re pfeatures feature_namecfeaturedisabledoptionovalmin_fFrWrsrjr~zs<          z_Feature.__init__NcCsv|dust|tst|dsJ|dust|tsJ|dur$|j}t}|D]}|j|||dr8||q)|S)a 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. macros : list of tuples, optional A list of C macro definitions. Nr force_flagsr) rrrrrvrrfeature_is_supportedr_)renamesrrsupported_namesr%rWrWrj feature_namess   z_Feature.feature_namescCs|sJ||jvS)z Returns True if a certain feature is exist and covered within `_Config.conf_features`. Parameters ---------- 'name': str feature name in uppercase. )isupperr)rerrWrWrjfeature_is_exists z_Feature.feature_is_existFcsfdd}t|||dS)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|tr j|dStfdd|D}|t|d7}|S)Nrcsg|] }j|dqS)r)rvrr%rVrWrjrsz<_Feature.feature_sorted..sort_cb..r)rrrvmaxr)rqrankrVrWrjsort_cbs z(_Feature.feature_sorted..sort_cb)reversekey)sorted)rerrrrWrVrjfeature_sorteds  z_Feature.feature_sortedcsltffdd t|tr|}|g}nt|dsJt}|D] }||}q#|s4|||S)a Return a set of CPU features that implied by 'names' Parameters ---------- names: str or sequence of str CPU feature name(s) in uppercase. keep_origins: bool if False(default) then the returned set will not contain any features from 'names'. This case happens only when two features imply each other. Examples -------- >>> 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'} csTt}j|}|dgD]}||||vrq|||||}q|S)Nr)rrvrr_union)r_callerrr#ra get_impliesrerWrjrs   z-_Feature.feature_implies..get_impliesr)rrrrrdifference_update)rer keep_originsrnrWrrjfeature_impliess  z_Feature.feature_impliescCs.t|tr t|f}nt|}|||S)z/same as feature_implies() but combining 'names')rrrrr)rerrWrWrjfeature_implies_cs  z_Feature.feature_implies_ccs^t|ts t|ds J|j|ddfdd|D}t|dkr-|j|dddd }|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"] rT)rcg|]}|vr|qSrWrW)rrrrWrjr>z*_Feature.feature_ahead..rrNr)rrrrrr)reraheadrWrrj feature_aheads z_Feature.feature_aheadcst|ts t|ds Jg}|D]5fdd|D}|r@|g}|ddvr5q||ddd|q|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"] rcs&g|]}|vr|vr|qSrW)r)rnnrrrerWrjrbs z+_Feature.feature_untied..rNr)rrrrrremover)rerfinaltiedrWrrjfeature_untiedEs"  z_Feature.feature_untiedcs^fddt|tst|dkr|}||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}t|D]\}}j|ds(|d|d}|Sq|S)NTrr)rrrXrvr)tnamesrar) keyisfalsererWrjtilus z%_Feature.feature_get_til..tilrcsh|] }|D]}|qqSrWrW)rrt)rrWrj sz+_Feature.feature_get_til..)rrrrrr)rerrrW)rrerrjfeature_get_tilns   z_Feature.feature_get_tilc CsB||d}g}|D]}|j|}||d|d|g7}q |S)z Return a list of CPU features that required to be detected sorted from the lowest to highest interest. r)r=r<)rrvr)rerr=rr#rWrWrjfeature_detects  z_Feature.feature_detectcCsV|||}g}|D]}|j|}|dg}|r ||s!q ||7}q ||S)zi Return a list of CPU features flags sorted from the lowest to highest interest. rT)rrrvrr?rN)rerrTrr#r%rWrWrj feature_flagss    z_Feature.feature_flagscCs|dur ||}|d|d|ftj|jd|}tj|s-|d||j |||j d|d}|sC|jdd d |S) a 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. macros : list of tuples, optional A list of C macro definitions. Nz$testing feature '%s' with flags (%s)rzcpu_%s.czfeature test file is not existrrrJTr) rrrryrzrlowerrrrr=)rerrrrKrrWrWrj feature_tests$    z_Feature.feature_testcCsn|sJ|dust|tsJ||jv}|r5||D] }|j|||ds*dSq|j|||ds5dS|S)a Check if a certain CPU feature is supported by the platform and compiler. Parameters ---------- name: str CPU feature name in uppercase. force_flags: list or None, optional If None(default), default compiler flags for every CPU feature will be used during test. macros : list of tuples, optional A list of C macro definitions. NrF)rrrrvrr)rerrr supportedimplrWrWrjrs  z_Feature.feature_is_supportedcsVt|tsJj|}|dd}|dur)fdd|dgD}|o(t|}|S)zM check if the feature can be auto-vectorized by the compiler rVNcsg|]}|gqSrW)r?rrVrWrjrs z0_Feature.feature_can_autovec..rT)rrrvrany)rerr#can valid_flagsrWrVrjfeature_can_autovecs     z_Feature.feature_can_autovecc Cst|tsJ|j|}|dg}|sgS|d||||}g}g}|D]2}tj|j d| }tj |sC| d|| |||jd} | rV||q)||q)|rf|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. r7z%Testing extra checks for feature '%s'z extra_%s.czextra check file does not existrztesting failed for checksTr)rrrvrrrryrzrrrrrrr=r) rerr#r7rT available not_availablechkrK is_supportedrWrWrjfeature_extra_checkss,       z_Feature.feature_extra_checksrcs|sJ|j|}|dusJd|d|j|fg}|dd|dgD7}|dg}|||7}|D]}|d|j|fd |j|fd g7}q9d krZfd 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 1cSg|]}d|qS)z #include <%s>rW)rrrWrWrjr>z3_Feature.feature_c_preprocessor..rr<z#ifndef %sHAVE_%sz #define %sHAVE_%s 1z#endifrcsg|]}d|qS) rW)rltabsrWrjrNr )rrvrrrr)rer{rrtprepr extra_defsedefrWrrjfeature_c_preprocessor s(         z_Feature.feature_c_preprocessorF)r)rrrrr~rrrrrrrrrrr0rrrrrrrWrWrWrjrols. "# 1&) '  &roc@seZdZdZddZddZedZddZ ed Z d d Z d d Z ddZ ddZddZddZddZddZddZddZdS)_ParseaA 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 stdjgfjjgfjdgfjdgfjddgfd_tdr'dSg_ g_ g_ i_ j r:d}}d|dur]d|}|}|_ |_ d|durd|}fdd |D}||}|_ t|d krd |d d jD]-\}}d||}|r|sdggfj |<q|\} } } | | | fj |<qd_dS)NMAXOPT) KEEP_BASELINE KEEP_SORTrWERRORAUTOVECparse_is_cachedzcheck requested baseline cpu_baselinez&check requested dispatch-able features cpu_dispatchcsh|] }|jvr|qSrWparse_baseline_namesrrVrWrjrs  z"_Parse.__init__..rz skip featureszsince its part of baselinezinitialize targets groupszparse target groupFT)r]_parse_policy_not_keepbase_parse_policy_keepsort_parse_policy_not_keepsort_parse_policy_maxopt_parse_policy_werror_parse_policy_autovec_parse_policiesrrparse_baseline_flagsparse_dispatch_namesparse_target_groupsrXr_parse_arg_featuresrrrr differencerrr rystrip_parse_target_tokensr) rerrbaseline_names cpu_dispatch_conflict_baseline group_namerT GROUP_NAME has_baselinefeatures extra_flagsrWrVrjr~sz               z_Parse.__init__c Cs|d|t|U}d}d}d}d}d}d}t|D]<\} } | |kr*|dn.|dkr>| |}|dkr8q|t|7}|| 7}| |}|dkrW|t|t| 7}nqWdn1sbwY|dkrr|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 -> riz@targetsz*/zreached the max of linesNz(expected to find '%s' within a C commentzexpected to end with '%s')rrrXrfindrr) rerfdrT max_to_reach start_with start_posend_withend_pos current_linelinerWrWrj parse_targetss>        z_Parse.parse_targetsz \s|,|([+-])c Cs:t|ts |d|t}ttdt|j|}d}|D]{}|ddvr-||d|dkr4d}q|dkr;d}q| }t}|d krGnD|d kra|j d } | sX||d |j | d gd}n*|dkrk|j }n |dkrs|j}n||j vr~||n ||s||d||r||}n||}d}q|S)Nzexpected a string in '%s'Tr)#$zYtarget groups and policies aren't allowed from arguments, only from dispatch-able sourcesrO-FNONENATIVErz-native option isn't supported by the compiler)DETECT_FEATURESrrMAXMINz&, '%s' isn't a known feature or option)rrrrrr[rr>_parse_regex_argryr=rrvrrxr_rrr) rearg_name req_featuresfinal_featuresrTrtokTOK features_torrWrWrjr sX         z_Parse._parse_arg_featuresz\s|[*,/]|([()])cCst|tsJg}g}d}t}t}d}ttdt|j|}|s(|d|D]}| } |d} | dvr>|dq*| dkrT|durK|d| | | q*| dkrm|dura|d | | |||\}}}q*| d kr~|durz|d t}q*| d kr|dur|d | |} | dur| t|nt| dkr| d} | r| |vr|| d}q*| dkr|dur|dd}q*|dur| | q*|| s|d| | |jvp| |jv} | r| |vr|| q*| | q*|dur|d |r |d|d||}t|D]&} |j| \}}}|D]}||vr'q|d| |f| |qq|jD])\} \}}}d}| |vrV|}|d| n|}|s]q>||||\}}}q>|||fS)NFzexpected one token at leastr)rOrze+/- are 'not' allowed from target's groups or @targets, only from cpu_baseline and cpu_dispatch parmsrzCpolicies aren't allowed inside multi-target '()', only CPU featuresrzHtarget groups aren't allowed inside multi-target '()', only CPU featuresrz"unclosed multi-target, missing ')'rz$multi-target opener '(' wasn't foundrBASELINEz/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)rrrrr[rr>_parse_regex_targetrryr__parse_token_policy_parse_token_group_parse_multi_targettuplerrrrrrrrr )rerT final_targetsrrskippedpolicies multi_targetrrchtargets is_enabledpridepsr#havenhavefuncrWrWrjrBs                     z_Parse._parse_target_tokenscCsZt|dks|dd|dkr|d|dd}||jvr+|d||j|S)zvalidate policy tokenrrNrz*'$' must stuck in the begin of policy namez6'%s' is an invalid policy name, available policies are)rrrr)retokenrWrWrjrs    z_Parse._parse_token_policycst|dks|dd|dkr|d|dd}|j|ddgf\}}}|dur9|d|d|j|r=d }fd d |D7fd d |D7|fS) zvalidate group tokenrrNrz)'#' must stuck in the begin of group nameFz&'%s' is an invalid target group name, zavailable target groups areTcrrWrWr)r rWrjrrz-_Parse._parse_token_group..crrWrWr)rrWrjrr)rrrrr)rerrr r ghas_baselinegtargets gextra_flagsrW)rr rjrs$      z_Parse._parse_token_groupcsr|sdtfdd|Dsd|tfdd|Ds%dS|}|s.dS|}t|}|S)z9validate multi targets that defined between parentheses()zempty multi-target '()'cg|]}|qSrW)rrtarrVrWrjrs z._Parse._parse_multi_target..z#invalid target name in multi-targetcs g|] }|jvp |jvqSrW)rrrrVrWrjrs  N)rallrrr )rerrWrVrjrs       z_Parse._parse_multi_targetcsxg}|ddD]&}d}t|tr|jv}n tfdd|D}|r.||||q|r7d||||fS)zskip all baseline featuresNFcsg|]}|jvqSrWrrrVrWrjrz5_Parse._parse_policy_not_keepbase..zskip baseline features)rrrrrrr)rerr rr ris_baserWrVrjrs       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)rrerr rrWrWrjrs z_Parse._parse_policy_keepsortcCs|j|dd}|||fS)z%sorted depend on the highest interestTr)rr rWrWrjrs z!_Parse._parse_policy_not_keepsortcCsT|jr |dn|jr|dn|jd}|s!|jdddn||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 skippedTr)r5rrXr=rerr rrTrWrWrjrs    z_Parse._parse_policy_maxoptcCs:|jd}|s|jdddn |d||7}|||fS)z#force warnings to treated as errorsrzTcurrent compiler doesn't support werror flags, warnings will 'not' treated as errorsTrz'compiler warnings are treated as errors)r=rr!rWrWrjr&s   z_Parse._parse_policy_werrorcstg}|ddD]$}t|tr|}n tfdd|D}|s,||||q|r5d||||fS)z=skip features that has no auto-vectorized support by compilerNcrrW)rrrrVrWrjr:rz0_Parse._parse_policy_autovec..z!skip non auto-vectorized features)rrrrrrr)rerr rr rrrWrVrjr3s       z_Parse._parse_policy_autovecN)rrrrr~rrrrrrrrrrrrrrrrrWrWrWrjrQs".R 6 8t   rc@sjeZdZdZdddZddZd d Zd d Zd dZdddZ ddZ dddZ dddZ dddZ 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. minrNcCst|t||t|||||t|t||js-|jr-| dd}t |||||_ ||_ t |di|_|jdt|d|_dS)NzSnative flag is specified through environment variables. force cpu-baseline='native'rsources_status hit_cache)rr~rrrr1rorXr6rr_requested_baseline_requested_dispatchrr%rr_rr&)rerrrrrWrWrjr~Ms      zCCompilerOpt.__init__cCs |jo|jS)zF Returns True if the class loaded from the cache file )rr&rVrWrWrj is_cachedgs zCCompilerOpt.is_cachedcC|jS)zE Returns a list of final CPU baseline compiler flags )rrVrWrWrjcpu_baseline_flagsmzCCompilerOpt.cpu_baseline_flagscCr*)zC return a list of final CPU baseline feature names rrVrWrWrjcpu_baseline_namessr,zCCompilerOpt.cpu_baseline_namescCr*)zC return a list of final CPU dispatch feature names )rrVrWrWrjcpu_dispatch_namesyr,zCCompilerOpt.cpu_dispatch_namescKs&i}|}|dg}|D]g}tj|} |r-| |s$tj|| } | |vr-|| ||\} } } | | || | } | D]}|j | ||| d}t | | |}||g|q?| rnt | |}||g|| | f|j |<qg}|D]\}}||j|t|fd|i|7}q||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. ccompiler: CCompiler Distutils `CCompiler` instance to be used for compilation. If None (default), the provided instance during the initialization will be used instead. **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)nochanger)r+ setdefaultryrzr startswithrrr_generate_config _wrap_targetr rr%r rr)rersrc_dirrr to_compilebaseline_flagsr/srcrrrrr0rtar_srcrTobjectssrcsrWrWrj try_dispatchs</      zCCompilerOpt.try_dispatchc snd|}}t|}t|}tj|}tj|s3jd|dddt|t |du}d fdd |D}d fd d |D} | t d jjd |d ||||| d d} |D] } | j| ddd7} qnd} |D]} | t djj| j| ddd7} q| t djj| | dWddS1swYdS)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 itTrr \ cg|] }dj|fqSz3 %sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__))rrrVrWrjr z9CCompilerOpt.generate_dispatch_header..cr>r?r@rrVrWrjrrAa /* * 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)pfx baseline_str dispatch_str baseline_len dispatch_lenbaseline_callsdispatch_callsrrrrz #ifdef {pfx}CPU_TARGET_{name} {pre} #endif /*{pfx}CPU_TARGET_{name}*/ )rBrprez /******* baseline features *******/ {baseline_pre} /******* dispatch features *******/ {dispatch_pre} )rB baseline_pre dispatch_preN)rr-r.rryrzrrrrrrrr r!rrr) re header_pathrdispatch_namesrErF header_dirr%rGrHrJrrKrWrVrjgenerate_dispatch_headersV             "z%CCompilerOpt.generate_dispatch_headerFc Csg}g}g}g}|d|f|d|d|f|d|d|f|d|jr/dn|jf|d|jr.cSs&g|]\}}|D]\}}t|qqSrWrZ)rrirowscolrWrWrjr s&z z: r)rr3r;r4r<rXreprr'r-rr+rr(r.r%r r1rrrrrrrr) refullreport platform_rows baseline_rows dispatch_rowsrr7r7rrMtarget_sourcesrrirr generatedr pretty_namerTrr=r8textsecs_lencols_lentabpadsecr\r]rrWrWrjr`) s      "      zCCompilerOpt.reportc st|ttfs Jt|tr|}}n d|}d|}tj|tj|}djgtj|| R}|rBtj |rB|S| d|| | |}d|jfdd|D} d| } t|d } | td j|j|tj|| d Wd|S1swY|S) N.__z {0}.{2}{1}zwrap dispatch-able target -> z#define %sCPU_TARGET_csg|]}|qSrWrWr target_joinrWrjr sz-CCompilerOpt._wrap_target..rraR /** * 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}" )rB target_namerz target_defs)rrr rryrzbasenamer!splitextrrrrrrrrrr abspath) rer dispatch_srctargetr0ext_namerq wrap_pathrrrrrWrorjr4 s0             zCCompilerOpt._wrap_targetc Cstj|}tj|dd}tj||}|||}z5t|'}|d}t |dkrBt |d|krB WdWdSWdn1sLwYWn t y[Ynw| d|g} |D].} t | trp| } n dd d | D} || } d d d | D} | d |j| | fqfd| } |rd|j} nd} t|d}|tdj|j| | |dWddS1swYdS)Nrz.hz cache_hash:rrTzgenerate dispatched config -> rncSsg|]}|qSrWrWr"rWrWrjr sz1CCompilerOpt._generate_config..z&&cSr)zCHK(%s)rWrrWrWrjr rz2 %sCPU_DISPATCH_EXPAND_(CB((%s), %s, __VA_ARGS__))r=z( %sCPU_DISPATCH_EXPAND_(CB(__VA_ARGS__))rraZ // 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} )rBrGrHrF)ryrzrsrtrrrreadliner>rintrnrrrrrrrrr r!)rerrvrr config_pathrr% last_hashrHrrq req_detectrGrrWrWrjr3 s^            zCCompilerOpt._generate_config)r$rN)NNr)rrrrr~r)r+r-r.r<rOr`r4r3rWrWrWrjr#Gs  W S m&r#cKs2t|fi|}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#ryrzrr)rO)rdispatch_hpathrrrWrWrjnew_ccompiler_opt s r)rsysioryrrrrrvrrrr rr1rorr#rrWrWrWrjs8H ; hy 4