Skip to content

[Wasm RyuJit] Add new binary ops to codegenwasm.cpp #122118

@kg

Description

@kg

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:

  1. Add its corresponding gentree enum GT_xxx to the switch in CodeGen::genCodeForTreeNode in codegenwasm.cpp to make sure that it calls genCodeForBinary. GT_ADD for example is already there, so the additional items can be added as cases below GT_ADD. For example, INS_i32_sub corresponds to i32.sub which corresponds to GT_SUB.
  2. Add unique cases to genCodeForBinary in codegenwasm.cpp for each GT_xxx and TYP_xxx pairing that map to the appropriate wasm INS_type_xxx enumeration. For example, for GT_SUB and TYP_INT it would be case PackOperAndType(GT_SUB, TYP_INT): ins = INS_i32_sub; break; with appropriate newlines.

Metadata

Metadata

Assignees

Labels

arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions