The WebAssembly RyuJIT backend in codegenwasm.cpp and emitwasm.cpp needs to be updated as follows:
- Add a definition for
CodeGen::genSetRegToConst which switches on tree->gtOper() and has cases for GT_CNS_INT and GT_CNS_DBL. The case for GT_CNS_INT should use AsIntCon()->IconValue() to store the integer constant into a ssize_t constant. The case for GT_CNS_DBL should use AsDblCon()->DconValue() to store the double constant into a double constant.
- Declare a new member function in
emitwasm.h called emitEncodeLEB64 with the signature size_t emitter:emitEncodeLEB64(uint8_t *destination, const void *source, bool valueIsSigned).
- Define
emitEncodeLeb64 in emitwasm.cpp and make its body a NYI_WASM.
- Declare a new member function in
emitwasm.h called emitIns_R_F with the signature void emitter::emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl).
- Define
emitIns_R_F in emitwasm.cpp and make its body a NYI_WASM.
- Update
genSetRegToConst's GT_CNS_INT case to use emitEncodeLEB64 to measure the size of the integer constant like so: emitAttr encodedSize = (emitAttr)GetEmitter()->emitEncodeLEB64(nullptr, &constant, true);
- Update
genSetRegToConst's GT_CNS_DBL case to determine the size of the floating-point constant based on targetType, like so: emitAttr encodedSize = (targetType == TYP_FLOAT) ? EA_4BYTE : EA_8BYTE;
- Update
genSetRegToConst's GT_CNS_INT case to call emitIns_R_I with appropriate arguments, like so: GetEmitter()->emitIns_R_I((targetType == TYP_INT) ? INS_i32_const : INS_i64_const, encodedSize, targetReg, constant);.
- Update
genSetRegToConst's GT_CNS_DBL case to call emitIns_R_F with appropriate arguments, like so: GetEmitter()->emitIns_R_F((targetType == TYP_FLOAT) ? INS_f32_const : INS_f64_const, encodedSize, targetReg, constant);.
- Update
CodeGen::genCodeForTreeNode to add cases for GT_CNS_INT and GT_CNS_DBL that call the new genSetRegToConst member function. The targetReg is treeNode->GetRegNum() and the targetType is treeNode->TypeGet(). After calling genSetRegToConst, call genProduceReg(treeNode).
The WebAssembly RyuJIT backend in
codegenwasm.cppandemitwasm.cppneeds to be updated as follows:CodeGen::genSetRegToConstwhich switches ontree->gtOper()and has cases forGT_CNS_INTandGT_CNS_DBL. The case forGT_CNS_INTshould useAsIntCon()->IconValue()to store the integer constant into assize_t constant. The case forGT_CNS_DBLshould useAsDblCon()->DconValue()to store the double constant into adouble constant.emitwasm.hcalledemitEncodeLEB64with the signaturesize_t emitter:emitEncodeLEB64(uint8_t *destination, const void *source, bool valueIsSigned).emitEncodeLeb64inemitwasm.cppand make its body aNYI_WASM.emitwasm.hcalledemitIns_R_Fwith the signaturevoid emitter::emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl).emitIns_R_Finemitwasm.cppand make its body aNYI_WASM.genSetRegToConst'sGT_CNS_INTcase to useemitEncodeLEB64to measure the size of the integer constant like so:emitAttr encodedSize = (emitAttr)GetEmitter()->emitEncodeLEB64(nullptr, &constant, true);genSetRegToConst'sGT_CNS_DBLcase to determine the size of the floating-point constant based on targetType, like so:emitAttr encodedSize = (targetType == TYP_FLOAT) ? EA_4BYTE : EA_8BYTE;genSetRegToConst'sGT_CNS_INTcase to callemitIns_R_Iwith appropriate arguments, like so:GetEmitter()->emitIns_R_I((targetType == TYP_INT) ? INS_i32_const : INS_i64_const, encodedSize, targetReg, constant);.genSetRegToConst'sGT_CNS_DBLcase to callemitIns_R_Fwith appropriate arguments, like so:GetEmitter()->emitIns_R_F((targetType == TYP_FLOAT) ? INS_f32_const : INS_f64_const, encodedSize, targetReg, constant);.CodeGen::genCodeForTreeNodeto add cases forGT_CNS_INTandGT_CNS_DBLthat call the newgenSetRegToConstmember function. ThetargetRegistreeNode->GetRegNum()and thetargetTypeistreeNode->TypeGet(). After callinggenSetRegToConst, callgenProduceReg(treeNode).