internal static partial class Helpers
{
public static InstructionSetSupport ConfigureInstructionSetSupport(string instructionSet, int maxVectorTBitWidth, bool isVectorTOptimistic, TargetArchitecture targetArchitecture, TargetOS targetOS,
- string mustNotBeMessage, string invalidImplicationMessage, Logger logger)
+ string mustNotBeMessage, string invalidImplicationMessage, Logger logger, bool optimizingForSize = false)
{
InstructionSetSupportBuilder instructionSetSupportBuilder = new(targetArchitecture);
}
}
+ // Whether to allow optimistically expanding the instruction sets beyond what was specified.
+ // We seed this from optimizingForSize - if we're size-optimizing, we don't want to unnecessarily
+ // compile both branches of IsSupported checks.
+ bool allowOptimistic = !optimizingForSize;
+
if (instructionSet == "native")
{
+ // We're compiling for a specific chip
+ allowOptimistic = false;
+
if (GetTargetArchitecture(null) != targetArchitecture)
{
throw new CommandLineException("Instruction set 'native' not supported when cross-compiling to a different architecture.");
InstructionSetSupportBuilder optimisticInstructionSetSupportBuilder = new InstructionSetSupportBuilder(instructionSetSupportBuilder);
// Optimistically assume some instruction sets are present.
- if (targetArchitecture == TargetArchitecture.X86 || targetArchitecture == TargetArchitecture.X64)
+ if (allowOptimistic && (targetArchitecture == TargetArchitecture.X86 || targetArchitecture == TargetArchitecture.X64))
{
// We set these hardware features as opportunistically enabled as most of hardware in the wild supports them.
// Note that we do not indicate support for AVX, or any other instruction set which uses the VEX encodings as
TargetArchitecture targetArchitecture = Get(_command.TargetArchitecture);
TargetOS targetOS = Get(_command.TargetOS);
InstructionSetSupport instructionSetSupport = Helpers.ConfigureInstructionSetSupport(Get(_command.InstructionSet), Get(_command.MaxVectorTBitWidth), isVectorTOptimistic, targetArchitecture, targetOS,
- "Unrecognized instruction set {0}", "Unsupported combination of instruction sets: {0}/{1}", logger);
+ "Unrecognized instruction set {0}", "Unsupported combination of instruction sets: {0}/{1}", logger,
+ optimizingForSize: _command.OptimizationMode == OptimizationMode.PreferSize);
string systemModuleName = Get(_command.SystemModuleName);
string reflectionData = Get(_command.ReflectionData);