Skip to content

Commit

Permalink
More simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatos committed Jul 19, 2024
1 parent e85c679 commit 189dca9
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,19 +887,14 @@ void X87StackOptimization::Run(IREmitter* Emit) {

// We need a couple of intermediate instructions to change the sign
// of a value
Ref HelperNode {};
if (!ReducedPrecisionMode) {
Ref Low = GetConstant(0);
Ref High = GetConstant(0b1'000'0000'0000'0000ULL);
HelperNode = IREmit->_VCastFromGPR(16, 8, Low);
HelperNode = IREmit->_VInsGPR(16, 8, 1, HelperNode, High);
}

// Negate value
Ref ResultNode {};
if (ReducedPrecisionMode) {
ResultNode = IREmit->_VFNeg(8, 8, Value);
} else {
Ref Low = GetConstant(0);
Ref High = GetConstant(0b1'000'0000'0000'0000ULL);
Ref HelperNode = IREmit->_VCastFromGPR(16, 8, Low);
HelperNode = IREmit->_VInsGPR(16, 8, 1, HelperNode, High);
ResultNode = IREmit->_VXor(16, 1, Value, HelperNode);
}
StoreStackValue(ResultNode);
Expand All @@ -909,19 +904,15 @@ void X87StackOptimization::Run(IREmitter* Emit) {
case OP_F80STACKABS: {
Ref Value = LoadStackValue();

Ref HelperNode {};
if (!ReducedPrecisionMode) {
// Intermediate insts
Ref Low = GetConstant(~0ULL);
Ref High = GetConstant(0b0'111'1111'1111'1111ULL);
HelperNode = IREmit->_VCastFromGPR(16, 8, Low);
HelperNode = IREmit->_VInsGPR(16, 8, 1, HelperNode, High);
}

Ref ResultNode {};
if (ReducedPrecisionMode) {
ResultNode = IREmit->_VFAbs(8, 8, Value);
} else {
// Intermediate insts
Ref Low = GetConstant(~0ULL);
Ref High = GetConstant(0b0'111'1111'1111'1111ULL);
Ref HelperNode = IREmit->_VCastFromGPR(16, 8, Low);
HelperNode = IREmit->_VInsGPR(16, 8, 1, HelperNode, High);
ResultNode = IREmit->_VAnd(16, 1, Value, HelperNode);
}
StoreStackValue(ResultNode);
Expand Down Expand Up @@ -1012,16 +1003,20 @@ void X87StackOptimization::Run(IREmitter* Emit) {
break;
}

case OP_INCSTACKTOP:
case OP_INCSTACKTOP: {
if (SlowPath) {
UpdateTopForPush_Slow();
} else {
StackData.rotate(false);
}
break;
}

case OP_DECSTACKTOP: {
if (SlowPath) {
if (IROp->Op == OP_DECSTACKTOP) {
UpdateTopForPop_Slow();
} else {
UpdateTopForPush_Slow();
}
UpdateTopForPop_Slow();
} else {
StackData.rotate(IROp->Op == OP_DECSTACKTOP);
StackData.rotate(true);
}
break;
}
Expand All @@ -1042,13 +1037,12 @@ void X87StackOptimization::Run(IREmitter* Emit) {
case OP_F80VBSLSTACK: {
const auto* Op = IROp->C<IROp_F80VBSLStack>();

auto* VecCond = CurrentIR.GetNode(Op->VectorMask);
auto StackOffset1 = Op->SrcStack1;
auto StackOffset2 = Op->SrcStack2;
Ref Value1 = LoadStackValue(StackOffset1);
Ref Value2 = LoadStackValue(StackOffset2);

Ref StackNode = IREmit->_VBSL(16, VecCond, Value1, Value2);
Ref StackNode = IREmit->_VBSL(16, CurrentIR.GetNode(Op->VectorMask), Value1, Value2);
StoreStackValue(StackNode, 0, StackOffset1 && StackOffset2);
break;
}
Expand Down

0 comments on commit 189dca9

Please sign in to comment.