-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
The Wasm RyuJit backend needs to be updated with a basic implementation of the new binary operations added to instrswasm.h in #122081. This will be done by adding new code to codegenwasm.cpp.
For floating point types (f32 and f64) the binary operations begin with the add opcode and end with the copysign opcode. For integer types (i32 and i64) these begin with the add opcode and end with the rotr opcode. The Wasm instructions are defined in instrswasm.h using INST( statements, where i.e. INST(f32_eq, "f32.eq", 0, IF_OPCODE, 0x5B) defines the binary operation INS_f32_eq.
We want to add implementations for each of these assuming there is a corresponding gentree GT_xxx enum, similar to how add has GT_ADD as its counterpart. For any Wasm binary opcode where there is no obviously corresponding GT_xxx gentree enum, we should skip it. For example, there is no GT_xxx enum for the copysign binary operator, so we can skip that one specifically.
The GT_xxx enum is defined in gtlist.h using GTNODE( statements, where i.e. GTNODE(ADD, GenTreeOp, 1, 0, GTK_BINOP defines the binary operation GT_ADD.
In some cases the mapping between operations may be non-obvious. For example, GT_UDIV with a TYP_INT maps to INS_i32_div_u. For example, GT_RSZ maps to INS_i32_shr_u because RSZ is a zero-extended right shift.
The process for adding a binary operation from instrswasm.h to codegenwasm.cpp is as follows:
- Add its corresponding gentree enum
GT_xxxto the switch inCodeGen::genCodeForTreeNodeincodegenwasm.cppto make sure that it callsgenCodeForBinary.GT_ADDfor example is already there, so the additional items can be added ascases belowGT_ADD. For example,INS_i32_subcorresponds toi32.subwhich corresponds toGT_SUB. - Add unique cases to
genCodeForBinaryincodegenwasm.cppfor eachGT_xxxandTYP_xxxpairing that map to the appropriate wasmINS_type_xxxenumeration. For example, forGT_SUBandTYP_INTit would becase PackOperAndType(GT_SUB, TYP_INT): ins = INS_i32_sub; break;with appropriate newlines.