]> granicus.if.org Git - php/commitdiff
Implement configuration option for explicit native intrinsics
authorAnatol Belski <ab@php.net>
Mon, 29 Jan 2018 17:24:27 +0000 (18:24 +0100)
committerAnatol Belski <ab@php.net>
Mon, 29 Jan 2018 17:26:03 +0000 (18:26 +0100)
It mimics -march=native, AVX and more to go, if needed.

win32/build/config.w32
win32/build/confutils.js

index a043ddbb205734e0d820f670b72298007873ee04..7697838bb151141f35ff2fe78533a84cca94b516 100644 (file)
@@ -342,3 +342,10 @@ ARG_ENABLE("test-ini", "Enable automatic php.ini generation. The test.ini will b
 ARG_WITH("test-ini-ext-exclude", "Comma separated list of shared extensions to \
                be excluded from the test.ini", "no");
 
+ARG_ENABLE("native-intrinsics", "Comma separated list of intrinsic optimizations to enable. \
+       Available optimization names are sse, sse2, sse4.1, sse4.2. SSE and SSE2 are enabled \
+       by default. The best optimization specified will automatically enable all the older \
+       optimizations. Note, that the produced binary might not work properly, if the \
+       optimizations are not available on the target processor.", "no");
+toolset_setup_intrinsic_cflags();
+
index d588df78a74a55b6fdac2211b501894aa6520b78..c15af50a51590998376c192d5acc4af529e28499 100644 (file)
@@ -3219,6 +3219,53 @@ function toolset_setup_common_cflags()
        }
 }
 
+function toolset_setup_intrinsic_cflags()
+{
+       var default_enabled = "sse2";
+       /* XXX AVX and above needs to be reflected in /arch, for now SSE4.2 is
+               the best possible optimization.*/
+       var avail = WScript.CreateObject("Scripting.Dictionary");
+       avail.Add("sse", "__SSE__");
+       avail.Add("sse2", "__SSE2__");
+       avail.Add("sse3", "__SSE3__");
+       avail.Add("ssse3", "__SSSE3__");
+       avail.Add("sse4.1", "__SSE4_1__");
+       avail.Add("sse4.2", "__SSE4_2__");
+       /* From oldest to newest. */
+       var scale = new Array("sse", "sse2", "sse3", "ssse3", "sse4.1", "sse4.2");
+
+       if (VS_TOOLSET) {
+               if ("no" == PHP_NATIVE_INTRINSICS || "yes" == PHP_NATIVE_INTRINSICS) {
+                       PHP_NATIVE_INTRINSICS = default_enabled;
+               }
+
+               if ("all" == PHP_NATIVE_INTRINSICS) {
+                       var list = (new VBArray(avail.Keys())).toArray();
+
+                       for (var i in list) {
+                               AC_DEFINE(avail.Item(list[i]), 1);
+                       }
+               } else {
+                       var list = PHP_NATIVE_INTRINSICS.split(",");
+                       var j = 0;
+                       for (var k = 0; k < scale.length; k++) {
+                               for (var i = 0; i < list.length; i++) {
+                                       var it = list[i].toLowerCase();
+                                       if (scale[k] == it) {
+                                               j = k > j ? k : j;
+                                       } else if (!avail.Exists(it)) {
+                                               WARNING("Unknown intrinsic name '" + it + "' ignored");
+                                       }
+                               }
+                       }
+                       for (var i = 0; i <= j; i++) {
+                               var it = scale[i];
+                               AC_DEFINE(avail.Item(it), 1);
+                       }
+               }
+       }
+}
+
 function toolset_setup_common_ldlags()
 {
        // General DLL link flags