如何在msbuild中设置“启用增强指令集”?

3
如何在使用命令行编译时设置参数“启用增强指令集”的值?

enter image description here


据推测,https://dev59.com/5GUp5IYBdhLWcg3wo4ud 将会奏效。 - Alan Birtles
你的VS版本是什么? - Mr Qian
https://stackoverflow.com/questions/6448256/how-can-msbuild-exe-be-set-up-to-embed-the-proper-value-for-sse2-into-m-ix86-fp - user6380706
1个回答

4
To achieve this, it may be complex but can be achieved. You only need to use an MSBuild property to pass the value from the MSBuild command line to the EnableEnhancedInstructionSet Item metadata.
MSBuild can pass the MSBuild property instead of item metadata. Solution: Modify the following in your xxx.vcxproj file: 1) First, set a default value of Not Set.
<PropertyGroup>

<Instruction_Set>NotSet</Instruction_Set>

</PropertyGroup>


<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <EnableEnhancedInstructionSet>$(Instruction_Set)</EnableEnhancedInstructionSet>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

2) 然后,您可以使用以下类似的msbuild命令行来设置它:

msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=StreamingSIMDExtensions

这些参数的值如下:
后者是您需要使用的
SSE:流SIMD扩展
SSE2:流SIMD扩展2
AVX:高级矢量扩展
AVX2:高级矢量扩展2
AVX512:高级矢量扩展512
IA32:无扩展
未设置:未设置
您应该在命令行中使用它的值:
msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=xxx

===========================================

更新

我已经在VS2019下成功测试了所有参数。但我想知道哪里出了问题。

请看以下内容:

a) 使用SSE

msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=StreamingSIMDExtensions

enter image description here

b) 使用 AVX

 msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=AdvancedVectorExtensions

enter image description here

c) 使用 AVX512

msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=AdvancedVectorExtensions512

enter image description here

d) 使用 IA32:

 msbuild xxx\xxx.vcxproj -t:build -p:Instruction_Set=NoExtensions

enter image description here


它能工作!但只有一个评论。 几乎在我运行的VS版本中(2019),参数的值是错误的。 它接受诸如“NotSet”,“AdvancedVectorExtensions2”,“StreamingSIMDExtensions2”等值。 - user6380706
我列出的所有值都在VS2019中进行了测试,并确保它们都正确。因此,我很好奇哪里出错了。您应该使用“-p:Instruction_Set = StreamingSIMDExtensions”或“-p:Instruction_Set = StreamingSIMDExtensions2”等。 - Mr Qian
我列出的参数后面跟着要输入的实际值。我已经更新了我的答案。请查看“更新”并进行确认。 - Mr Qian
如果有帮助,请不要忘记接受答案,如果没有帮助,请随时告诉我们。 - Mr Qian
1
好的,抱歉,我误解了参数的编写方式;)一开始我以为粗体文本是参数的值。 - user6380706
没关系。无论如何,我们的共同努力解决了你的问题。我已经将它添加到答案中。祝你有美好的一天! - Mr Qian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接