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