bg dZddlZddlZddlZddlZddlZddlZddlZGddZGddZ iZ GddZ Gd d Z Gd d Z Gd dZGddee e e e eZdZdS)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 eZdZdZdZdZdZdZej ej ej e dZiZdZdZeeddd eddd ed dd ed dd eddd eddd ZedddddddZedzideddddeddd !d"ed#dd$!d%ed&d"d'!d(ed)d%d*!d+ed,d(d-!d.ed/d+0d1ed2d.d3d4d5ed6d1d7!d8ed9d1d7!d:ed;d10d<ed=d:0d>ed?d:0d@edAdBddCDdEedFd@0dGedHdEdIdGdJdKedLdGdMdKdJdNedOdEdPdNddQRdSedTdNdUdSVdWedXdNdYdWdJdZed[d\d]dZdJd^ed_dZd`d^dJdaeddbdcddeeddadfdged#dedfdhed&dgddiDdjeddkldmeddjdfdned#dmdfdoeddpldqeddo0dred#dq0dsed&dtdfdued)ds0dved,ds0dwed/du0ZdxZdyZdS){_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=switch -Werrorz-xHostz/QxHostz/O3z/Werrorz/O2z/WXz -mcpu=a64fx)gccclangicciccwmsvcfcczSSE SSE2z SSE SSE2 SSE3zVSX VSX2zNEON NEON_FP16 NEON_VFPV4 ASIMD)x86x64ppc64ppc64les390xarmhfaarch64SSEz 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,r: AVX512_CLX+ AVX512VNNI)rrr?r@ AVX512_CNL,zAVX512IFMA AVX512VBMI AVX512_ICL-zAVX512_CLX AVX512_CNLz(AVX512VBMI2 AVX512BITALG AVX512VPOPCNTDQ AVX512_SPR. AVX512FP16VSXz altivec.hVSX_ASM)rrr:VSX2)rrr,VSX3VSX4VSX4_MMAVXz vecintrin.h)rrVXEVXE2NEONz arm_neon.h NEON_FP16 NEON_VFPV4ASIMDzNEON_FP16 NEON_VFPV4ASIMDHPASIMDDPASIMDFHMc p|jriS|jp|j}|jp |jp|j}|r|rt dwidt ddt ddt ddt d d t d d t d dt ddt ddt ddt ddt ddt ddt ddt ddt dd t d!d"t d#d$t d%d&t d'd(t d)d*t d+d,t d-S|rp|jrht dwidt ddt ddt ddt d d t d d idt ddt ddidt d./dt d./dt d0d12dt dd12dt d3d42dt d5d42d t d6d"t d7d$t d8d&t d9d(t d:d*t d;d,t ddt d?dt d@d t dAd idt dBdt dCdidt d./dt d./dt d0dD2dt ddD2dt d3dE2dt d5dE2d t dFd"t dGd$t dHd&t dId(t dJd*t dKd,t dnididid id t dLMdidt dCdidt dNMdt dNMdt d0dO2dt dPdO2dt dQdR2dt dSdR2d t dT/d"t dT/d$t dRd&id(id*id,t dT/S|j p|j }|rt t |j rdUndVdW2t dXdYZt d[dYZt d\dYZ]}|jr,d^|d_d`<dX|dUd`<da|dbd`<dc|ddd`<|S|j }|r@t t det dfdYZt dgdYZh}|S|j r~|r|t t didjkt dldjkt dmdjkt dndjkt dot dpt dqrS|jrz|rxt t dst dtt dut dvt dot dpt dqrSiS)xa7Return 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-msse2r z-msse3r"z-mssse3r$z-msse4.1r&z-mpopcntr(z-msse4.2r*z-mavxr1z-mf16cr-z-mxopr/z-mfma4r3z-mfmar5z-mavx2r7z-mavx512f -mno-mmxr;z -mavx512cdr=z-mavx512er -mavx512pfrAz/-mavx5124fmaps -mavx5124vnniw -mavx512vpopcntdqrCz -mavx512vl -mavx512bw -mavx512dqrEz -mavx512vnnirHz-mavx512ifma -mavx512vbmirJz.-mavx512vbmi2 -mavx512bitalg -mavx512vpopcntdqrLz -mavx512fp16z!Intel Compiler doesn't support it)disablez F16C AVX2z-march=core-avx2)rr`z AVX2 AVX512CDz-march=common-avx512z AVX2 AVX512Fz-xKNLz-xKNMz-xSKYLAKE-AVX512z -xCASCADELAKEz -xCANNONLAKEz-xICELAKE-CLIENTzNot supported yetz /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 itrQrz-mvsxz -mcpu=power8F)r`r,z-mcpu=power9 -mtune=power9z-mcpu=power10 -mtune=power10)rOrQrRrSz-maltivec -mvsxrOr`z -mcpu=power9rRz -mcpu=power10rSz-march=arch11 -mzvectorz -march=arch12z -march=arch13)rUrVrWzNEON_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)rXrYrZr[r\r]r^z -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 cc_is_fccdict cc_is_icc cc_is_iccw cc_is_msvc cc_on_ppc64le cc_on_ppc64 cc_on_s390x cc_on_aarch64 cc_on_armhf)selfon_x86is_unixon_powerpartialon_zarchs p/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/numpy/distutils/ccompiler_opt.pyconf_features_partialz_Config.conf_features_partialIsT  = I14>.FD$4F  g d' ' ' ((((' ))))' ))))'  **** '  ++++ '  ++++ '  ++++' ((((' ))))' ((((' ))))' ((((' ))))' !56666' ,////' $;<<<$89999?!/ @&9::::A!/ !( D ( do( d(/ (/ (/ -1^C$[))))(/ /3~E4l++++2(/ R(/ R (/ R (/ -0000 (/ R(/  ,,,,(/ R(/ -0000(/ -0000(/ #<(/ #<!(/ *2.+(/ 0,N1(/ 6:7(/ <:=(/ BN3333C(/ DE(/ FG(/ HI(/ J:K(/ (( T%9)9  '+'9AVVr!(6u8G ;+<w'+9(+9(+:(N#  3)%)%   GN   ' $4d/.3T-00'3 3 3 , .    ":(?-00'1 1 1 * 0 c|j=ddlddl}|fd}t j||_|j2tj t|j g|_dSdS)NrcV dS#t$rYdSwxYwN)rmtreeOSError)shutiltmpsryrm_tempz!_Config.__init__..rm_temp?sBMM#&&&&&DDs  (() conf_tmp_pathrtempfilemkdtempatexitregisterconf_cache_factorsospathgetmtime__file__ conf_nocache)rsrrrrs @@ry__init__z_Config.__init__:s   % MMM OOO""$$C       OG $ $ $!$D   " *  **!'D # # # + *r{rc)__name__ __module__ __qualname____doc__r conf_nooptrrrrjoindirnamerealpathrconf_check_pathconf_target_groups conf_c_prefixconf_c_prefix_rj conf_cc_flagsconf_min_features conf_featuresrzrrcr{ryrrs``BLJMgll ((2233XOMNDd%    $ .    d   t   t   d"   C&&&MN3DYYYd      Yq%GGGGYq&-HHHHYq&-HHHHYq'=IIIIYq';KLLLLYq(3333Y     Y$q%GGGG%Y&r5-HHHH'Y(r51111)Y*r62222+Y,r62222-Y.$U)    /Y64Y77777Y8T3F    9Y@T=    AYJT3O6    KYTT\    UY\T5L    ]YdT!8<    eYnT\    oYzdA{KKKK{Y~tQeDDDDYBtQuEEEECYFtQu!+----GYNT1m 4 4 4 4OYRdAtEBBBBSYVtQeDDDDWYZa6666[Y\D!V4444]Y`T1k::::aYda)?PUVVVVeYh$73333iYl$73333mYp4I6666qYMtooobr{rceZdZdZdZddZgfdZdZedZ edZ ed d d Z ed Z ed Z ddZejdZeddZdS) _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()`. c||_dSr~) _ccompiler)rs ccompilers ryrz_Distutils.__init__Zs #r{Nc t|tsJt|tsJ|dg|z}|s|j}|j|fd|i|S)zWrap CCompiler.compile()extra_postargs) isinstancelistpoprcompile)rssourcesr`rkwargss ry dist_compilez_Distutils.dist_compile]sv'4(())(%&&''& +R0058 (I y III&IIIr{ct|tsJddlm}|j}t |dd}|rGt |jdd}|dvrt |d|jnt |d|jd} | |g|||j d }n6#|$r.} | t| d Yd} ~ nd} ~ wwxYw|rt |d||S) zgReturn True if 'CCompiler.compile()' able to compile a source file with certain flags. r CompileErrorspawnN compiler_typer)rF)macros output_dirTstderr) rstrdistutils.errorsrrgetattrsetattr_dist_test_spawn_paths_dist_test_spawnrrdist_log) rssourcer`rrccbk_spawncc_typetestes ry dist_testz_Distutils.dist_testgs>&#&&''&111111 _2w--  <doCCG)##GT%@AAAAGT%:;;; /   %4;M    DD / / / MM#a&&M . . . . . . . . /  + B * * * s!B$$C)$CCc |t|dr|jSt|jdd}|dvrd}n|dvrd}ndd lm}|}t|jd t|jd d}|r|d kr)t|d r |d}nt |}n|}t|d r1t|dkrd|dd}nCtj dd}|tj ddz }|||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.utilrrlenrrenvironget)rsrplatformrcc_infor extra_argss ry dist_infoz_Distutils.dist_infosZ 4 & & #? "$/?B?? - - -HH 5 5 5HH 3 3 3 3 3 3#|~~H$/:wtP]_a7b7bcc 'V++w ++ ("1:w<<H 7J ' ' 9CLL1,<,<'!""+..JJ*..266J "*..R88 8J#Xz:r{c<ddlm}|tj|)zRaise a compiler errorrr)rrr _dist_str)argsrs ry dist_errorz_Distutils.dist_errors. 211111l:/6777r{c<ddlm}|tj|)zRaise a distutils errorr)DistutilsError)rrrr)rrs ry dist_fatalz_Distutils.dist_fatals. 433333nZ148999r{Frcddlm}tj|}|r||dS||dS)zPrint a console messager)logN)numpy.distutilsrrrwarninfo)rrrouts ryrz_Distutils.dist_logsQ ('''''"D)   HHSMMMMM HHSMMMMMr{cddlm} |||S#t$r&}t|dYd}~nd}~wwxYwdS)zALoad a module from file, required by the abstract class '_Cache'.r)exec_mod_from_locationTrN) misc_utilr Exceptionrr)namerrrs rydist_load_modulez_Distutils.dist_load_modulesz 655555 0))$55 5 0 0 0   $  / / / / / / / / 0ts  A?Acfdtjd}d|j|jfz}dfdg|RD}||zS)z+Return a string to print by log and errors.ct|tsPt|dr@g}|D] }||!dd|zdzSt|S)Nr(r))rrrappendr)argretato_strs ryrz$_Distutils._dist_str..to_strs|c3'' 0GC,D,D 0**AJJvvayy))))CHHSMM)C//s88Or{rzCCompilerOpt.%s[%d] : rc&g|] }|Srcrc).0rrs ry z(_Distutils._dist_str..s1    F1II   r{)inspectstackfunctionlinenor)rrstartrrs @ryrz_Distutils._dist_strs      "(ENEL+IIhh    tXX     s{r{c*t|jds||dStjd} |jjtjd<|||tjd<dS#|tjd<wxYw)z Fix msvc SDK ENV path same as distutils do without it we get c1: fatal error C1356: unable to find mspdbcore.dll _pathsNr)rrrrgetenvrr)rscmddisplayold_paths ryrz!_Distutils._dist_test_spawn_pathss t11   ! !# & & & F9V$$ *!%!7BJv   ! !# & & &!)BJv   BJv  ) ) ) )s .BBz/.*(warning D9002|invalid argument for option).*c tj|tjd}|r>tjt j|rt d|d|zdS#tj$r}|j }|j }Yd}~nd}~wt$r}|}d}Yd}~nd}~wwxYwt d|d||fzdS)NT)rtextzFlags in commandz/aren't supported by the compiler, output -> %sCommandz(failed with exit status %d output -> %s) subprocess check_outputSTDOUTrematchr_dist_warn_regexrCalledProcessErroroutput returncoder)rroexcsrs ryrz_Distutils._dist_test_spawns 'J4E-1333A RXj91== %%&.')*.+4,    AAAAAAA   AAAAAAA   sG qK       s$A!A%%B"4B B"BB"r~)rrrrrrrr staticmethodrrrrrrrrrrrcr{ryrrMsQ  $$$JJJJ/14###J88\8 ::\: $\\\$ * * * *"rz    \   r{rcbeZdZdZejdZd dZdZdZ dZ e dZ 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_)Nchi|_t|_d|_d|_|jr|ddS|jg||jR|_ ||_|rtj |r|d|| d|}|s|ddnt|drt|d s|d dnr|j |jkrM|d |jD]\}}t%|||d|_n|d |jst&|j }|ri|d |jD]:\}}||jvst-j|j|r)t%|||;|t&|j <t3j|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_pathrr cache_hashr _cache_hashrrexistsrrrritemsr _share_cacher__dict__rr _cache_ignorerr cache_flush)rs cache_pathfactors cache_modattrval other_caches ryrz_Cache.__init__%s`  UU!    MM9 : : : F*4?NGNd6MNNN%  9w~~j)) 9 7DDD 11':FF  9MMC#"!F33 9 F33 9MM"6tMDDDD%77MM"6777%.^%9%9%;%;11 cdC0000(,D%%MM"7888  -&**4+;<T)compactwz # AUTOGENERATED DON'T EDIT # Please make changes to the code generator (distutils/ccompiler_opt.py) hash = {} data = \ )r"rr(copykeysrrr)rrrrr%makedirspprintpformatopenwritetextwrapdedentformatr$)rscdictr.d repr_dictfs ryr*z_Cache.cache_flushXs  F .0@AAA ""$$M&&((  Dx*D11  $ GOOD, - -w~~a    KNNNN5$777 $"C ( ( A GGHO% ())  + + + GGI                     s AE--E14E1c~d}|D]7}t|D]%}t||dzz|dzz|z }|dz}&8|S)Nrr'l)rord)rsr,chashrDchars ryr#z_Cache.cache_hashtsg $ $AA $ $Teqj1Ub[AEI# $ r{cfd}|S)zr A static method that can be treated as a decorator to dynamically cache certain methods. ctjg|||R}||jvr |j|S|g|Ri|}||j|<|Sr~)rrr8valuesr)rsrr cache_keyccbcbs ry cache_wrap_mez _Cache.me..cache_wrap_mes "%+[[]]5;]]__IDM))}Y//"T+D+++F++C'*DM) $Jr{rc)rOrPs` rymez _Cache.me~s$     r{r~) rrrrrrr)rr3r*r#rrQrcr{ryrrs4BJ|,,M+*+*+*+*Z 8\r{rc.eZdZdZdZejdZejgfdZdZ e j dZ e j dZ e j dZe j d Zd Ze j d Ze j d Zd ZdS) _CCompilera2A 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_ppc64le : bool True when the target architecture is 64-bit litle-endian powerpc cc_on_s390x : bool True when the target architecture is IBM/ZARCH on linux 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` cLt|drdSd}d}d}|}|\}}}|||fD]}|D]\} } } t|| d||f||ffD]Z\} } | D]R\} } } | r!tj| | tjs)| r|| sAt|| d[|D]R\} } } | r!tj| |tjs)| r|| sAt|| dS|jr"|d|dd d|_ |j r|d d d|_ |j r# |d |dd d|_ d |_ d D]}t|d|zr ||_ nd |_dD]}t|d|zr ||_ni|_|j|j}||d|jz|D]n\}}gx|j|<}|r[t+|t,sJ|}|D]-}||gr||.od|_dS)N cc_is_cached))rfz.*(x|x86_|amd)64.*r)rez.*(win32|x86|i386|i686).*r)rnz&.*(powerpc|ppc)64(el|le).*|.*powerpc.*z4defined(__powerpc64__) && defined(__LITTLE_ENDIAN__))roz.*(powerpc|ppc).*|.*powerpc.*z1defined(__powerpc64__) && defined(__BIG_ENDIAN__))rqz.*(aarch64|arm64).*r)rrz.*arm.*z3defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__))rpz .*s390x.*r) cc_on_noarchrr))rgz.*(gcc|gnu\-g).*r)rhz .*clang.*r)rlz.*(intelw|intelemw|iccw).*r)rkz.*(intel|icc).*r)rmz.*msvc.*r)riz.*fcc.*r) cc_is_noccrr)) cc_has_debugz$.*(O0|Od|ggdb|coverage|debug:full).*r) cc_has_nativez..*(-march=native|-xHost|/QxHost|-mcpu=a64fx).*r)rdz.*DISABLE_OPT.*rFTz]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)rrrrrrrcc_on_)r r rr rrcc_is_z=undefined flag for compiler '%s', leave an empty dict instead)rrrrr IGNORECASE cc_test_cexprrVrrdrrWrgcc_marchrcc_namecc_flagsrrrr&rrsplit cc_test_flagsrrU)rs detect_archdetect_compiler detect_argsrr compiler_inforsectionr.rgexcexprr@searchinarchrcompiler_flagsr`nflagsrDs ryrz_CCompiler.__init__s 4 ( (  F   NN$$ .7+-#_kB + +G%, + +!dEdE**** +#.x!8?M:Z [   FH%+  !dEx G G!3!3E!:!:dD)))!, & & D$ BHT:r}EE  T//66  D$ % % % %   ! MM7'0777     !DM ? ! MMB4M P P P DM ? "  MM7'0777     "DN! 2  DtX_--  $  ! B  DtX_-- #   +// ==  ! OO.04 =   *//11 ) )KD%+- -DM$ & )!%--..- ))A))1#..) a((( r{ct|tsJ|d|tj|jd}|||}|s|dd|S)z@ Returns True if the compiler supports 'flags'. z testing flagsz test_flags.ctesting failedTr)rrrrrrrr)rsr` test_pathrs ryrcz_CCompiler.cc_test_flags7s} %&&''& ou---GLL!5~FF ~~i// 9 MM*4M 8 8 8 r{c|d|tj|jd}t |d5}|tjd|ddddn #1swxYwY| ||}|s|dd |S) zJ Same as the above but supports compile-time expressions. ztesting compiler expressionznpy_dist_test_cexpr.cr6z #if !(zq) #error "unsupported expression" #endif int dummy; NrpTr) rrrrrr<r=r>r?r)rsrjr`rqfdrs ryr^z_CCompiler.cc_test_cexprDs 3U;;;GLL!35LMM )S ! ! R HHX_&&&&                  ~~i// 9 MM*4M 8 8 8 s ,BB Bct|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'] ) rrrgrhrk_cc_normalize_unixrmrl_cc_normalize_win)rsr`s rycc_normalize_flagsz_CCompiler.cc_normalize_flagsWsw.%&&''& > 2T- 2 2**511 1 ? 1do 1))%00 0 r{z^(-mcpu=|-march=|-x[A-Z0-9\-])zB^(?!(-mcpu=|-march=|-x[A-Z0-9\-]|-m[a-z0-9\-\.]*.$))|(?:-mzvector)z^(-mfpu|-mtune)z[0-9.]cfd}t|dkr|Stt|D]\}}tjj|s |d|dz }|| d}t tjj |}||\}} } |dkrMt| dkr:|D]} || \} } }|| kr|| z} | dzd | z}||gz}|dkr||z }g}t}t|D][}tjj |}|sn&|d|vr*| |d|d|\|S)Nc |d}tddtjj|dz}||d|ddfS)N+0rrr)rbfloatrrfindall_cc_normalize_arch_ver)rDtokensverrss ry ver_flagsz0_CCompiler._cc_normalize_unix..ver_flagsskWWS\\Fbgg 46q BBCq 6!"":- -r{rrrz)r enumeratereversedrr_cc_normalize_unix_mrgxrfilter_cc_normalize_unix_frgxsearchrr_cc_normalize_unix_krgxaddinsert)rsr`ricur_flag lower_flags upper_flagsfilteredrrlsubflagsxflagxver_ xsubflags final_flagsmatchedrDrs` ryruz_CCompiler._cc_normalize_unixs . . . . . u::??L$Xe__55  KAx8D8(CC 1Q3.K*KF,3[H#,)H"5"5 CxQww3x==1,,(88E)25)9)9&D!Yd{{#,x#7#:(:(::z)E1uu$  %%% % %AHT91==E &qW$$ E!H%%%   q! $ $ $ $r{z^(?!(/arch\:|/Qx\:))z ^(/arch|/Qx:)c tt|D]b\}}tj|j|s |dz }t t |jj|d| || dzcS|S)Nr) rrrr_cc_normalize_win_mrgxrr_cc_normalize_win_frgxr)rsr`rrDs ryrvz_CCompiler._cc_normalize_winshuoo..  DAq8D7;;  FA+2E#A2#Jrss    r{N)rrrrrrrQrcr^rwrrrrrr~rurrrvrcr{ryrSrSs://`t!t!t!l Y  Y  Y)+Y$>)bj))bj )bj(RZ///b(RZ(RZr{rSceZdZdZdZddgfdZdZddZddZd Z d Z d Z d Z d Z ejdZejdgfdZejdgfdZejdZejdZddZdS)_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`. cb t|drdS|x|_}t|D]}|| |j|}  fd|D d}|1| || d|z|ddD]C} |}t|tr| |<Dt|_|j|jd}| D]%}||jvr|j|&d|_dS) Nfeature_is_cachedc$i|] \}}|v || Srcrc)rkvfeatures ry z%_Feature.__init__..s0!1G3C3C!3C3C3Cr{razfeature '%s' is disabled,Tr)rr?r@rr`r:r)rrzfeature_supportedrr8rupdater&rrrrrrbr feature_minrr_upperrr) rs pfeatures feature_namecfeaturedisabledoptionovalmin_fFrs @ryrz_Feature.__init__s 4, - -  F-1-G-G-I-II !1!122 3 3L .G),7H NN'~~//   {{9--H# l+++ /,>T 3 3{{6**dC((3&*jjllGFO  355&**4="==$$&& ( (AD*** $$Q'''!%r{Nc@|'t|tst|dsJ|t|tsJ||j}t }|D]/}||||r||0|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) rrrrrr8rfeature_is_supportedr)rsnamesrrsupported_namesrDs ry feature_namesz_Feature.feature_namess& Muc** z** M  "jd&C&C""C =*//11E%% ' 'A(({6) ' ##A&&&r{c@|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)rsrs ryfeature_is_existz_Feature.feature_is_exists%||~~~t)))r{Fc2fd}t|||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 ct|trj|dStfd|D}|t |dz z }|S)Nrc6g|]}j|dS)r)rrrDrss ryrz<_Feature.feature_sorted..sort_cb..<s&III!.q1*=IIIr{r)rrrmaxr)rrankrss rysort_cbz(_Feature.feature_sorted..sort_cb8se!S!! =-a0<<IIIIqIIIJJD CFFAI DKr{)reversekey)sorted)rsrrrs` ryfeature_sortedz_Feature.feature_sorted)s3     eW'::::r{c.tffd t|tr|}|g}nCt|dsJt}|D] }||}!|s|||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'} c t}j|}|dgD]P}||||vr|||||}Q|S)Nr)rrrrunion)r_callerrrBr get_impliesrss ryrz-_Feature.feature_implies..get_implies[seeG&t,AUU9b)) A A A<< D!!!!-- Aw(?(?@@Nr{r)rrrrrdifference_update)rsr keep_originsrnrs` @ryfeature_impliesz_Feature.feature_impliesCs0'*ee        eS ! ! 8!k%((GGEE5*-- . .-eeG 8 8!-- A77 -  % %e , , ,r{ct|trt|f}nt|}|||S)z/same as feature_implies() but combining 'names')rrrrr)rsrs ryfeature_implies_cz_Feature.feature_implies_ctsN eS ! ! MMEEJJE{{4//66777r{ct|tst|dsJ||dfd|D}t |dkr||ddd}|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|]}|v| Srcrc)rrrs ryrz*_Feature.feature_ahead..s#666qQg%5%5%5%5%5r{rrNr)rrrrrr)rsraheadrs @ry feature_aheadz_Feature.feature_ahead|s65#&& z**   +&&u4&@@6666E666 u::??''t'<>> 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"] rcJg|]}|v|v| Src)r)rnnrrrss ryrz+_Feature.feature_untied..sD==Q$*>*>r*B*B%B%B%B%B%Br{rNr)rrrrrremover)rsrfinaltiedrrs` @@ryfeature_untiedz_Feature.feature_untieds.5#&& z**   +  A**1--G"D ***41#:66DH$$ T"1"Xa[))) LLOOOO r{cfdt|tst|dkr!|}||S|}fd|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. c|}|d}t|D]5\}}j|ds|d|dz}n6|S)NTrr)rrrrr)tnamesrr keyisfalserss rytilz%_Feature.feature_get_til..tils++F33F(((>>F!&))  1-a044ZFF#DQqSD\FEMr{rc0h|]}|D]}|Srcrc)rrtrs ry z+_Feature.feature_get_til..s.222q33q6622a2222r{)rrrrrr)rsrrrs` `@ryfeature_get_tilz_Feature.feature_get_tils       eS ! ! SZZ1__CJJE MMOOOL""5))2222E222""5)))r{c ||d}g}|D]=}|j|}||d|d|gz }>|S)z Return a list of CPU features that required to be detected sorted from the lowest to highest interest. r,r@r?)rrr)rsrr@rrBs ryfeature_detectz_Feature.feature_detectsj $$U,<== ; ;A&q)A aeeHaeeGaS&9&9:: :FF r{c |||}g}|D]B}|j|}|dg}|r||s=||z }C||S)zi Return a list of CPU features flags sorted from the lowest to highest interest. r`)rrrrrcrw)rsrr`rrBrDs ry feature_flagsz_Feature.feature_flagss ##D$:$:5$A$ABB  A&q)Agr""A D..q11  QJEE&&u---r{c|||}|d|dd|dtj|jd|z}tj|s|d|| |||j dz| }|s|d 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. Nztesting feature 'z' with flags (rrzcpu_%s.czfeature test file is not existr rrpTr) rrrrrrlowerr%rrra)rsrrrrqrs ry feature_testz_Feature.feature_tests$  ,,T22K DD#((;''''    GLL  *tzz||";  w~~i(( I OO.Ps6,-""A3''r{r`)rrrrany)rsrrBcan valid_flagss` ryfeature_can_autovecz_Feature.feature_can_autovecGs $$$%%$  "4 (eeIt$$ ;12w1C1CK2#k"2"2C r{ct|tsJ|j|}|dg}|sgS|d|z|||}g}g}|D]}t j|j d| z}t j |s| d|| |||jdz} | r|||||r|d|d|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 existr ztesting failed for checksTr)rrrrrrrrrrrr%rrrar) rsrrBr:r` available not_availablechkrq is_supporteds ryfeature_extra_checksz_Feature.feature_extra_checksVsb$$$$$$  "4 (uu^R00  I =DlSSS""4((   * *C $lSYY[[&@I7>>),, N A9MMM>>)UT]8=T5TUUL *  %%%%$$S))))  S MM5}TM R R Rr{rc|sJ|j|}|Jd|zd|jd|dg}|d|dgDz }|dg}|||z }|D]!}|d |jd|d |jd|dd gz }"d krfd |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 HAVE_z 1cg|]}d|zS)z #include <%s>rc)rr2s ryrz3_Feature.feature_c_preprocessor..s*   $%Oa    r{rr?z#ifndef z #define z#endifrc g|] }dz|z S) rc)rltabss ryrz3_Feature.feature_c_preprocessor..s!444d4i1_444r{ )rrrrrr)rsrrrprepr extra_defsedefs ` ryfeature_c_preprocessorz_Feature.feature_c_preprocessor}sS,##%%&&%(,,\::""" < ' '%)%7%7%7 F    )0Y)C)C    [["-- d// ===   D E'+'9'9'944@@+/+=+=+=tttD EE !884444e444Eyyr{F)r)rrrrrrrrrrrrrrrrQrrrrrrrcr{ryrrs   & & &D#'D!!!!F * * *;;;;4////b888$$$L'''R***6    Y . .Y . Y-1"%%%Y%N Y59"Y8 Y  Y  Y##Y#L/ / / / / / r{rceZdZdZdZdZejdZdZ ejdZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdS)_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 tdjgfjjgfjdgfjdgfjddgf_tdrdSg_ g_ g_ i_ j rdx}}d|rd|}|}|_ |_ d|d|}fd|D}||}|_ t+|d krd |d d jD]y\}}d ||}|r|sdggfj |<S|\} } } | | | fj |<zd_dS)NMAXOPT) KEEP_BASELINE KEEP_SORTr WERRORAUTOVECparse_is_cachedzcheck requested baseline cpu_baselinez&check requested dispatch-able features cpu_dispatchc&h|] }|jv |Srcparse_baseline_namesrs ryrz"_Parse.__init__..s1D555555r{rz skip featureszsince its part of baselinezinitialize targets groupszparse target groupFT)rj_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_groupsrdr_parse_arg_featuresrrrr differencerrr&rstrip_parse_target_tokensr) rsrrbaseline_names cpu_dispatch_conflict_baseline group_namer GROUP_NAME has_baselinefeatures extra_flagss ` ryrz_Parse.__init__s#d5 +/ )4 )4 *D '   0 4* + +  F$&!$&!$&!#% = /*. .L< 0111  #33NLQQL!// ==N(,(:(:>(J(JD %(,(;(;&&~66))D % >???  # 44^\RRM(L!. 8 8 F F (,(;(;""<00))D %$%%)) #%68T 1222"&"9"?"?"A"A   J MM. ; ; ;#))++J   2r8(4))&11 0L(Kh 4D $Z 0 0 $r{c|d|t|5}d}d}d}d}d}d}t|D]\} } | |kr|dny|dkr.| |}|dkrD|t |z }|| z }| |}|dkr$|t |t | z z }ndddn #1swxYwY|dkr|d |z|dkr|d |z|||}||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')rr<rrfindrr#) rsrrsr max_to_reach start_with start_posend_withend_pos current_linelines ry parse_targetsz_Parse.parse_targets/s, 96BBB &\\ RFL#JIHG&/mm  " d<//OO$>???E?? $ * 5 5I B Z0I$))H--b==s6{{SYY66GE!%               , ?? OOFS T T T b== OO7(B C C C ')*((000sB7C))C-0C-z \s|,|([+-])c t|ts|d|zt}t t dt j|j|}d}|D]L}|ddvr||d|dkrd},|dkrd}5| }t}|d krn|d kr>|j d } | s||d | | d g}n{|dkr|j }n[|dkr|j}nM||j vr||n.||s||d|z|r||}n||}d}N|S)Nzexpected a string in '%s'Tr)#$zYtarget groups and policies aren't allowed from arguments, only from dispatch-able sourcesrz-FNONENATIVErz-native option isn't supported by the compiler)DETECT_FEATURESrrMAXMINz&, '%s' isn't a known feature or option)rrrrrrrrb_parse_regex_argrrarrr8rrrrr!) rsarg_name req_featuresfinal_featuresrrtokTOK features_tors ryr z_Parse._parse_arg_featuresfs,,, D OO7(B C C CfT28D,A<#P#PQQRR, , C1v##6 czzczz))++C%%Kf}}x0OOHG#00 &0F/G1 "499;; ". $000OOC((((0055DsJ H!/!5!5k!B!B!/!:!:;!G!GFFr{z\s|[*,/]|([()])c ^t|tsJg}g}d}t}t}d}tt dt j|j|}|s|d|D]!}| } |d} | dvr|d9| dkr@||d| | | | dkr4||d | | |||\}}}| d kr&||d t}| d kr||d | |} | #| t|n6t| dkr| d} | r| |vr|| d}v| dkr||dd}|| | || s|d| z| |jvp| |jv} | r| |vr||  | | #||d |r|d|d||}t|D]N} |j| \}}}|D]8}||vr|d| d|d| |9O|jD]@\} \}}}d}| |vr|}|d| zn|}|s/||||\}}}A|||fS)NFzexpected one token at leastr)rzr:ze+/- are 'not' allowed from target's groups or @targets, only from cpu_baseline and cpu_dispatch parmsr9zCpolicies aren't allowed inside multi-target '()', only CPU featuresr8zHtarget 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 'z' force enables ''zpolicy '%s' is ON)rrrrrrrb_parse_regex_targetrrr_parse_token_policy_parse_token_group_parse_multi_targettuplerrrrrrrrr&)rsr final_targetsr+r)skippedpolicies multi_targetrDrEchtargets is_enabledprdepsrBhavenhavefuncs ryr#z_Parse._parse_target_tokenss&#&&''&   5555 fT28D,Df#M#MNNOO ; OO9 : : :> !> !C))++CQBZDs+OO. T55c::;;;;s+OO. ''\=+VV9 m[[s+OO$HIII"uu s'OO$JKKK22<@@?KKl 3 344447||q((")!*67-#?#?%,,W555# *$$#/(YZZZ#'L+ $$S))),,S11FOO$>$DEEE4445444-//%,,S111 C     # OO@ A A A   MM@    ++M:: h A-a0JAq$  == AAqqq Q $(#7#=#=#?#?   AeQDH}} 1A56666 7;tm[88 4L-]K77r{ct|dks|dd|dkr|d|dd}||jvr0|d|z|j|S)zvalidate policy tokenrr-Nrz*'$' must stuck in the begin of policy namez6'%s' is an invalid policy name, available policies are)rrrr8)rstokens ryrKz_Parse._parse_token_policys u::??eBCCjE!H44 OOH I I Iabb  , , , OOH5P$))++    r{ct|dks|dd|dkr|d|dd}|j|ddgf\}}}|3|d|zdz|j|rd }fd |Dz fd |Dz |fS) zvalidate group tokenrr-Nrz)'#' must stuck in the begin of group nameFz&'%s' is an invalid target group name, zavailable target groups areTcg|]}|v| Srcrc)rrDrOs ryrz-_Parse._parse_token_group..1s#HHH-1G1G!1G1G1Gr{cg|]}|v| Srcrc)rrDr+s ryrz-_Parse._parse_token_group..2s#HHHa1K3G3G3G3G3Gr{)rrrrr8)rsr\r)rOr+ ghas_baselinegtargets gextra_flagss `` ryrLz_Parse._parse_token_groups u::??eBCCjE!H44 OOG H H Habb 040H0L0L E4$1 1 - x   OO85@-.(--//     LHHHHXHHHH HHHH<HHHH ]K77r{cL|sdtfd|Dsd|tfd|DsdS|}|sdS|}t |}|S)z9validate multi targets that defined between parentheses()zempty multi-target '()'c:g|]}|Src)rrtarrss ryrz._Parse._parse_multi_target..:s4   +.D ! !# & &   r{z#invalid target name in multi-targetc4g|]}|jvp|jvSrc)rrres ryrz._Parse._parse_multi_target..>sC   t001t00   r{N)rallrrrN)rsrTs` ryrMz_Parse._parse_multi_target5s 7 OO5 6 6 6    29      L OOA7 K K K           4$$W-- 4%%g....r{c,g}|ddD]j}d}t|tr |jv}ntfd|D}|r*||||k|rd||||fS)zskip all baseline featuresNFc"g|] }|jv Srcrrs ryrz5_Parse._parse_policy_not_keepbase..Ws122r{zskip baseline features)rrrrhrrr)rsr)rOr+rPrfis_bases` ryrz!_Parse._parse_policy_not_keepbaseNs # * *CG#s## !::  *s###$$S)))  = MM2G < < <]K77r{c:|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)rrsr)rOr+s ryrz_Parse._parse_policy_keepsortds3 =}OJ   ]K77r{c:||d}|||fS)z%sorted depend on the highest interestTr)rrms ryrz!_Parse._parse_policy_not_keepsortms'++M4+HH ]K77r{c|jr|dnI|jr|dn,|jd}|s|ddn||z }|||fS)z&append the compiler optimization flagsz3debug mode is detected, policy 'maxopt' is skipped.z5optimization is disabled, policy 'maxopt' is skipped.r zOcurrent compiler doesn't support optimization flags, policy 'maxopt' is skippedTr)rXrrdrarsr)rOr+r`s ryrz_Parse._parse_policy_maxoptrs   % MMO P P P P ] % MMQ R R R RM%(E % 19= u$ ]K77r{c|jd}|s|ddn|d||z }|||fS)z#force warnings to treated as errorsr zTcurrent compiler doesn't support werror flags, warnings will 'not' treated as errorsTrz'compiler warnings are treated as errors)rarrps ryrz_Parse._parse_policy_werrorsj h' ! MM8@D      MMC D D D 5 K]K77r{c@g}|ddD]t}t|tr|}ntfd|D}|s*||||u|rd||||fS)z=skip features that has no auto-vectorized support by compilerNc:g|]}|Src)r)rrrss ryrz0_Parse._parse_policy_autovec..s7,,Q//r{z!skip non auto-vectorized features)rrrrhrrr)rsr)rOr+rPrfrs` ryrz_Parse._parse_policy_autovecs # $ $C#s## ..s33  $$$S)))s###  H MM=w G G G]K77r{N)rrrrrr6rrr@r rJr#rKrLrMrrrrrrrcr{ryr r s--\P$P$P$d414141l"rz.11666p%"*%788r8r8r8h   888,2888,888888 888" 8 8 888888r{r cXeZdZdZddZdZdZdZd Zdd Z d Z dd Z ddZ ddZ 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. minrNc`t|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)rrrrrrSrrdrYrr _requested_baseline_requested_dispatchrrxr rrry)rsrrrr+s ryrzCCompilerOpt.__init__sD),,,j$..*:*:L,WWWD!!!$} $!3 $ MM.   $LlL999$0 #/ &d,,>s,C,CCDD%%eR0077@@@@ =kN:;;%%eR0077<<<(4g'>D  $ $%++--  KE4 (t(d5kk-6:@ GGr{c d|z}}t|}t|}tj|}tj|s/d|ddt j|t|d5}d fd|D}d fd |D} | tj d jd |d ||||| d } |D]} | | ddzz } d } |D]I} | tj dj| | dz } J| tj dj| | ddddS#1swxYwYdS)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 itTrr6 \ c,g|]}djd|dSrzWITH_CPU_EXPAND_(MACRO_TO_CALL(, __VA_ARGS__))rrs ryrz9CCompilerOpt.generate_dispatch_header..M A+++A''',+++r{c,g|]}djd|dSrrrs ryrz9CCompilerOpt.generate_dispatch_header..S rr{a /* * 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_callsrr)rrz #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)rrrrrrrr%r9r<rr=r>r?r@rrr) rs header_pathr$dispatch_namesrr header_dirrDrrrrrs ` rygenerate_dispatch_headerz%CCompilerOpt.generate_dispatch_header3 s :[HIII00220022>** >** W__[11 w~~j)) $ MMOzOOO     K # # # +s # #8 q$\\++++( +++N %\\++++( +++N GGHO%&SXXn5M5M XXn55L).-    (L& Q Q ; ;Dq ; I ID PP L&  1!!V+$D. s"444'$CII444r{cBg|]\}}|D]\}}t|Srcr)rrrowscols ryrz'CCompilerOpt.report.. s3FFFDFFvsACHHFFFFr{z z: r)rrVr_rWr`rdreprrzrrrrr{rrxr&rrrrrrrrr) rsfullreport platform_rows baseline_rows dispatch_rowsr$rr:rrtarget_sourcesrrrTrf generatedr pretty_namer`rr@rrsecs_lencols_lentabpadsecrrr/s ryrzCCompilerOpt.report s    z=1222 h ~}5666 h ~}5666 n!. AMMDM     j!_ @KKDL     = P  !G H H H H  +tD4L/M/M!N O O O0022 NN000    0022 .Lchh~...f     " <  4I**>:: ; ;(-(c22Nss#8NTGc'll$:::  +/Vy"~~PV!W X X X X  !2 3 3 3**>:: 4 4(-%/S%9%9UccvQT ?U !3!3C!8!899((4#6#6t7K7KC7P7P#Q#QRR$"5"5c":":;;! '1#s';';DcVVDDD D$=$=d$C$CCLL:F R 6 6 6F $$X...$$k7%;<<<$$gu%5666$$nl%CDDD$$h%7888"44C!(("c33334 44V444FFFFFF3x==#h--00 4 4IC  B 3#C.) )C KKc D( ) ) )  4 4SscCHHn-- C#I,s23333 4yyr{c  t|ttfsJt|tr|x}}n*d|}d|}tj|tj|}djgtj|| R}|r!tj |r|S| d|| | |}d|jz fd|D} d| } t|d5} | t#jd |j|tj|| dddn #1swxYwY|S) N.__z {0}.{2}{1}zwrap dispatch-able target -> z#define %sCPU_TARGET_cg|]}|zSrcrc)rrD target_joins ryrz-CCompilerOpt._wrap_target.. s9991{Q999r{rr6aR /** * 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_namer target_defs)rrrNrrrbasenamer@splitextrr%rrrrr<r=r>r?abspath) rsr dispatch_srctargetrext_namer wrap_pathr*rrsrs @ryrzCCompilerOpt._wrap_target s&3,//00/ fc " " ,%+ +H{{xx''H))F++KGLLRW-=-=l-K-KLL 'L'W)9)9))D)DWhnnFVFVWWW  y11   5yAAA&&t'='=f'E'EFF-0CC 9999999 ii ,, )S ! ! R HHX_ &  '[W__\22                   s=A!G**G.1G.c tj|}tj|ddz}tj||}|||} t |5}|d}t|dkr't|d|kr ddddSdddn #1swxYwYn#t$rYnwxYwtj tj |d|d|g} |D]} t| t r| } nd d | D} || } d d | D} | d |jd| d| dd| } |r d|jz} nd} t |d5}|t+jd|j| | |dddn #1swxYwYdS)Nrz.hz cache_hash:rrT)exist_okzgenerate dispatched config -> rcg|]}|Srcrc)rrs ryrz1CCompilerOpt._generate_config../ s(8(8(8q(8(8(8r{z&&cg|]}d|zS)zCHK(%s)rc)rrDs ryrz1CCompilerOpt._generate_config..1 s)$$$"# A $$$r{rzCPU_DISPATCH_EXPAND_(CB((z), rrz( %sCPU_DISPATCH_EXPAND_(CB(__VA_ARGS__))rr6aZ // 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} )rrrr#F)rrrrrr#r<readlinerbrintrr9rrrrrrrr=r>r?r@)rsrrrTr) config_pathr#rD last_hashrrfr req_detectrrss ryrzCCompilerOpt._generate_config sDg&&|44 g&&{33A6= gll:{;; __Wl;;  k"" aJJLL..}== y>>Q&&3y|+<+< +J+J                           D  BGOOK004@@@@ 6 DDD  C#s## :! "ii(8(8C(8(8(899 ,,S11J$$'1$$$J  ! ! !###ZZZ    !n55  ;#$NN N +s # # r HHX_&'-*                  (usP?DAC<# D0 D<DDDD DD+AI;;I?I?)rvrN)NNr)rrrrrr~rrrrrrrrrcr{ryrurus 44444444 ))) ))) ))) UUUUnQQQfkkkkZ$$$$L<<<<<<r{ruc t|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 )rurrr%r~r)rdispatch_hpathrr s rynew_ccompiler_optrW sW" x * *6 * *C 7>>. ) )55 $$^444 Jr{)rrrrr:rr r>rrr'rrSrr rurrcr{ryrsEE  xxxxxxxxtx x x x x x x x t FFFFFFFFPwwwwwwwwr c c c c c c c c Jt8t8t8t8t8t8t8t8lqqqqq7J Hfqqqf r{