Commit 616b64fb authored by Maciej Kalinski's avatar Maciej Kalinski Committed by gbsbuild

Certain IGC clients may need to set default rounding mode, which previously...

Certain IGC clients may need to set default rounding mode, which previously was hardcoded as RNE for fp and RTZ for int

Change-Id: I59f37d7deffffdfa62ee76e44a87682e7a00c0c5
parent fc81f93b
......@@ -1308,7 +1308,6 @@ void CEncoder::DataMov(ISA_Opcode opcode, CVariable* dst, CVariable* src)
bool Need64BitEmu =
m_program->GetContext()->platform.hasNo64BitInst() &&
(Is64BitDst || Is64BitSrc);
// If DP is not supported, need to split mov as well.
if (IGC_IS_FLAG_ENABLED(ForceDPEmulation) ||
!m_program->GetContext()->platform.supportFP64())
......@@ -1615,7 +1614,6 @@ void CEncoder::Arithmetic(ISA_Opcode opcode, CVariable* dst, CVariable* src0, CV
VISA_VectorOpnd* srcOpnd2 = GetSourceOperand(src2, m_encoderState.m_srcOperand[2]);
VISA_VectorOpnd* dstOpnd = GetDestinationOperand(dst, m_encoderState.m_dstOperand);
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
V(vKernel->AppendVISAArithmeticInst(
opcode,
predOpnd,
......@@ -2577,52 +2575,37 @@ void CEncoder::SetVectorMask(bool VMask)
src1_Opnd));
}
void CEncoder::SetCr0FromRneModeTo(uint roundingMode)
void CEncoder::SetFloatRoundingMode(RoundingMode actualMode, RoundingMode newMode)
{
assert (roundingMode != RoundingMode::RoundToNearestEven &&
"Changing to same rounding mode is probably a bug");
VISA_VectorOpnd* src0_Opnd = nullptr;
VISA_VectorOpnd* src1_Opnd = nullptr;
VISA_VectorOpnd* dst_Opnd = nullptr;
VISA_GenVar* cr0_var;
V(vKernel->GetPredefinedVar(cr0_var, PREDEFINED_CR0));
V(vKernel->CreateVISASrcOperand(src0_Opnd, cr0_var, MODIFIER_NONE, 0, 1, 0, 0, 0));
V(vKernel->CreateVISAImmediate(src1_Opnd, &roundingMode, ISA_TYPE_UD));
V(vKernel->CreateVISADstOperand(dst_Opnd, cr0_var, 1, 0, 0));
V(vKernel->AppendVISAArithmeticInst(
ISA_OR,
nullptr,
false,
vISA_EMASK_M1_NM,
EXEC_SIZE_1,
dst_Opnd,
src0_Opnd,
src1_Opnd));
if (actualMode != newMode)
{
VISA_VectorOpnd* src0_Opnd = nullptr;
VISA_VectorOpnd* src1_Opnd = nullptr;
VISA_VectorOpnd* dst_Opnd = nullptr;
VISA_GenVar* cr0_var;
uint roundingMode = actualMode ^ newMode;
V(vKernel->GetPredefinedVar(cr0_var, PREDEFINED_CR0));
V(vKernel->CreateVISASrcOperand(src0_Opnd, cr0_var, MODIFIER_NONE, 0, 1, 0, 0, 0));
V(vKernel->CreateVISAImmediate(src1_Opnd, &roundingMode, ISA_TYPE_UD));
V(vKernel->CreateVISADstOperand(dst_Opnd, cr0_var, 1, 0, 0));
V(vKernel->AppendVISAArithmeticInst(
ISA_XOR,
nullptr,
false,
vISA_EMASK_M1_NM,
EXEC_SIZE_1,
dst_Opnd,
src0_Opnd,
src1_Opnd));
}
}
void CEncoder::SetCr0RneMode()
void CEncoder::SetFloatRoundingModeDefault(RoundingMode actualMode)
{
VISA_VectorOpnd* src0_Opnd = nullptr;
VISA_VectorOpnd* src1_Opnd = nullptr;
VISA_VectorOpnd* dst_Opnd = nullptr;
VISA_GenVar* cr0_var;
// Note that this will set RNE for FP and rtz for float->int
uint imm_data = ~IntAndFPRoundingModeMask;
const RoundingMode defaultRoundingMode = getEncoderRoundingMode(static_cast<Float_RoundingMode>(
m_program->GetContext()->getModuleMetaData()->compOpt.FloatRoundingMode));
V(vKernel->GetPredefinedVar(cr0_var, PREDEFINED_CR0));
V(vKernel->CreateVISASrcOperand(src0_Opnd, cr0_var, MODIFIER_NONE, 0, 1, 0, 0, 0));
V(vKernel->CreateVISAImmediate(src1_Opnd, &imm_data, ISA_TYPE_UD));
V(vKernel->CreateVISADstOperand(dst_Opnd, cr0_var, 1, 0, 0));
V(vKernel->AppendVISAArithmeticInst(
ISA_AND,
nullptr,
false,
vISA_EMASK_M1_NM,
EXEC_SIZE_1,
dst_Opnd,
src0_Opnd,
src1_Opnd));
SetFloatRoundingMode(actualMode, defaultRoundingMode);
}
CEncoder::RoundingMode CEncoder::getEncoderRoundingMode(Float_RoundingMode FP_RM)
......@@ -3956,6 +3939,11 @@ void CEncoder::InitEncoder( bool canAbortOnSpill )
context->m_floatDenormMode32,
context->m_floatDenormMode64);
// The instruction is generated only if mode != FLOAT_ROUND_TO_NEAREST_EVEN
CEncoder::SetFloatRoundingMode(
getEncoderRoundingMode(FLOAT_ROUND_TO_NEAREST_EVEN),
getEncoderRoundingMode(static_cast<Float_RoundingMode>(
context->getModuleMetaData()->compOpt.FloatRoundingMode)));
}
void CEncoder::SetKernelStackPointer64()
......
......@@ -366,12 +366,11 @@ public:
IntAndFPRoundingModeMask = 0x1030
};
// SetCr0FromRneModeTo - Assumes that current rounding mode is RNE. Switches to mode
// specified by 'roundingMode'.
void SetCr0FromRneModeTo(uint roundingMode);
// SetCr0RneMode - Sets the rounding mode to RNE
void SetCr0RneMode();
// Get rouding mode of encoder
// Switches from actualMode to newMode
void SetFloatRoundingMode(RoundingMode actualMode, RoundingMode newMode);
// Switches from actualMode to default rounding mode
void SetFloatRoundingModeDefault(RoundingMode actualMode);
// Get rounding mode of encoder
RoundingMode getEncoderRoundingMode(Float_RoundingMode FP_RM);
static uint GetCISADataTypeSize(VISA_Type type);
......
......@@ -389,6 +389,8 @@ bool EmitPass::runOnFunction(llvm::Function &F)
}
// call builder after pre-analysis pass where scratchspace offset to VISA is calculated
m_encoder->InitEncoder(m_canAbortOnSpill);
m_roundingMode = m_encoder->getEncoderRoundingMode(
static_cast<Float_RoundingMode>(ctx->getModuleMetaData()->compOpt.FloatRoundingMode));
m_currShader->PreCompile();
if (m_FGA && m_FGA->getGroup(&F)->hasStackCall())
{
......@@ -11794,7 +11796,10 @@ bool EmitPass::ignoreRoundingMode(llvm::Instruction* inst) const
void EmitPass::ResetRoundingMode(llvm::GenIntrinsicInst* inst)
{
if (m_roundingMode == CEncoder::RoundToNearestEven) {
const CEncoder::RoundingMode defaultRoundingMode = m_encoder->getEncoderRoundingMode(static_cast<Float_RoundingMode>(
getAnalysis<CodeGenContextWrapper>().getCodeGenContext()->getModuleMetaData()->compOpt.FloatRoundingMode));
if (m_roundingMode == defaultRoundingMode) {
// Already in default mode.
return;
}
......@@ -11815,8 +11820,8 @@ void EmitPass::ResetRoundingMode(llvm::GenIntrinsicInst* inst)
break;
}
m_encoder->SetCr0RneMode();
m_roundingMode = CEncoder::RoundToNearestEven;
m_encoder->SetFloatRoundingModeDefault(m_roundingMode);
m_roundingMode = defaultRoundingMode;
}
void EmitPass::emitf32tof16_rtz(llvm::GenIntrinsicInst* inst)
......@@ -11827,7 +11832,7 @@ void EmitPass::emitf32tof16_rtz(llvm::GenIntrinsicInst* inst)
if (m_roundingMode != GetRoundingMode(inst))
{
m_encoder->SetCr0FromRneModeTo(CEncoder::RoundToZero);
m_encoder->SetFloatRoundingMode(m_roundingMode, CEncoder::RoundToZero);
m_roundingMode = CEncoder::RoundToZero;
}
......@@ -11859,7 +11864,7 @@ void EmitPass::emititof(llvm::GenIntrinsicInst* inst)
if (RM != m_roundingMode)
{
m_encoder->SetCr0FromRneModeTo(RM);
m_encoder->SetFloatRoundingMode(m_roundingMode, RM);
m_roundingMode = RM;
}
m_encoder->Cast(dst, src);
......@@ -11881,7 +11886,7 @@ void EmitPass::emitFPOrtz(llvm::GenIntrinsicInst* inst)
if (RM != m_roundingMode)
{
m_encoder->SetCr0FromRneModeTo(RM);
m_encoder->SetFloatRoundingMode(m_roundingMode, RM);
m_roundingMode = RM;
}
......@@ -11927,7 +11932,7 @@ void EmitPass::emitfptrunc(llvm::GenIntrinsicInst* inst)
if (RM != m_roundingMode)
{
m_encoder->SetCr0FromRneModeTo(RM);
m_encoder->SetFloatRoundingMode(m_roundingMode, RM);
m_roundingMode = RM;
}
m_encoder->Cast(dst, src);
......@@ -14096,4 +14101,3 @@ void EmitPass::emitDP4A(GenIntrinsicInst* GII) {
m_encoder->Push();
}
......@@ -75,6 +75,7 @@ namespace IGC
bool OptDisable = false;
bool MadEnable = false;
bool NoSignedZeros = false;
unsigned FloatRoundingMode = 0; // default mode: IGC::Float_RoundingMode::FLOAT_ROUND_TO_NEAREST_EVEN
bool UnsafeMathOptimizations = false;
bool FiniteMathOnly = false;
bool FastRelaxedMath = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment