Add support for VCCLCompilerTool EnableEnhancedInstructionSet setting.
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/195283002
git-svn-id: http://gyp.googlecode.com/svn/trunk@1865 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/MSVSSettings.py b/pylib/gyp/MSVSSettings.py
index 63a83dc..205b3b5 100644
--- a/pylib/gyp/MSVSSettings.py
+++ b/pylib/gyp/MSVSSettings.py
@@ -616,7 +616,9 @@
_Same(_compile, 'EnableEnhancedInstructionSet',
_Enumeration(['NotSet',
'StreamingSIMDExtensions', # /arch:SSE
- 'StreamingSIMDExtensions2'])) # /arch:SSE2
+ 'StreamingSIMDExtensions2', # /arch:SSE2
+ 'AdvancedVectorExtensions', # /arch:AVX (vs2012+)
+ 'NoExtensions',])) # /arch:IA32 (vs2012+)
_Same(_compile, 'ErrorReporting',
_Enumeration(['None', # /errorReport:none
'Prompt', # /errorReport:prompt
diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py
index 709ba30..6de77d7 100644
--- a/pylib/gyp/msvs_emulation.py
+++ b/pylib/gyp/msvs_emulation.py
@@ -379,6 +379,8 @@
map={'false': '-', 'true': ''}, prefix='/Zc:wchar_t')
cl('EnablePREfast', map={'true': '/analyze'})
cl('AdditionalOptions', prefix='')
+ cl('EnableEnhancedInstructionSet',
+ map={'1': 'SSE', '2': 'SSE2', '3': 'AVX', '4': 'IA32'}, prefix='/arch:')
cflags.extend(['/FI' + f for f in self._Setting(
('VCCLCompilerTool', 'ForcedIncludeFiles'), config, default=[])])
if self.vs_version.short_name in ('2013', '2013e'):
diff --git a/test/win/compiler-flags/enable-enhanced-instruction-set.cc b/test/win/compiler-flags/enable-enhanced-instruction-set.cc
new file mode 100644
index 0000000..2491f16
--- /dev/null
+++ b/test/win/compiler-flags/enable-enhanced-instruction-set.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2014 Google Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+static const char* GetArchOption() {
+#if _M_IX86_FP == 0
+ return "IA32";
+#elif _M_IX86_FP == 1
+ return "SSE";
+#elif _M_IX86_FP == 2
+# if !defined(__AVX__)
+ return "SSE2";
+# else
+ return "AVX";
+# endif
+#else
+ return "UNSUPPORTED OPTION";
+#endif
+}
+
+int main() {
+ printf("/arch:%s\n", GetArchOption());
+ return 0;
+}
diff --git a/test/win/compiler-flags/enable-enhanced-instruction-set.gyp b/test/win/compiler-flags/enable-enhanced-instruction-set.gyp
new file mode 100644
index 0000000..44d8ad3
--- /dev/null
+++ b/test/win/compiler-flags/enable-enhanced-instruction-set.gyp
@@ -0,0 +1,54 @@
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'sse_extensions',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnableEnhancedInstructionSet': '1', # StreamingSIMDExtensions
+ }
+ },
+ 'sources': ['enable-enhanced-instruction-set.cc'],
+ },
+ {
+ 'target_name': 'sse2_extensions',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnableEnhancedInstructionSet': '2', # StreamingSIMDExtensions2
+ }
+ },
+ 'sources': ['enable-enhanced-instruction-set.cc'],
+ },
+ ],
+ 'conditions': [
+ ['MSVS_VERSION[0:4]>"2010"', {
+ 'targets': [
+ {
+ 'target_name': 'avx_extensions',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnableEnhancedInstructionSet': '3', # AdvancedVectorExtensions
+ }
+ },
+ 'sources': ['enable-enhanced-instruction-set.cc'],
+ },
+ {
+ 'target_name': 'no_extensions',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'EnableEnhancedInstructionSet': '4', # NoExtensions
+ }
+ },
+ 'sources': ['enable-enhanced-instruction-set.cc'],
+ },
+ ],
+ }],
+ ],
+}
diff --git a/test/win/gyptest-cl-enable-enhanced-instruction-set.py b/test/win/gyptest-cl-enable-enhanced-instruction-set.py
new file mode 100644
index 0000000..5ee4cdd
--- /dev/null
+++ b/test/win/gyptest-cl-enable-enhanced-instruction-set.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Test VCCLCompilerTool EnableEnhancedInstructionSet setting.
+"""
+
+import TestGyp
+
+import os
+import sys
+
+if sys.platform == 'win32':
+ test = TestGyp.TestGyp()
+
+ CHDIR = 'compiler-flags'
+ test.run_gyp('enable-enhanced-instruction-set.gyp', chdir=CHDIR)
+
+ test.build('enable-enhanced-instruction-set.gyp', test.ALL, chdir=CHDIR)
+
+ test.run_built_executable('sse_extensions', chdir=CHDIR,
+ stdout='/arch:SSE\n')
+ test.run_built_executable('sse2_extensions', chdir=CHDIR,
+ stdout='/arch:SSE2\n')
+
+ # /arch:AVX introduced in VS2010, but MSBuild support lagged until 2012.
+ if os.path.exists(test.built_file_path('avx_extensions')):
+ test.run_built_executable('no_extensions', chdir=CHDIR,
+ stdout='/arch:AVX\n')
+
+ # /arch:IA32 introduced in VS2012.
+ if os.path.exists(test.built_file_path('no_extensions')):
+ test.run_built_executable('no_extensions', chdir=CHDIR,
+ stdout='/arch:IA32\n')
+
+ test.pass_test()