如何在 msbuild 中设置 'Enable Enhanced Instruction Set'?

How can I set the 'Enable Enhanced Instruction Set' in msbuild?

从命令行使用 msbuild 编译时如何设置参数“Enable Enhanced Instruction Set”的值?

实现这个,可能比较复杂但是可以做到。您只需要借助 MSBuild 属性 将值从 msbuild 命令行传输到 EnableEnhancedInstructionSet Item matadata.

MSBuild 可以传输 msbuild 属性 而不是项目元数据。

解决方案

在您的 xxx.vcxproj 文件中修改这些内容:

1) 首先给它设置一个默认值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:StreamingSIMDExtensions

SSE2:StreamingSIMDExtensions2

AVX:AdvancedVectorExtensions

AVX2:AdvancedVectorExtensions2

AVX512:AdvancedVectorExtensions512

IA32: 无扩展

未设置: 未设置

你应该在命令行中使用它的值:

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

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

更新

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

请看这些:

a) 使用 SSE:

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

b) 使用 AVX:

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

c) 使用 AVX512:

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

d) 使用 IA32:

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