@@ -3361,7 +3361,7 @@ function toolset_setup_common_cflags()
33613361
33623362 ADD_FLAG ( "CFLAGS" , "/Zc:wchar_t" ) ;
33633363 } else if ( CLANG_TOOLSET ) {
3364- ADD_FLAG ( "CFLAGS" , "-Wno-deprecated-declarations" ) ;
3364+ ADD_FLAG ( "CFLAGS" , "-Wno-deprecated-declarations -Wno-microsoft-enum-forward-reference " ) ;
33653365 if ( TARGET_ARCH == 'x86' ) {
33663366 ADD_FLAG ( 'CFLAGS' , '-m32' ) ;
33673367 } else {
@@ -3395,24 +3395,25 @@ function toolset_setup_intrinsic_cflags()
33953395 /* From oldest to newest. */
33963396 var scale = new Array ( "sse" , "sse2" , "sse3" , "ssse3" , "sse4.1" , "sse4.2" , "avx" , "avx2" , "avx512" ) ;
33973397
3398- if ( VS_TOOLSET ) {
3399- if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3400- ERROR ( "Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. " )
3401- }
3398+ if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3399+ ERROR ( "Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. " )
3400+ }
34023401
3403- if ( TARGET_ARCH == 'arm64' ) {
3404- /* arm64 supports neon */
3405- configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3406- /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3407- AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3408- return ;
3409- }
3402+ if ( TARGET_ARCH == 'arm64' ) {
3403+ /* arm64 supports neon */
3404+ configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3405+ /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3406+ AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3407+ return ;
3408+ }
34103409
3411- if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3412- PHP_NATIVE_INTRINSICS = default_enabled ;
3413- }
3410+ // if --enable-native-intrisics is not specified, it's "no" - enable default
3411+ if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3412+ PHP_NATIVE_INTRINSICS = default_enabled ;
3413+ }
34143414
3415- if ( "all" == PHP_NATIVE_INTRINSICS ) {
3415+ if ( "all" == PHP_NATIVE_INTRINSICS ) {
3416+ if ( VS_TOOLSET ) {
34163417 var list = ( new VBArray ( avail . Keys ( ) ) ) . toArray ( ) ;
34173418
34183419 for ( var i in list ) {
@@ -3421,46 +3422,61 @@ function toolset_setup_intrinsic_cflags()
34213422
34223423 /* All means all. __AVX__, __AVX2__, and __AVX512*__ are defined by compiler. */
34233424 ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3424- configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3425- } else {
3426- var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3427- var j = 0 ;
3428- for ( var k = 0 ; k < scale . length ; k ++ ) {
3429- for ( var i = 0 ; i < list . length ; i ++ ) {
3430- var it = list [ i ] . toLowerCase ( ) ;
3431- if ( scale [ k ] == it ) {
3432- j = k > j ? k : j ;
3433- } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3434- WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
3435- }
3436- }
3437- }
3438- if ( TARGET_ARCH == 'x86' ) {
3439- /* SSE2 is currently the default on 32-bit. It could change later,
3440- for now no need to pass it. But, if SSE only was chosen,
3441- /arch:SSE is required. */
3442- if ( "sse" == scale [ j ] ) {
3443- ADD_FLAG ( "CFLAGS" , "/arch:SSE" ) ;
3425+ } else if ( CLANG_TOOLSET ) {
3426+ ADD_FLAG ( "CFLAGS" , "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3427+ }
3428+ configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3429+ } else {
3430+ var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3431+ var j = 0 ;
3432+ for ( var k = 0 ; k < scale . length ; k ++ ) {
3433+ for ( var i = 0 ; i < list . length ; i ++ ) {
3434+ var it = list [ i ] . toLowerCase ( ) ;
3435+ if ( scale [ k ] == it ) {
3436+ j = k > j ? k : j ;
3437+ } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3438+ WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
34443439 }
34453440 }
3446- configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3447- /* There is no explicit way to enable intrinsics between SSE3 and SSE4.2.
3448- The declared macros therefore won't affect the code generation,
3449- but will enable the guarded code parts. */
3450- if ( "avx512" == scale [ j ] ) {
3451- ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3452- j -= 3 ;
3453- } else if ( "avx2" == scale [ j ] ) {
3454- ADD_FLAG ( "CFLAGS" , "/arch:AVX2" ) ;
3455- j -= 2 ;
3456- } else if ( "avx" == scale [ j ] ) {
3457- ADD_FLAG ( "CFLAGS" , "/arch:AVX" ) ;
3458- j -= 1 ;
3459- }
3441+ }
3442+ if ( TARGET_ARCH == 'x86' ) {
3443+ /* SSE2 is currently the default on 32-bit. It could change later,
3444+ for now no need to pass it. But, if SSE only was chosen,
3445+ /arch:SSE is required. */
3446+ if ( "sse" == scale [ j ] ) {
3447+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:SSE" : "-msse" ) ;
3448+ }
3449+ }
3450+ configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3451+ if ( "avx512" == scale [ j ] ) {
3452+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX512" : "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3453+ j -= 3 ;
3454+ } else if ( "avx2" == scale [ j ] ) {
3455+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX2" : "-mavx2" ) ;
3456+ j -= 2 ;
3457+ } else if ( "avx" == scale [ j ] ) {
3458+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX" : "-mavx" ) ;
3459+ j -= 1 ;
3460+ }
3461+ if ( VS_TOOLSET ) {
3462+ /* MSVC has no explicit way to enable intrinsics between SSE3 and SSE4.2.
3463+ The declared macros won't affect code generation, but will enable
3464+ the guarded code parts. */
34603465 for ( var i = 0 ; i <= j ; i ++ ) {
34613466 var it = scale [ i ] ;
34623467 AC_DEFINE ( avail . Item ( it ) , 1 ) ;
34633468 }
3469+ } else if ( CLANG_TOOLSET ) {
3470+ /* clang supports -m flags for each SSE level and auto-defines
3471+ the corresponding __SSE*__ macros. Pass the highest requested
3472+ level; clang implicitly enables all lower levels. */
3473+ var clang_flag_map = {
3474+ "sse" : "-msse" , "sse2" : "-msse2" , "sse3" : "-msse3" ,
3475+ "ssse3" : "-mssse3" , "sse4.1" : "-msse4.1" , "sse4.2" : "-msse4.2"
3476+ } ;
3477+ if ( clang_flag_map [ scale [ j ] ] ) {
3478+ ADD_FLAG ( "CFLAGS" , clang_flag_map [ scale [ j ] ] ) ;
3479+ }
34643480 }
34653481 }
34663482}
0 commit comments