Skip to content

Commit d124b96

Browse files
committed
[MERGE #5221 @sigatrev] arm64: use FCSEL for float instructions
Merge pull request #5221 from sigatrev:fcsel
2 parents 21b5e9d + cb9a86a commit d124b96

File tree

8 files changed

+36
-1
lines changed

8 files changed

+36
-1
lines changed

lib/Backend/Lower.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,8 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
30513051
{
30523052
StackSym* thisSym = instr->m_func->m_symTable->Find(symid)->AsStackSym();
30533053
IR::RegOpnd* thisSymReg = IR::RegOpnd::New(thisSym, thisSym->GetType(), instr->m_func);
3054-
IR::Instr* cmov = IR::Instr::New(LowererMD::MDSpecBlockNEOpcode, thisSymReg, thisSymReg, thisSymReg, instr->m_func);
3054+
Js::OpCode specBlockOp = thisSymReg->IsFloat() ? LowererMD::MDSpecBlockFNEOpcode : LowererMD::MDSpecBlockNEOpcode;
3055+
IR::Instr* cmov = IR::Instr::New(specBlockOp, thisSymReg, thisSymReg, thisSymReg, instr->m_func);
30553056
instr->InsertBefore(cmov);
30563057
m_lowererMD.Legalize(cmov);
30573058
} NEXT_BITSET_IN_SPARSEBV;

lib/Backend/LowerMDShared.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Js::OpCode LowererMD::MDCallOpcode = Js::OpCode::CALL;
2222
const Js::OpCode LowererMD::MDImulOpcode = Js::OpCode::IMUL2;
2323
const Js::OpCode LowererMD::MDLea = Js::OpCode::LEA;
2424
const Js::OpCode LowererMD::MDSpecBlockNEOpcode = Js::OpCode::CMOVNE;
25+
const Js::OpCode LowererMD::MDSpecBlockFNEOpcode = Js::OpCode::CMOVNE;
2526

2627
static const int TWO_31_FLOAT = 0x4f000000;
2728
static const int FLOAT_INT_MIN = 0xcf000000;

lib/Backend/LowerMDShared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class LowererMD
8181
static const Js::OpCode MDImulOpcode;
8282
static const Js::OpCode MDLea;
8383
static const Js::OpCode MDSpecBlockNEOpcode;
84+
static const Js::OpCode MDSpecBlockFNEOpcode;
8485

8586
UINT FloatPrefThreshold;
8687

lib/Backend/arm64/EncoderMD.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,24 @@ int EncoderMD::EmitConvertToInt(Arm64CodeEmitter &Emitter, IR::Instr* instr, _In
761761
return 0;
762762
}
763763

764+
template<typename _Emitter>
765+
int EncoderMD::EmitConditionalSelectFp(Arm64CodeEmitter &Emitter, IR::Instr *instr, int condition, _Emitter emitter)
766+
{
767+
IR::Opnd* dst = instr->GetDst();
768+
IR::Opnd* src1 = instr->GetSrc1();
769+
IR::Opnd* src2 = instr->GetSrc2();
770+
Assert(dst->IsRegOpnd());
771+
Assert(src1->IsRegOpnd());
772+
Assert(src2->IsRegOpnd());
773+
774+
int size = dst->GetSize();
775+
Assert(size == 4 || size == 8);
776+
Assert(size == src1->GetSize());
777+
Assert(size == src2->GetSize());
778+
779+
return emitter(Emitter, this->GetFloatRegEncode(dst->AsRegOpnd()), this->GetFloatRegEncode(src1->AsRegOpnd()), this->GetRegEncode(src2->AsRegOpnd()), condition, (size == 8) ? SIZE_1D : SIZE_1S);
780+
}
781+
764782
//---------------------------------------------------------------------------
765783
//
766784
// GenerateEncoding()
@@ -1180,6 +1198,14 @@ EncoderMD::GenerateEncoding(IR::Instr* instr, BYTE *pc)
11801198
bytes = this->EmitOp2FpRegister(Emitter, instr->GetSrc1(), instr->GetSrc2(), EmitNeonFcmp);
11811199
break;
11821200

1201+
case Js::OpCode::FCSELEQ:
1202+
bytes = this->EmitConditionalSelectFp(Emitter, instr, COND_EQ, EmitNeonFcsel);
1203+
break;
1204+
1205+
case Js::OpCode::FCSELNE:
1206+
bytes = this->EmitConditionalSelectFp(Emitter, instr, COND_NE, EmitNeonFcsel);
1207+
break;
1208+
11831209
case Js::OpCode::FCVT:
11841210
dst = instr->GetDst();
11851211
src1 = instr->GetSrc1();

lib/Backend/arm64/EncoderMD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,5 @@ class EncoderMD
256256
template<typename _LoadStoreFunc> int EmitLoadStoreFp(Arm64CodeEmitter &Emitter, IR::Instr* instr, IR::Opnd* memOpnd, IR::Opnd* srcDstOpnd, _LoadStoreFunc loadStore);
257257
template<typename _LoadStoreFunc> int EmitLoadStoreFpPair(Arm64CodeEmitter &Emitter, IR::Instr* instr, IR::Opnd* memOpnd, IR::Opnd* srcDst1Opnd, IR::Opnd* srcDst2Opnd, _LoadStoreFunc loadStore);
258258
template<typename _Int32Func, typename _Uint32Func, typename _Int64Func, typename _Uint64Func> int EmitConvertToInt(Arm64CodeEmitter &Emitter, IR::Instr* instr, _Int32Func toInt32, _Uint32Func toUint32, _Int64Func toInt64, _Uint64Func toUint64);
259+
template<typename _Emitter> int EmitConditionalSelectFp(Arm64CodeEmitter &Emitter, IR::Instr *instr, int condition, _Emitter emitter);
259260
};

