B @`%t @sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z GdddZ GdddZ iZ GdddZ Gd d d eZGd 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#@s2eZdZdZdZdZdZdZej ej ej e dZiZdZdZeeddd d eddd d ed dd d ed d dd edddd dZedddddddZeeddddedddded dd!ded"d#d$ded%d&d'ded(d)d*ded+d,d-ed.d/d0dd1ed2d3d4ded5d3d4ded6d3d-ed7d8d-ed9d8d-ed:d;ddd?d-ed@dAdBdCddDedEdCdFdGddDedHdAdIdJddKdLedMdJdNdOdPedQdJdRdSddDedTdUdVdWddDeddXdYeddZdd[ed d\dd[edd]dYedd^d-ed d_d-ed"d`dd[ed%dad-ed(dad-ed+dbd-dcZdddeZdfdgZdS)h_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 FNZchecksZNPY_ZNPY__z -march=nativez-O3z-Werror)nativeoptwerrorz-xHostz/QxHostz/O3z/Werrorz/O2z/WX)gccclangicciccwmsvczSSE SSE2z SSE SSE2 SSE3zVSX VSX2zNEON NEON_FP16 NEON_VFPV4 ASIMD)x86x64ppc64ppc64learmhfaarch64z xmmintrin.hSSE2)interestheadersimpliesSSEz emmintrin.h)rrrz pmmintrin.hSSE3z tmmintrin.hSSSE3z smmintrin.hSSE41zpopcntintrin.hPOPCNT)rrSSE42z immintrin.h)rrrimplies_detect AVXz x86intrin.h F16C z FMA3 AVX2ZAVX512F_REDUCE)rrr$ extra_checksAVX512F(AVX512CDzAVX512ER AVX512PF AVX512_KNL)rrgroupdetectr$)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)rrVSX)rrr$VSX2z arm_neon.hNEON NEON_FP16zNEON_FP16 NEON_VFPV4ASIMDASIMDHP)rrrrrr!r#r&XOPFMA4r*FMA3AVX2r/r1r2r6r8r:r<r>r?r@VSX3rArB NEON_VFPV4rCrDASIMDDPASIMDFHMcCs|jr iS|jp|j}|jp |j}|r|rttddtddtddtddtddtddtddtd dtd dtd dtd dtd dtddtddtddtddtddtddtddtddtdddS|r|jrttddtddtddtddtdditddtd ditddtddtdddtdddtdddtd ddtd!dtd"dtd#dtd$dtd%dtd&ddS|rN|jrNttd'dtd(dtd)dtd*dtd+ditd,dtd-ditddtddtdd.dtdd.dtdd/dtd d/dtd0dtd1dtd2dtd3dtd4dtd5ddS|r|jrttd'dtd(diiitd6d7itd-ditd8d7td8d7tdd9dtd:d9dtd;ddtd>dtdz!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)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)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_clangdict cc_is_icc cc_is_iccw cc_is_msvc cc_on_ppc64le cc_on_ppc64 cc_on_aarch64 cc_on_armhf)selfZon_x86Zis_unixZon_powerpartialr_A/tmp/pip-unpacked-wheel-ecq9wray/numpy/distutils/ccompiler_opt.pyconf_features_partial*s>         z_Config.conf_features_partialcsb|jdkr@ddl}ddl|fdd}t||_|jdkr^tj t |j g|_dS)Nrcs(yWntk r"YnXdS)N)rmtreeIOErrorr_)shutiltmpr_r`rm_tempsz!_Config.__init__..rm_temp) conf_tmp_pathtempfilerdmkdtempatexitregisterconf_cache_factorsospathgetmtime__file__ conf_nocache)r]rhrfr_)rdrer`__init__s    z_Config.__init__)__name__ __module__ __qualname____doc__rq conf_nooptrlrgrmrnjoindirnamerealpathrpconf_check_pathconf_target_groups conf_c_prefixconf_c_prefix_rU conf_cc_flagsconf_min_features conf_featuresrarrr_r_r_r`r s"                      Wrc@seZdZdZddZddZddZdd Zed d Z ed d Z 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 ||_dS)N) _ccompiler)r] ccompilerr_r_r`rrsz_Distutils.__init__cKsDt|tstt|tst|dg|}|jj|fd|i|S)zWrap CCompiler.compile()Zextra_postargs) isinstancelistAssertionErrorpoprcompile)r]sourcesrMkwargsr_r_r` dist_compile"s z_Distutils.dist_compilec Cst|tstddlm}|j}t|dd}|rdt|jdd}|dkrVt|d|jnt|d|j d}y|j |g||j d d }Wn4|k r}z|j t|d d Wdd}~XYnX|rt|d||S) zgReturn True if 'CCompiler.compile()' able to compile a source file with certain flags. r) CompileErrorspawnN compiler_typer )r F) output_dirT)stderr) rstrrdistutils.errorsrrgetattrsetattr_dist_test_spawn_paths_dist_test_spawnrrgdist_log) r]sourcerMrccZbk_spawncc_typetester_r_r` dist_test+s&  $ z_Distutils.dist_testcCst|dr|jSt|jdd}|dkr,d}n |dkr:d}ndd lm}|}t|jd t|jd d}|rp|d krt|d r|d}qt|}n|}t|d rt|dkrd|dd}n t 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 )ZintelemZintelemwx86_64)intelZintelwZinteler r) get_platformcompiler compiler_sounix__iter__r NCFLAGSCPPFLAGS) hasattrrrrdistutils.utilrrlenrxrmenvironget)r]rplatformrZcc_infor extra_argsr_r_r` dist_infoEs*       z_Distutils.dist_infocGsddlm}|tj|dS)zRaise a compiler errorr)rN)rrr _dist_str)argsrr_r_r` dist_errorjs z_Distutils.dist_errorcGsddlm}|tj|dS)zRaise a distutils errorr)DistutilsErrorN)rrrr)rrr_r_r` dist_fatalps z_Distutils.dist_fatalF)rcGs4ddlm}tj|}|r&||n ||dS)zPrint a console messager)logN)Znumpy.distutilsrrrwarninfo)rrroutr_r_r`rvs    z_Distutils.dist_logc CsLddlm}y |||Stk rF}ztj|ddWdd}~XYnXdS)zALoad a module from file, required by the abstract class '_Cache'.r)npy_load_moduleT)rN)Z numpy.compatr Exceptionrr)namernrrr_r_r`dist_load_modules    z_Distutils.dist_load_modulecsJfddtd}d|j|jf}dfdd|D}||S)z+Return a string to print by log and errors.csNt|tsFt|drFg}x|D]}||qWdd|dSt|S)Nr(r))rrrappendrx)argreta)to_strr_r`rs  z$_Distutils._dist_str..to_strrzCCompilerOpt.%s[%d] : rcsg|] }|qSr_r_).0r)rr_r` sz(_Distutils._dist_str..)inspectstackfunctionlinenorx)rrstartrr_)rr`rs    z_Distutils._dist_strNc CsRt|jds||dStd}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)rrrrmgetenvrr)r]cmddisplayold_pathr_r_r`rs   z!_Distutils._dist_test_spawn_pathsz/.*(warning D9002|invalid argument for option).*c Csddlm}y:tj|tjdd}|rDttj|rDt d|d|WnJtj k rv}z|j }|j }Wdd}~XYn t k rd}d}YnXdSt d |d ||fdS) Nr)rT)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)rrroexcsr_r_r`rs$    z_Distutils._dist_test_spawn)N)N)rsrtrurvrrrrr staticmethodrrrrrrrrrrr_r_r_r`rs   %    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_)NcGsfi|_t|_d|_|jr(|ddS|j||j}|rtj |r|d|| d|}|st|jdddnnt |drt |d s|jd ddnJ||j kr|d x"|jD]\}}t|||qWd|_n |d t|j|||jsZt|}|rZ|d xD|jD]6\}}||jks t|j|rHq t|||q W|t|<dS)NFzcache is disabled by `Config`zload cache from file ->cachez)unable to load the cache file as a moduleT)rhashdatazinvalid cache filezhit the file cachezmiss the file cachezhit the memory cache)cache_meset cache_private cache_infilerqr cache_hashrlrmrnexistsrrrritemsrrjrk _cache_write _share_cacher__dict__rr _cache_ignore)r] cache_pathfactorschashZ cache_modattrvalZ other_cacher_r_r`rrsF             z_Cache.__init__cCsdS)Nr_)r]r_r_r`__del__sz_Cache.__del__c Cs|d|x0t|jD]}t|j|r|j|qWtj |}tj |s`t |t j|jdd}t|d&}|td|||WdQRXdS)Nzwrite cache to path ->T)compactwz # AUTOGENERATED DON'T EDIT # Please make changes to the code generator (distutils/ccompiler_opt.py) hash = {} data = \ )rrrkeysrrrrrmrnryrmakedirspprintpformatopenwritetextwrapdedentformat)r]rrrd repr_dictfr_r_r`rs     z_Cache._cache_writecGsLd}xB|D]:}x4t|D](}t||d>|d>|}|dM}qWq W|S)Nrrl)rord)r]rrrcharr_r_r`r0s  z_Cache.cache_hashcsfdd}|S)zr A static method that can be treated as a decorator to dynamically cache certain methods. csNtjf|||}||jkr0|j|S|f||}||j|<|S)N)rrsrvaluesr)r]rr 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) rsrtrurvrrrrrrrrrrr_r_r_r`rs  , 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` cCsJt|drdSd}d}d}|}|\}}}x0|||fD]"}x|D]\} } t|| dqBWq8WxR||f||ffD]>\} } x4| D],\} } | rt| | tjsq~t|| dPq~WqpWx2|D]*\} } | rt| |tjsqt|| dqW|jr |jd|ddd d|_|j r&|jd dd d|_|j rJ|jd |ddd d|_ d |_ x&d D]} t |d| rV| |_ PqVWd |_x&dD]}t |d|r||_PqWi|_|j|j}|dkr|d|jxj|D]^\}}g|j|<}|rt|ts t|}x&|D]}||gr||qWqWd|_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 >>)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:<< unknown)r r rrrrZcc_on_)rrr rr Zcc_is_z=undefined flag for compiler '%s', leave an empty dict instead)rrrrr IGNORECASErrrPrwrrScc_marchrcc_namecc_flagsrrrrrrrsplit cc_test_flagsrr)r]Z detect_archZdetect_compilerZ detect_argsrrZ compiler_inforsectionrZrgexr4ZsearchinarchrZcompiler_flagsrMZnflagsrr_r_r`rryst             z_CCompiler.__init__cCsLt|tst|d|tj|jd}|||}|sH|jddd|S)z@ Returns True if the compiler supports 'flags'. z testing flagsz test_flags.cztesting failedT)r) rrrrrmrnrxr{r)r]rM test_pathrr_r_r`rs  z_CCompiler.cc_test_flagscCsDt|tst|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'] ) rrrrSrTrV_cc_normalize_unixrXrW_cc_normalize_win)r]rMr_r_r`cc_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.]csZfdd}t|dkr|Sxtt|D]\}}tj|sBq*|d|d }|| d}ttjj |}||\}} } |dkrt| dkrx*|D]"} || \} } }|| kr|| } qW| dd | }||g}|dkr||7}Pq*Wg}t }xVt|D]J}tj |}|s"n"|d|kr6qn| |d|d|qW|S)Nc s@|d}tddtj|d}||d|ddfS)N+0r rr)rfloatrxrfindall_cc_normalize_arch_ver)rtokensver)r]r_r` ver_flagss z0_CCompiler._cc_normalize_unix..ver_flagsrrr")r enumeratereversedrr_cc_normalize_unix_mrgxrfilter_cc_normalize_unix_frgxsearchrxr_cc_normalize_unix_krgxaddinsert)r]rMr)iZcur_flagZ lower_flagsZ upper_flagsZfilterdr(rZsubflagsZxflagZxver_Z xsubflagsZ final_flagsmatchedrrr_)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| || dSW|S)Nr) r*r+rr_cc_normalize_win_mrgxrr-_cc_normalize_win_frgxr/)r]rMr3rr_r_r`r Tsz_CCompiler._cc_normalize_winN)rsrtrurvrrrrrr!rrr,r.r0r&rr7r6r r_r_r_r`rLs$,h 1rc@seZdZdZddZd%ddZddZd&d d Zd'd d ZddZ ddZ ddZ ddZ ddZ ejddZejd(ddZejd)ddZejddZejd 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||_}xt|D]}|||j|}fdd|Dd}|dk r| ||j d||ddq*x,dD]$}|}t |t r| |<qWq*Wt|_|j|jd }x*| D]}||jkr|j|qWd|_dS) Nfeature_is_cachedcsi|]\}}|kr||qSr_r_)rkv)featurer_r` ssz%_Feature.__init__..rNzfeature '%s' is disabled,T)r)rr3r4rrMr-r )rrafeature_supportedrrrupdaterrrrrrrr feature_minrrupperr1r9) r]Z pfeatures feature_nameZcfeaturedisabledoptionZovalZmin_fFr_)r<r`rrls4        z_Feature.__init__NcCsx|dks t|tst|ds t|dks6t|ts6t|dkrH|j}t}x$|D]}|j||drT| |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) rrrrrr>rrfeature_is_supportedr1)r]namesrFZsupported_namesrr_r_r` feature_namess   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. )isupperrr)r]rr_r_r`feature_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|trj|dStfdd|D}|t|d7}|S)Nrcsg|]}j|dqS)r)r>)rr)r]r_r`rsz<_Feature.feature_sorted..sort_cb..r)rrr>maxr)r:Zrank)r]r_r`sort_cbs  z(_Feature.feature_sorted..sort_cb)reversekey)sorted)r]rHrNrMr_)r]r`feature_sorteds z_Feature.feature_sortedcsptffdd t|tr.|}|g}n0t|ds>> 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|dgD]2}||||kr6q|||||}qW|S)Nr)rr>rr1union)rZ_callerrrr3) get_impliesr]r_r`rSs   z-_Feature.feature_implies..get_impliesr)rrrrrrRdifference_update)r]rH keep_originsrnr_)rSr]r`feature_impliess   z_Feature.feature_impliescCs.t|trt|f}nt|}|||S)z/same as feature_implies() but combining 'names')rrrrRrW)r]rHr_r_r`feature_implies_cs  z_Feature.feature_implies_ccs^t|tst|dst|j|ddfdd|D}t|dkrZ|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)rUcsg|]}|kr|qSr_r_)rrV)rr_r`r+sz*_Feature.feature_ahead..r)rNNr)rrrrrWrrQ)r]rHZaheadr_)rr` feature_ahead s  z_Feature.feature_aheadcst|tst|dstg}xr|D]jfdd|D}|r|g}|ddkrlq"||ddd|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"] rcs&g|]}|kr|kr|qSr_)rW)rnn)rrVr]r_r`rPsz+_Feature.feature_untied..rNr)rrrrrWrQremover)r]rHfinalZtiedr_)rrVr]r`feature_untied2s   z_Feature.feature_untiedcs^fddt|ts$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|ds"|d|d}Pq"W|S)NT)rNr)rXrQr*r>r)Ztnamesr3rV) keyisfalser]r_r`tilbs z%_Feature.feature_get_til..tilrcsh|]}|D]}|qqSr_r_)rrVt)r_r_r` ssz+_Feature.feature_get_til..)rrrrNrYrQ)r]rHr^r_)r^r]r_r`feature_get_til[s  z_Feature.feature_get_tilc CsF||d}g}x0|D](}|j|}||d|d|g7}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>rrr!)r]rHrMrVrrr_r_r` feature_flagss    z_Feature.feature_flagscCs|dkr||}|d|d|ftj|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)rzcpu_%s.czfeature test file is not existrztesting failedT)r) rdrrxrmrnr{lowerrrrr)r]rrFrrr_r_r` feature_tests   z_Feature.feature_testcCsh|s t|dks"t|ts"t||jk}|rdx"||D]}|||srWrf)r]rrF supportedimplr_r_r`rGs    z_Feature.feature_is_supportedcsVt|tstj|}|dd}|dkrRfdd|dgD}|oPt|}|S)zM check if the feature can be auto-vectorized by the compiler rONcsg|]}|gqSr_)r)rr)r]r_r`rsz0_Feature.feature_can_autovec..rM)rrrr>rany)r]rrcanZ valid_flagsr_)r]r`feature_can_autovecs   z_Feature.feature_can_autovecc Cst|tst|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)rrrr>rrrdrmrnrxr{rerrrrr) r]rrr-rM availableZ not_availableZchkr is_supportedr_r_r`feature_extra_checkss*        z_Feature.feature_extra_checksrcs|s t|j|}|dk s$td|d|j|fg}|dd|dgD7}|dg}|||7}x.|D]&}|d|j|fd |j|fd g7}qtWd krfd 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_)rhr_r_r`r$sz3_Feature.feature_c_preprocessor..rr3z#ifndef %sHAVE_%sz #define %sHAVE_%s 1z#endifrcsg|]}d|qS) r_)rl)tabsr_r`r3s )rJrr>rr}rnrx)r]rBrrr<ZpreprZ extra_defsZedefr_)rrr`feature_c_preprocessors"        z_Feature.feature_c_preprocessor)NN)F)F)N)N)r)rsrtrurvrrrIrKrQrWrXrYr]rbrcrrrdrfrGrkrnrtr_r_r_r`r8^s& "   1&)  " 'r8c@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_tdrNdSg_ g_ g_ i_ j rtd}}d|dk rd|}|}|_ |_ d|dk r$d|}fdd |D}||}|_ t|d kr$d |d d xpjD]b\}}d||}|rf|szdggfj |<q:|\} } } | | | fj |<q:Wd_dS)NMAXOPT)Z KEEP_BASELINEZ KEEP_SORTrvZWERRORZAUTOVECparse_is_cachedzcheck requested baseline cpu_baselinez&check requested dispatch-able features cpu_dispatchcsh|]}|jkr|qSr_)parse_baseline_names)rr)r]r_r`rasz"_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_policiesrrzparse_baseline_flagsparse_dispatch_namesparse_target_groupsrPr_parse_arg_featuresrIrdrQrX differencerr|rrAstrip_parse_target_tokensrw) r]rxrybaseline_namesZ cpu_dispatch_Zconflict_baselineZ group_namer'Z GROUP_NAME has_baselinefeatures extra_flagsr_)r]r`rres`             z_Parse.__init__c Cs|d|t|}d}d}d}d}d}d}xt|D]t\} } | |krT|dP|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 iz@targetsz*/zreached the max of linesNz(expected to find '%s' within a C commentzexpected to end with '%s')rrr*rfindrr) r]rfdr'Z max_to_reachZ start_withZ start_posZend_withZend_pos current_lineliner_r_r` parse_targetss8       z_Parse.parse_targetsz \s|[,]|([+-])c Cs>t|ts|d|t}ttdt|j|}d}x|D]}|ddkr\||d|dkrjd}q@|dkrxd}q@| }t}|d krn|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"-FNONEZNATIVErz-native option isn't supported by the compiler)rFMAXZMINz&, '%s' isn't a known feature or option)rrrrrr-rr_parse_regex_argrArrIr>rr@r1rKrRr) r]Zarg_nameZ req_featuresZfinal_featuresr'rtokTOKZ features_torr_r_r`rsN           z_Parse._parse_arg_featuresz\s|[*,/]|([()])cCs t|tstg}g}d}t}t}d}ttdt|j|}|sP| dx|D]}| } |d} | dkr| dqX| dkr|dk r| d| | | qX| dkr|dk r| d | | |||\}}}qX| d kr|dk r| d t}qX| d kr~|dkr$| d ||} | dkrH| t|n0t| dkr^| d} | rx| |krx|| d}qX| dkr|dk r| dd}qX|dk r| | qX|| s| d| | |jkp| |jk} | r| |krX|| qX| | qXW|dk r$| d |r8|d|d||}x\t|D]P} |j| \}}}x8|D]0}||krxqf|d| |f| |qfWqLWx`|jD]R\} \}}}d}| |kr|}|d| n|}|sq||||\}}}qW|||fS)NFzexpected one token at leastr)r"rze+/- 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 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)rrrrrr-rr_parse_regex_targetrrAr1_parse_token_policy_parse_token_group_parse_multi_targettuplerrrKrzrrr]rr)r]r' final_targetsrrskippedZpoliciesZ multi_targetrrchtargets is_enabledpr4depsrZhaveZnhavefuncr_r_r`r%s                          z_Parse._parse_target_tokenscCsZt|dks |dd|dkr*|d|dd}||jkrV|d||j|S)zvalidate policy tokenrrNrz*'$' must stuck in the begin of policy namez6'%s' is an invalid policy name, available policies are)rrrr)r]tokenr_r_r`rs     z_Parse._parse_token_policycst|dks |dd|dkr*|d|dd}|j|ddgf\}}}|dkrr|d|d|j|rzd }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 areTcsg|]}|kr|qSr_r_)rr)rr_r`rsz-_Parse._parse_token_group..csg|]}|kr|qSr_r_)rr)rr_r`rs)rrrrr)r]rrrrZ ghas_baselineZgtargetsZ gextra_flagsr_)rrr`rs    z_Parse._parse_token_groupcsr|sdtfdd|Ds0d|tfdd|DsJdS|}|s\dS|}t|}|S)z9validate multi targets that defined between parentheses()zempty multi-target '()'csg|]}|qSr_)rK)rtar)r]r_r`rsz._Parse._parse_multi_target..z#invalid target name in multi-targetcs g|]}|jkp|jkqSr_)rzr)rr)r]r_r`rsN)rallrYrQr)r]rr_)r]r`rs      z_Parse._parse_multi_targetcs|g}x\|ddD]L}d}t|tr0|jk}ntfdd|D}|r||||qW|rrd||||fS)zskip all baseline featuresNFcsg|]}|jkqSr_)rz)rr)r]r_r`rsz5_Parse._parse_policy_not_keepbase..zskip baseline features)rrrzrrr[r)r]rrrrris_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]rrrr_r_r`r|s z_Parse._parse_policy_keepsortcCs|j|dd}|||fS)z%sorted depend on the highest interestT)rN)rQ)r]rrrr_r_r`r}sz!_Parse._parse_policy_not_keepsortcCsT|jr|dn8|jr$|dn&|jd}|sB|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 skippedT)r)rrrPr)r]rrrrMr_r_r`r~s    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 errorsT)rz'compiler warnings are treated as errors)rr)r]rrrrMr_r_r`r s   z_Parse._parse_policy_werrorcsxg}xX|ddD]H}t|tr,|}ntfdd|D}|s||||qW|rnd||||fS)z=skip features that has no auto-vectorized support by compilerNcsg|]}|qSr_)rk)rr`)r]r_r`rsz0_Parse._parse_policy_autovec..z!skip non auto-vectorized features)rrrkrr[rr)r]rrrrrrjr_)r]r`rs      z_Parse._parse_policy_autovecN)rsrtrurvrrrrrrrrrrrrr{r|r}r~rrr_r_r_r`ru6s .R6 6 t   ruc@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. minrLNcCst|t||t|||||t|t||jsZ|jrZ| dd}t |||||_ ||_ t |di|_|jdt|d|_dS)NzSnative flag is specified through environment variables. force cpu-baseline='native'rsources_status hit_cache)rrrrrrrr8rPrrru_requested_baseline_requested_dispatchrrrr1rr)r]rrxryrr_r_r`rr0s      zCCompilerOpt.__init__cCs |jo |jS)zF Returns True if the class loaded from the cache file )rr)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|qW| rt | |}||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 startswithrxrr_generate_config _wrap_targetrrdrrrr)r]rsrc_dirrZ to_compilebaseline_flagsrsrcrrrrrrZtar_srcrMZobjectsZsrcsr_r_r` try_dispatchbs0*       zCCompilerOpt.try_dispatchc sbd|}}t|}t|}tj|}tj|sfjd|dddt|t |d}d fdd |D}d fd d |D} | t d jjd |d ||||| d d} x"|D]} | j| ddd7} qWd} x4|D],} | t djj| j| ddd7} qW| t djj| | dWdQRXdS)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)rrz \ csg|]}dj|fqS)z3 %sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__)))r})rr)r]r_r`rsz9CCompilerOpt.generate_dispatch_header..csg|]}dj|fqS)z3 %sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__)))r})rr)r]r_r`rsa /* * 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_lenbaseline_callsdispatch_callsr r)rrrsz #ifdef {pfx}CPU_TARGET_{name} {pre} #endif /*{pfx}CPU_TARGET_{name}*/ )rrprez /******* baseline features *******/ {baseline_pre} /******* dispatch features *******/ {dispatch_pre} )r baseline_pre dispatch_preN)rrrrrmrnryrrrrxrrrrr}rtr~) r]Z header_pathrdispatch_namesrr header_dirrrrrrrr_)r]r`generate_dispatch_headersJ                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|jf|}|d |rd |nd f| }|d|rd |nd fg}x|D]} || | 7}qW|d|r&d |nd f|jrB|d n|d t|j f| } |d | rtd | nd fi} x>|jD]0\} \} }x |D]}| |g| qWqW|r| sDd}xN|| D]@}| |}t|tr|n dd |} || dt|7}qW|d|r8|ddnd fn(|dx|| D] }| |}t|trz|n dd |}d ||}d |||}d ||}g}x.t|tr|fn|D]} || | 7}qW|rd |nd }|d|||f|d|f|d|f|d|fx|D]}|d|fqNWq\Wg}dd|D}dd|D}d}tt|t|}x|D]\}}|s|dq|d |t|7}|||dx<|D]4\}}|d |t|7}|||d|qWqWd |S)NPlatform)r r z CPU baselinez CPU dispatchZ Architecture unsupportedZCompilerz unix-like) Requestedzoptimization disabledrZEnabledrnoneZFlagsz Extra checksr z(%s)z[%d] Generatedr)rr ZDetectcSsg|]\}}t|qSr_)r)rZsecsr4r_r_r`rb sz'CCompilerOpt.report..cSs&g|]\}}|D]\}}t|qqSr_)r)rr4rowscolr_r_r`rc sz z: rs)rrrrrrPreprrrrxrrnrrrrrrQrrrrdrWrcrL) r]fullreportZ platform_rowsZ baseline_rowsZ dispatch_rowsrrr-rrZtarget_sourcesrr4rr generatedr pretty_namerMrr4rtextZsecs_lenZcols_lentabpadsecrrrr_r_r`r s        $    "zCCompilerOpt.reportc st|ttfstt|tr&|}}nd|}d|}tj|tj|}djtj || f}|rtj |r|S| d|| ||}d|jfdd|D} d| } t|d .} | td j|j|tj|| d WdQRX|S) N.__z {0}.{2}{1}zwrap dispatch-able target -> z#define %sCPU_TARGET_csg|] }|qSr_r_)rr) target_joinr_r`r sz-CCompilerOpt._wrap_target..rsraR /** * 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)rrrrrxrmrnbasenamersplitextrerrrQrXr~rrrrabspath) r]r dispatch_srctargetrZext_namerZ wrap_pathrrrr_)rr`rr s(         zCCompilerOpt._wrap_targetc CsZtj|dd}tj||}|||}yFt|4}|d}t |dkrht |d|krhdSWdQRXWnt k rYnX| d|g} xd|D]\} t | tr| } ndd d | D} || } d d d | D} | d |j| | fqWd| } |rd|j} nd} t|d&}|tdj|j| | |dWdQRXdS)Nz.cz.hz cache_hash:rrTzgenerate dispatched config -> rcSsg|]}|qSr_r_)rr`r_r_r`r sz1CCompilerOpt._generate_config..z&&cSsg|] }d|qS)zCHK(%s)r_)rrr_r_r`r sz2 %sCPU_DISPATCH_EXPAND_(CB((%s), %s, __VA_ARGS__))z \ z( %sCPU_DISPATCH_EXPAND_(CB(__VA_ARGS__))r raZ // 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} )rrrrF)rmrnrreplacerxrrreadlinerrintrcrrrrcrr~rrrr)r]rrrrZ config_pathrrZ last_hashrrrZ req_detectrrr_r_r`r sB         zCCompilerOpt._generate_config)rrLN)N)F)F)F)rsrtrurvrrrrrrrrrrrr_r_r_r`r*s  PS m &rcKs.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 )rrmrnrrr)rZdispatch_hpathrrr_r_r`new_ccompiler_opt s  r)rvsysiormrrrrrjrrrrrobjectrr8rurrr_r_r_r` s4H ;[w,