@@ -3306,7 +3306,7 @@ function toolset_setup_common_cflags()
33063306
33073307 ADD_FLAG ( "CFLAGS" , "/Zc:wchar_t" ) ;
33083308 } else if ( CLANG_TOOLSET ) {
3309- ADD_FLAG ( "CFLAGS" , "-Wno-deprecated-declarations" ) ;
3309+ ADD_FLAG ( "CFLAGS" , "-Wno-deprecated-declarations -Wno-microsoft-enum-forward-reference " ) ;
33103310 if ( TARGET_ARCH == 'x86' ) {
33113311 ADD_FLAG ( 'CFLAGS' , '-m32' ) ;
33123312 } else {
@@ -3340,24 +3340,25 @@ function toolset_setup_intrinsic_cflags()
33403340 /* From oldest to newest. */
33413341 var scale = new Array ( "sse" , "sse2" , "sse3" , "ssse3" , "sse4.1" , "sse4.2" , "avx" , "avx2" , "avx512" ) ;
33423342
3343- if ( VS_TOOLSET ) {
3344- if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3345- ERROR ( "Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. " )
3346- }
3343+ if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3344+ return ;
3345+ }
33473346
3348- if ( TARGET_ARCH == 'arm64' ) {
3349- /* arm64 supports neon */
3350- configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3351- /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3352- AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3353- return ;
3354- }
3347+ if ( TARGET_ARCH == 'arm64' ) {
3348+ /* arm64 supports neon */
3349+ configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3350+ /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3351+ AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3352+ return ;
3353+ }
33553354
3356- if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3357- PHP_NATIVE_INTRINSICS = default_enabled ;
3358- }
3355+ // if --enable-native-intrisics is not specified, it's "no" - enable default
3356+ if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3357+ PHP_NATIVE_INTRINSICS = default_enabled ;
3358+ }
33593359
3360- if ( "all" == PHP_NATIVE_INTRINSICS ) {
3360+ if ( "all" == PHP_NATIVE_INTRINSICS ) {
3361+ if ( VS_TOOLSET ) {
33613362 var list = ( new VBArray ( avail . Keys ( ) ) ) . toArray ( ) ;
33623363
33633364 for ( var i in list ) {
@@ -3366,46 +3367,61 @@ function toolset_setup_intrinsic_cflags()
33663367
33673368 /* All means all. __AVX__, __AVX2__, and __AVX512*__ are defined by compiler. */
33683369 ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3369- configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3370- } else {
3371- var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3372- var j = 0 ;
3373- for ( var k = 0 ; k < scale . length ; k ++ ) {
3374- for ( var i = 0 ; i < list . length ; i ++ ) {
3375- var it = list [ i ] . toLowerCase ( ) ;
3376- if ( scale [ k ] == it ) {
3377- j = k > j ? k : j ;
3378- } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3379- WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
3380- }
3381- }
3382- }
3383- if ( TARGET_ARCH == 'x86' ) {
3384- /* SSE2 is currently the default on 32-bit. It could change later,
3385- for now no need to pass it. But, if SSE only was chosen,
3386- /arch:SSE is required. */
3387- if ( "sse" == scale [ j ] ) {
3388- ADD_FLAG ( "CFLAGS" , "/arch:SSE" ) ;
3370+ } else if ( CLANG_TOOLSET ) {
3371+ ADD_FLAG ( "CFLAGS" , "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3372+ }
3373+ configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3374+ } else {
3375+ var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3376+ var j = 0 ;
3377+ for ( var k = 0 ; k < scale . length ; k ++ ) {
3378+ for ( var i = 0 ; i < list . length ; i ++ ) {
3379+ var it = list [ i ] . toLowerCase ( ) ;
3380+ if ( scale [ k ] == it ) {
3381+ j = k > j ? k : j ;
3382+ } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3383+ WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
33893384 }
33903385 }
3391- configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3392- /* There is no explicit way to enable intrinsics between SSE3 and SSE4.2.
3393- The declared macros therefore won't affect the code generation,
3394- but will enable the guarded code parts. */
3395- if ( "avx512" == scale [ j ] ) {
3396- ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3397- j -= 3 ;
3398- } else if ( "avx2" == scale [ j ] ) {
3399- ADD_FLAG ( "CFLAGS" , "/arch:AVX2" ) ;
3400- j -= 2 ;
3401- } else if ( "avx" == scale [ j ] ) {
3402- ADD_FLAG ( "CFLAGS" , "/arch:AVX" ) ;
3403- j -= 1 ;
3404- }
3386+ }
3387+ if ( TARGET_ARCH == 'x86' ) {
3388+ /* SSE2 is currently the default on 32-bit. It could change later,
3389+ for now no need to pass it. But, if SSE only was chosen,
3390+ /arch:SSE is required. */
3391+ if ( "sse" == scale [ j ] ) {
3392+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:SSE" : "-msse" ) ;
3393+ }
3394+ }
3395+ configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3396+ if ( "avx512" == scale [ j ] ) {
3397+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX512" : "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3398+ j -= 3 ;
3399+ } else if ( "avx2" == scale [ j ] ) {
3400+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX2" : "-mavx2" ) ;
3401+ j -= 2 ;
3402+ } else if ( "avx" == scale [ j ] ) {
3403+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX" : "-mavx" ) ;
3404+ j -= 1 ;
3405+ }
3406+ if ( VS_TOOLSET ) {
3407+ /* MSVC has no explicit way to enable intrinsics between SSE3 and SSE4.2.
3408+ The declared macros won't affect code generation, but will enable
3409+ the guarded code parts. */
34053410 for ( var i = 0 ; i <= j ; i ++ ) {
34063411 var it = scale [ i ] ;
34073412 AC_DEFINE ( avail . Item ( it ) , 1 ) ;
34083413 }
3414+ } else if ( CLANG_TOOLSET ) {
3415+ /* clang supports -m flags for each SSE level and auto-defines
3416+ the corresponding __SSE*__ macros. Pass the highest requested
3417+ level; clang implicitly enables all lower levels. */
3418+ var clang_flag_map = {
3419+ "sse" : "-msse" , "sse2" : "-msse2" , "sse3" : "-msse3" ,
3420+ "ssse3" : "-mssse3" , "sse4.1" : "-msse4.1" , "sse4.2" : "-msse4.2"
3421+ } ;
3422+ if ( clang_flag_map [ scale [ j ] ] ) {
3423+ ADD_FLAG ( "CFLAGS" , clang_flag_map [ scale [ j ] ] ) ;
3424+ }
34093425 }
34103426 }
34113427}
0 commit comments