lib/Backend/arm64/LowerMD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Js::OpCode LowererMD::MDCallOpcode = Js::OpCode::Call;
1919
const Js::OpCode LowererMD::MDImulOpcode = Js::OpCode::MUL;
2020
const Js::OpCode LowererMD::MDLea = Js::OpCode::LEA;
2121
const Js::OpCode LowererMD::MDSpecBlockNEOpcode = Js::OpCode::CSELNE;
22+
const Js::OpCode LowererMD::MDSpecBlockFNEOpcode = Js::OpCode::FCSELNE;
2223

2324
template<typename T>
2425
inline void Swap(T& x, T& y)

lib/Backend/arm64/LowerMD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class LowererMD
6262
static const Js::OpCode MDImulOpcode;
6363
static const Js::OpCode MDLea;
6464
static const Js::OpCode MDSpecBlockNEOpcode;
65+
static const Js::OpCode MDSpecBlockFNEOpcode;
6566

6667
public:
6768
void Init(Lowerer *lowerer);

lib/Backend/arm64/MdOpCodes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ MACRO(LDARGOUTSZ, Reg1, 0, UNUSED, LEGAL_REG1, UNUSED,
108108
//VFP instructions:
109109
MACRO(FABS, Reg2, 0, UNUSED, LEGAL_REG2, UNUSED, D___)
110110
MACRO(FADD, Reg3, 0, UNUSED, LEGAL_REG3, UNUSED, D___)
111+
// FCSELcc src1, src2 -- select src1 if cc or src2 if not
112+
MACRO(FCSELEQ, Reg3, 0, UNUSED, LEGAL_REG3, UNUSED, D___)
113+
MACRO(FCSELNE, Reg3, 0, UNUSED, LEGAL_REG3, UNUSED, D___)
111114
MACRO(FCMP, Reg1, OpSideEffect, UNUSED, LEGAL_REG3_ND, UNUSED, D___)
112115
MACRO(FCVT, Reg2, 0, UNUSED, LEGAL_REG2, UNUSED, D___)
113116
MACRO(FCVTM, Reg2, 0, UNUSED, LEGAL_REG2, UNUSED, D___)

0 commit comments

Comments
 (0)