Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Updating the JIT to take EnableSSE3_4 into account when setting the supported instruction sets #16395

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2666,47 +2666,44 @@ void Compiler::compSetProcessor()
opts.setSupportedISA(InstructionSet_POPCNT);
}
}
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE3))

// There are currently two sets of flags that control SSE3 through SSE4.2 support
// This is the general EnableSSE3_4 flag and the individual ISA flags. We need to
// check both for any given ISA.
if (JitConfig.EnableSSE3_4())
{
if (configEnableISA(InstructionSet_SSE3))
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE3))
{
opts.setSupportedISA(InstructionSet_SSE3);
if (configEnableISA(InstructionSet_SSE3))
{
opts.setSupportedISA(InstructionSet_SSE3);
}
}
}
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE41))
{
if (configEnableISA(InstructionSet_SSE41))
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE41))
{
opts.setSupportedISA(InstructionSet_SSE41);
if (configEnableISA(InstructionSet_SSE41))
{
opts.setSupportedISA(InstructionSet_SSE41);
}
}
}
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE42))
{
if (configEnableISA(InstructionSet_SSE42))
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE42))
{
opts.setSupportedISA(InstructionSet_SSE42);
if (configEnableISA(InstructionSet_SSE42))
{
opts.setSupportedISA(InstructionSet_SSE42);
}
}
}
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSSE3))
{
if (configEnableISA(InstructionSet_SSSE3))
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSSE3))
{
opts.setSupportedISA(InstructionSet_SSSE3);
if (configEnableISA(InstructionSet_SSSE3))
{
opts.setSupportedISA(InstructionSet_SSSE3);
}
}
}
}
}

opts.compCanUseSSE4 = false;
if (!jitFlags.IsSet(JitFlags::JIT_FLAG_PREJIT) && jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE41) &&
jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE42))
{
if (JitConfig.EnableSSE3_4() != 0)
{
opts.compCanUseSSE4 = true;
}
}

if (!compIsForInlining())
{
if (canUseVexEncoding())
Expand All @@ -2716,8 +2713,12 @@ void Compiler::compSetProcessor()
codeGen->getEmitter()->SetContainsAVX(false);
codeGen->getEmitter()->SetContains256bitAVX(false);
}
else if (CanUseSSE4())
else if (compSupports(InstructionSet_SSSE3) || compSupports(InstructionSet_SSE41) ||
compSupports(InstructionSet_SSE42))
{
// Emitter::UseSSE4 controls whether we support the 4-byte encoding for certain
// instructions. We need to check if either is supported independently, since
// it is currently possible to enable/disable them separately.
codeGen->getEmitter()->SetUseSSE4(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to consider changing the name of this flag, as this is a bit confusing. But I don't think it's critical.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll log a bug to track it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
Expand Down
18 changes: 5 additions & 13 deletions src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7462,7 +7462,10 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return SIMD_AVX2_Supported;
}

if (CanUseSSE4())
// SIMD_SSE4_Supported actually requires all of SSE3, SSSE3, SSE4.1, and SSE4.2
// to be supported. We can only enable it if all four are enabled in the compiler
if (compSupports(InstructionSet_SSE42) && compSupports(InstructionSet_SSE41) &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a compSupportsAll(InstructionSet_SSE3 | InstructionSet_SSSE3 | InstructionSet_SSE41 | InstructionSet_SSE42) function to simplify this, if we think it is worthwhile.

compSupports(InstructionSet_SSSE3) && compSupports(InstructionSet_SSE3))
{
return SIMD_SSE4_Supported;
}
Expand Down Expand Up @@ -7992,7 +7995,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return false;
}

// Whether SSE2 is available
// Whether SSE and SSE2 is available
bool canUseSSE2() const
{
#ifdef _TARGET_XARCH_
Expand All @@ -8002,16 +8005,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#endif
}

// Whether SSE3, SSSE3, SSE4.1 and SSE4.2 is available
bool CanUseSSE4() const
{
#ifdef _TARGET_XARCH_
return opts.compCanUseSSE4;
#else
return false;
#endif
}

bool compSupports(InstructionSet isa) const
{
#if defined(_TARGET_XARCH_) || defined(_TARGET_ARM64_)
Expand Down Expand Up @@ -8137,7 +8130,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bool compUseCMOV;
#ifdef _TARGET_XARCH_
bool compCanUseSSE2; // Allow CodeGen to use "movq XMM" instructions
bool compCanUseSSE4; // Allow CodeGen to use SSE3, SSSE3, SSE4.1 and SSE4.2 instructions
#endif // _TARGET_XARCH_

#if defined(_TARGET_XARCH_) || defined(_TARGET_ARM64_)
Expand Down