@@ -3397,24 +3397,24 @@ function toolset_setup_intrinsic_cflags()
33973397 /* From oldest to newest. */
33983398 var scale = new Array ( "sse" , "sse2" , "sse3" , "ssse3" , "sse4.1" , "sse4.2" , "avx" , "avx2" , "avx512" ) ;
33993399
3400- if ( VS_TOOLSET ) {
3401- if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3402- ERROR ( "Can't enable intrinsics, --with-codegen-arch passed with an incompatible option. " )
3403- }
3400+ if ( "disabled" == PHP_NATIVE_INTRINSICS ) {
3401+ return ;
3402+ }
34043403
3405- if ( TARGET_ARCH == 'arm64' ) {
3406- /* arm64 supports neon */
3407- configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3408- /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3409- AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3410- return ;
3411- }
3404+ if ( TARGET_ARCH == 'arm64' ) {
3405+ /* arm64 supports neon */
3406+ configure_subst . Add ( "PHP_SIMD_SCALE" , 'NEON' ) ;
3407+ /* all officially supported arm64 cpu supports crc32 (TODO: to be confirmed) */
3408+ AC_DEFINE ( 'HAVE_ARCH64_CRC32' , 1 ) ;
3409+ return ;
3410+ }
34123411
3413- if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3414- PHP_NATIVE_INTRINSICS = default_enabled ;
3415- }
3412+ if ( "no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS ) {
3413+ PHP_NATIVE_INTRINSICS = default_enabled ;
3414+ }
34163415
3417- if ( "all" == PHP_NATIVE_INTRINSICS ) {
3416+ if ( "all" == PHP_NATIVE_INTRINSICS ) {
3417+ if ( VS_TOOLSET ) {
34183418 var list = ( new VBArray ( avail . Keys ( ) ) ) . toArray ( ) ;
34193419
34203420 for ( var i in list ) {
@@ -3423,42 +3423,47 @@ function toolset_setup_intrinsic_cflags()
34233423
34243424 /* All means all. __AVX__, __AVX2__, and __AVX512*__ are defined by compiler. */
34253425 ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3426- configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3427- } else {
3428- var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3429- var j = 0 ;
3430- for ( var k = 0 ; k < scale . length ; k ++ ) {
3431- for ( var i = 0 ; i < list . length ; i ++ ) {
3432- var it = list [ i ] . toLowerCase ( ) ;
3433- if ( scale [ k ] == it ) {
3434- j = k > j ? k : j ;
3435- } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3436- WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
3437- }
3438- }
3439- }
3440- if ( TARGET_ARCH == 'x86' ) {
3441- /* SSE2 is currently the default on 32-bit. It could change later,
3442- for now no need to pass it. But, if SSE only was chosen,
3443- /arch:SSE is required. */
3444- if ( "sse" == scale [ j ] ) {
3445- ADD_FLAG ( "CFLAGS" , "/arch:SSE" ) ;
3426+ } else if ( CLANG_TOOLSET ) {
3427+ ADD_FLAG ( "CFLAGS" , "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3428+ }
3429+ configure_subst . Add ( "PHP_SIMD_SCALE" , "AVX512" ) ;
3430+ } else {
3431+ var list = PHP_NATIVE_INTRINSICS . split ( "," ) ;
3432+ var j = 0 ;
3433+ for ( var k = 0 ; k < scale . length ; k ++ ) {
3434+ for ( var i = 0 ; i < list . length ; i ++ ) {
3435+ var it = list [ i ] . toLowerCase ( ) ;
3436+ if ( scale [ k ] == it ) {
3437+ j = k > j ? k : j ;
3438+ } else if ( ! avail . Exists ( it ) && "avx512" != it && "avx2" != it && "avx" != it ) {
3439+ WARNING ( "Unknown intrinsic name '" + it + "' ignored" ) ;
34463440 }
34473441 }
3448- configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3449- /* There is no explicit way to enable intrinsics between SSE3 and SSE4.2.
3450- The declared macros therefore won't affect the code generation,
3451- but will enable the guarded code parts. */
3452- if ( "avx512" == scale [ j ] ) {
3453- ADD_FLAG ( "CFLAGS" , "/arch:AVX512" ) ;
3454- j -= 3 ;
3455- } else if ( "avx2" == scale [ j ] ) {
3456- ADD_FLAG ( "CFLAGS" , "/arch:AVX2" ) ;
3457- j -= 2 ;
3458- } else if ( "avx" == scale [ j ] ) {
3459- ADD_FLAG ( "CFLAGS" , "/arch:AVX" ) ;
3460- j -= 1 ;
3461- }
3442+ }
3443+ if ( TARGET_ARCH == 'x86' ) {
3444+ /* SSE2 is currently the default on 32-bit. It could change later,
3445+ for now no need to pass it. But, if SSE only was chosen,
3446+ /arch:SSE is required. */
3447+ if ( "sse" == scale [ j ] ) {
3448+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:SSE" : "-msse" ) ;
3449+ }
3450+ }
3451+ configure_subst . Add ( "PHP_SIMD_SCALE" , scale [ j ] . toUpperCase ( ) ) ;
3452+ /* There is no explicit way to enable intrinsics between SSE3 and SSE4.2.
3453+ The declared macros therefore won't affect the code generation,
3454+ but will enable the guarded code parts. */
3455+ if ( "avx512" == scale [ j ] ) {
3456+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX512" : "-mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl" ) ;
3457+ j -= 3 ;
3458+ } else if ( "avx2" == scale [ j ] ) {
3459+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX2" : "-mavx2" ) ;
3460+ j -= 2 ;
3461+ } else if ( "avx" == scale [ j ] ) {
3462+ ADD_FLAG ( "CFLAGS" , VS_TOOLSET ? "/arch:AVX" : "-mavx" ) ;
3463+ j -= 1 ;
3464+ }
3465+ if ( VS_TOOLSET ) {
3466+ /* MSVC doesn't auto-define SSE macros; clang does with -m flags */
34623467 for ( var i = 0 ; i <= j ; i ++ ) {
34633468 var it = scale [ i ] ;
34643469 AC_DEFINE ( avail . Item ( it ) , 1 ) ;
0 commit comments