| 1 |
package ssa |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"math" |
| 6 |
"strings" |
| 7 |
|
| 8 |
"github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi" |
| 9 |
) |
| 10 |
|
| 11 |
// Opcode represents a SSA instruction. |
| 12 |
type Opcode uint32 |
| 13 |
|
| 14 |
// Instruction represents an instruction whose opcode is specified by |
| 15 |
// Opcode. Since Go doesn't have union type, we use this flattened type |
| 16 |
// for all instructions, and therefore each field has different meaning |
| 17 |
// depending on Opcode. |
| 18 |
type Instruction struct { |
| 19 |
// id is the unique ID of this instruction which ascends from 0 following the order of program. |
| 20 |
id int |
| 21 |
opcode Opcode |
| 22 |
u1, u2 uint64 |
| 23 |
v Value |
| 24 |
v2 Value |
| 25 |
v3 Value |
| 26 |
vs Values |
| 27 |
typ Type |
| 28 |
prev, next *Instruction |
| 29 |
|
| 30 |
// rValue is the (first) return value of this instruction. |
| 31 |
// For branching instructions except for OpcodeBrTable, they hold BlockID to jump cast to Value. |
| 32 |
rValue Value |
| 33 |
// rValues are the rest of the return values of this instruction. |
| 34 |
// For OpcodeBrTable, it holds the list of BlockID to jump cast to Value. |
| 35 |
rValues Values |
| 36 |
gid InstructionGroupID |
| 37 |
sourceOffset SourceOffset |
| 38 |
live bool |
| 39 |
alreadyLowered bool |
| 40 |
} |
| 41 |
|
| 42 |
// SourceOffset represents the offset of the source of an instruction. |
| 43 |
type SourceOffset int64 |
| 44 |
|
| 45 |
const sourceOffsetUnknown = -1 |
| 46 |
|
| 47 |
// Valid returns true if this source offset is valid. |
| 48 |
func (l SourceOffset) Valid() bool { |
| 49 |
return l != sourceOffsetUnknown |
| 50 |
} |
| 51 |
|
| 52 |
func (i *Instruction) annotateSourceOffset(line SourceOffset) { |
| 53 |
i.sourceOffset = line |
| 54 |
} |
| 55 |
|
| 56 |
// SourceOffset returns the source offset of this instruction. |
| 57 |
func (i *Instruction) SourceOffset() SourceOffset { |
| 58 |
return i.sourceOffset |
| 59 |
} |
| 60 |
|
| 61 |
// Opcode returns the opcode of this instruction. |
| 62 |
func (i *Instruction) Opcode() Opcode { |
| 63 |
return i.opcode |
| 64 |
} |
| 65 |
|
| 66 |
// GroupID returns the InstructionGroupID of this instruction. |
| 67 |
func (i *Instruction) GroupID() InstructionGroupID { |
| 68 |
return i.gid |
| 69 |
} |
| 70 |
|
| 71 |
// MarkLowered marks this instruction as already lowered. |
| 72 |
func (i *Instruction) MarkLowered() { |
| 73 |
i.alreadyLowered = true |
| 74 |
} |
| 75 |
|
| 76 |
// Lowered returns true if this instruction is already lowered. |
| 77 |
func (i *Instruction) Lowered() bool { |
| 78 |
return i.alreadyLowered |
| 79 |
} |
| 80 |
|
| 81 |
// resetInstruction resets this instruction to the initial state. |
| 82 |
func resetInstruction(i *Instruction) { |
| 83 |
*i = Instruction{} |
| 84 |
i.v = ValueInvalid |
| 85 |
i.v2 = ValueInvalid |
| 86 |
i.v3 = ValueInvalid |
| 87 |
i.rValue = ValueInvalid |
| 88 |
i.typ = typeInvalid |
| 89 |
i.vs = ValuesNil |
| 90 |
i.sourceOffset = sourceOffsetUnknown |
| 91 |
} |
| 92 |
|
| 93 |
// InstructionGroupID is assigned to each instruction and represents a group of instructions |
| 94 |
// where each instruction is interchangeable with others except for the last instruction |
| 95 |
// in the group which has side effects. In short, InstructionGroupID is determined by the side effects of instructions. |
| 96 |
// That means, if there's an instruction with side effect between two instructions, then these two instructions |
| 97 |
// will have different instructionGroupID. Note that each block always ends with branching, which is with side effects, |
| 98 |
// therefore, instructions in different blocks always have different InstructionGroupID(s). |
| 99 |
// |
| 100 |
// The notable application of this is used in lowering SSA-level instruction to a ISA specific instruction, |
| 101 |
// where we eagerly try to merge multiple instructions into single operation etc. Such merging cannot be done |
| 102 |
// if these instruction have different InstructionGroupID since it will change the semantics of a program. |
| 103 |
// |
| 104 |
// See passDeadCodeElimination. |
| 105 |
type InstructionGroupID uint32 |
| 106 |
|
| 107 |
// Returns Value(s) produced by this instruction if any. |
| 108 |
// The `first` is the first return value, and `rest` is the rest of the values. |
| 109 |
func (i *Instruction) Returns() (first Value, rest []Value) { |
| 110 |
if i.IsBranching() { |
| 111 |
return ValueInvalid, nil |
| 112 |
} |
| 113 |
return i.rValue, i.rValues.View() |
| 114 |
} |
| 115 |
|
| 116 |
// Return returns a Value(s) produced by this instruction if any. |
| 117 |
// If there's multiple return values, only the first one is returned. |
| 118 |
func (i *Instruction) Return() (first Value) { |
| 119 |
return i.rValue |
| 120 |
} |
| 121 |
|
| 122 |
// Args returns the arguments to this instruction. |
| 123 |
func (i *Instruction) Args() (v1, v2, v3 Value, vs []Value) { |
| 124 |
return i.v, i.v2, i.v3, i.vs.View() |
| 125 |
} |
| 126 |
|
| 127 |
// Arg returns the first argument to this instruction. |
| 128 |
func (i *Instruction) Arg() Value { |
| 129 |
return i.v |
| 130 |
} |
| 131 |
|
| 132 |
// Arg2 returns the first two arguments to this instruction. |
| 133 |
func (i *Instruction) Arg2() (Value, Value) { |
| 134 |
return i.v, i.v2 |
| 135 |
} |
| 136 |
|
| 137 |
// ArgWithLane returns the first argument to this instruction, and the lane type. |
| 138 |
func (i *Instruction) ArgWithLane() (Value, VecLane) { |
| 139 |
return i.v, VecLane(i.u1) |
| 140 |
} |
| 141 |
|
| 142 |
// Arg2WithLane returns the first two arguments to this instruction, and the lane type. |
| 143 |
func (i *Instruction) Arg2WithLane() (Value, Value, VecLane) { |
| 144 |
return i.v, i.v2, VecLane(i.u1) |
| 145 |
} |
| 146 |
|
| 147 |
// ShuffleData returns the first two arguments to this instruction and 2 uint64s `lo`, `hi`. |
| 148 |
// |
| 149 |
// Note: Each uint64 encodes a sequence of 8 bytes where each byte encodes a VecLane, |
| 150 |
// so that the 128bit integer `hi<<64|lo` packs a slice `[16]VecLane`, |
| 151 |
// where `lane[0]` is the least significant byte, and `lane[n]` is shifted to offset `n*8`. |
| 152 |
func (i *Instruction) ShuffleData() (v Value, v2 Value, lo uint64, hi uint64) { |
| 153 |
return i.v, i.v2, i.u1, i.u2 |
| 154 |
} |
| 155 |
|
| 156 |
// Arg3 returns the first three arguments to this instruction. |
| 157 |
func (i *Instruction) Arg3() (Value, Value, Value) { |
| 158 |
return i.v, i.v2, i.v3 |
| 159 |
} |
| 160 |
|
| 161 |
// Next returns the next instruction laid out next to itself. |
| 162 |
func (i *Instruction) Next() *Instruction { |
| 163 |
return i.next |
| 164 |
} |
| 165 |
|
| 166 |
// Prev returns the previous instruction laid out prior to itself. |
| 167 |
func (i *Instruction) Prev() *Instruction { |
| 168 |
return i.prev |
| 169 |
} |
| 170 |
|
| 171 |
// IsBranching returns true if this instruction is a branching instruction. |
| 172 |
func (i *Instruction) IsBranching() bool { |
| 173 |
switch i.opcode { |
| 174 |
case OpcodeJump, OpcodeBrz, OpcodeBrnz, OpcodeBrTable: |
| 175 |
return true |
| 176 |
default: |
| 177 |
return false |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
// TODO: complete opcode comments. |
| 182 |
const ( |
| 183 |
OpcodeInvalid Opcode = iota |
| 184 |
|
| 185 |
// OpcodeUndefined is a placeholder for undefined opcode. This can be used for debugging to intentionally |
| 186 |
// cause a crash at certain point. |
| 187 |
OpcodeUndefined |
| 188 |
|
| 189 |
// OpcodeJump takes the list of args to the `block` and unconditionally jumps to it. |
| 190 |
OpcodeJump |
| 191 |
|
| 192 |
// OpcodeBrz branches into `blk` with `args` if the value `c` equals zero: `Brz c, blk, args`. |
| 193 |
OpcodeBrz |
| 194 |
|
| 195 |
// OpcodeBrnz branches into `blk` with `args` if the value `c` is not zero: `Brnz c, blk, args`. |
| 196 |
OpcodeBrnz |
| 197 |
|
| 198 |
// OpcodeBrTable takes the index value `index`, and branches into `labelX`. If the `index` is out of range, |
| 199 |
// it branches into the last labelN: `BrTable index, [label1, label2, ... labelN]`. |
| 200 |
OpcodeBrTable |
| 201 |
|
| 202 |
// OpcodeExitWithCode exit the execution immediately. |
| 203 |
OpcodeExitWithCode |
| 204 |
|
| 205 |
// OpcodeExitIfTrueWithCode exits the execution immediately if the value `c` is not zero. |
| 206 |
OpcodeExitIfTrueWithCode |
| 207 |
|
| 208 |
// OpcodeReturn returns from the function: `return rvalues`. |
| 209 |
OpcodeReturn |
| 210 |
|
| 211 |
// OpcodeCall calls a function specified by the symbol FN with arguments `args`: `returnvals = Call FN, args...` |
| 212 |
// This is a "near" call, which means the call target is known at compile time, and the target is relatively close |
| 213 |
// to this function. If the target cannot be reached by near call, the backend fails to compile. |
| 214 |
OpcodeCall |
| 215 |
|
| 216 |
// OpcodeCallIndirect calls a function specified by `callee` which is a function address: `returnvals = call_indirect SIG, callee, args`. |
| 217 |
// Note that this is different from call_indirect in Wasm, which also does type checking, etc. |
| 218 |
OpcodeCallIndirect |
| 219 |
|
| 220 |
// OpcodeSplat performs a vector splat operation: `v = Splat.lane x`. |
| 221 |
OpcodeSplat |
| 222 |
|
| 223 |
// OpcodeSwizzle performs a vector swizzle operation: `v = Swizzle.lane x, y`. |
| 224 |
OpcodeSwizzle |
| 225 |
|
| 226 |
// OpcodeInsertlane inserts a lane value into a vector: `v = InsertLane x, y, Idx`. |
| 227 |
OpcodeInsertlane |
| 228 |
|
| 229 |
// OpcodeExtractlane extracts a lane value from a vector: `v = ExtractLane x, Idx`. |
| 230 |
OpcodeExtractlane |
| 231 |
|
| 232 |
// OpcodeLoad loads a Type value from the [base + offset] address: `v = Load base, offset`. |
| 233 |
OpcodeLoad |
| 234 |
|
| 235 |
// OpcodeStore stores a Type value to the [base + offset] address: `Store v, base, offset`. |
| 236 |
OpcodeStore |
| 237 |
|
| 238 |
// OpcodeUload8 loads the 8-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload8 base, offset`. |
| 239 |
OpcodeUload8 |
| 240 |
|
| 241 |
// OpcodeSload8 loads the 8-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload8 base, offset`. |
| 242 |
OpcodeSload8 |
| 243 |
|
| 244 |
// OpcodeIstore8 stores the 8-bit value to the [base + offset] address, sign-extended to 64 bits: `Istore8 v, base, offset`. |
| 245 |
OpcodeIstore8 |
| 246 |
|
| 247 |
// OpcodeUload16 loads the 16-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload16 base, offset`. |
| 248 |
OpcodeUload16 |
| 249 |
|
| 250 |
// OpcodeSload16 loads the 16-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload16 base, offset`. |
| 251 |
OpcodeSload16 |
| 252 |
|
| 253 |
// OpcodeIstore16 stores the 16-bit value to the [base + offset] address, zero-extended to 64 bits: `Istore16 v, base, offset`. |
| 254 |
OpcodeIstore16 |
| 255 |
|
| 256 |
// OpcodeUload32 loads the 32-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload32 base, offset`. |
| 257 |
OpcodeUload32 |
| 258 |
|
| 259 |
// OpcodeSload32 loads the 32-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload32 base, offset`. |
| 260 |
OpcodeSload32 |
| 261 |
|
| 262 |
// OpcodeIstore32 stores the 32-bit value to the [base + offset] address, zero-extended to 64 bits: `Istore16 v, base, offset`. |
| 263 |
OpcodeIstore32 |
| 264 |
|
| 265 |
// OpcodeLoadSplat represents a load that replicates the loaded value to all lanes `v = LoadSplat.lane p, Offset`. |
| 266 |
OpcodeLoadSplat |
| 267 |
|
| 268 |
// OpcodeVZeroExtLoad loads a scalar single/double precision floating point value from the [p + Offset] address, |
| 269 |
// and zero-extend it to the V128 value: `v = VExtLoad p, Offset`. |
| 270 |
OpcodeVZeroExtLoad |
| 271 |
|
| 272 |
// OpcodeIconst represents the integer const. |
| 273 |
OpcodeIconst |
| 274 |
|
| 275 |
// OpcodeF32const represents the single-precision const. |
| 276 |
OpcodeF32const |
| 277 |
|
| 278 |
// OpcodeF64const represents the double-precision const. |
| 279 |
OpcodeF64const |
| 280 |
|
| 281 |
// OpcodeVconst represents the 128bit vector const. |
| 282 |
OpcodeVconst |
| 283 |
|
| 284 |
// OpcodeVbor computes binary or between two 128bit vectors: `v = bor x, y`. |
| 285 |
OpcodeVbor |
| 286 |
|
| 287 |
// OpcodeVbxor computes binary xor between two 128bit vectors: `v = bxor x, y`. |
| 288 |
OpcodeVbxor |
| 289 |
|
| 290 |
// OpcodeVband computes binary and between two 128bit vectors: `v = band x, y`. |
| 291 |
OpcodeVband |
| 292 |
|
| 293 |
// OpcodeVbandnot computes binary and-not between two 128bit vectors: `v = bandnot x, y`. |
| 294 |
OpcodeVbandnot |
| 295 |
|
| 296 |
// OpcodeVbnot negates a 128bit vector: `v = bnot x`. |
| 297 |
OpcodeVbnot |
| 298 |
|
| 299 |
// OpcodeVbitselect uses the bits in the control mask c to select the corresponding bit from x when 1 |
| 300 |
// and y when 0: `v = bitselect c, x, y`. |
| 301 |
OpcodeVbitselect |
| 302 |
|
| 303 |
// OpcodeShuffle shuffles two vectors using the given 128-bit immediate: `v = shuffle imm, x, y`. |
| 304 |
// For each byte in the immediate, a value i in [0, 15] selects the i-th byte in vector x; |
| 305 |
// i in [16, 31] selects the (i-16)-th byte in vector y. |
| 306 |
OpcodeShuffle |
| 307 |
|
| 308 |
// OpcodeSelect chooses between two values based on a condition `c`: `v = Select c, x, y`. |
| 309 |
OpcodeSelect |
| 310 |
|
| 311 |
// OpcodeVanyTrue performs a any true operation: `s = VanyTrue a`. |
| 312 |
OpcodeVanyTrue |
| 313 |
|
| 314 |
// OpcodeVallTrue performs a lane-wise all true operation: `s = VallTrue.lane a`. |
| 315 |
OpcodeVallTrue |
| 316 |
|
| 317 |
// OpcodeVhighBits performs a lane-wise extract of the high bits: `v = VhighBits.lane a`. |
| 318 |
OpcodeVhighBits |
| 319 |
|
| 320 |
// OpcodeIcmp compares two integer values with the given condition: `v = icmp Cond, x, y`. |
| 321 |
OpcodeIcmp |
| 322 |
|
| 323 |
// OpcodeVIcmp compares two integer values with the given condition: `v = vicmp Cond, x, y` on vector. |
| 324 |
OpcodeVIcmp |
| 325 |
|
| 326 |
// OpcodeIcmpImm compares an integer value with the immediate value on the given condition: `v = icmp_imm Cond, x, Y`. |
| 327 |
OpcodeIcmpImm |
| 328 |
|
| 329 |
// OpcodeIadd performs an integer addition: `v = Iadd x, y`. |
| 330 |
OpcodeIadd |
| 331 |
|
| 332 |
// OpcodeVIadd performs an integer addition: `v = VIadd.lane x, y` on vector. |
| 333 |
OpcodeVIadd |
| 334 |
|
| 335 |
// OpcodeVSaddSat performs a signed saturating vector addition: `v = VSaddSat.lane x, y` on vector. |
| 336 |
OpcodeVSaddSat |
| 337 |
|
| 338 |
// OpcodeVUaddSat performs an unsigned saturating vector addition: `v = VUaddSat.lane x, y` on vector. |
| 339 |
OpcodeVUaddSat |
| 340 |
|
| 341 |
// OpcodeIsub performs an integer subtraction: `v = Isub x, y`. |
| 342 |
OpcodeIsub |
| 343 |
|
| 344 |
// OpcodeVIsub performs an integer subtraction: `v = VIsub.lane x, y` on vector. |
| 345 |
OpcodeVIsub |
| 346 |
|
| 347 |
// OpcodeVSsubSat performs a signed saturating vector subtraction: `v = VSsubSat.lane x, y` on vector. |
| 348 |
OpcodeVSsubSat |
| 349 |
|
| 350 |
// OpcodeVUsubSat performs an unsigned saturating vector subtraction: `v = VUsubSat.lane x, y` on vector. |
| 351 |
OpcodeVUsubSat |
| 352 |
|
| 353 |
// OpcodeVImin performs a signed integer min: `v = VImin.lane x, y` on vector. |
| 354 |
OpcodeVImin |
| 355 |
|
| 356 |
// OpcodeVUmin performs an unsigned integer min: `v = VUmin.lane x, y` on vector. |
| 357 |
OpcodeVUmin |
| 358 |
|
| 359 |
// OpcodeVImax performs a signed integer max: `v = VImax.lane x, y` on vector. |
| 360 |
OpcodeVImax |
| 361 |
|
| 362 |
// OpcodeVUmax performs an unsigned integer max: `v = VUmax.lane x, y` on vector. |
| 363 |
OpcodeVUmax |
| 364 |
|
| 365 |
// OpcodeVAvgRound performs an unsigned integer avg, truncating to zero: `v = VAvgRound.lane x, y` on vector. |
| 366 |
OpcodeVAvgRound |
| 367 |
|
| 368 |
// OpcodeVImul performs an integer multiplication: `v = VImul.lane x, y` on vector. |
| 369 |
OpcodeVImul |
| 370 |
|
| 371 |
// OpcodeVIneg negates the given integer vector value: `v = VIneg x`. |
| 372 |
OpcodeVIneg |
| 373 |
|
| 374 |
// OpcodeVIpopcnt counts the number of 1-bits in the given vector: `v = VIpopcnt x`. |
| 375 |
OpcodeVIpopcnt |
| 376 |
|
| 377 |
// OpcodeVIabs returns the absolute value for the given vector value: `v = VIabs.lane x`. |
| 378 |
OpcodeVIabs |
| 379 |
|
| 380 |
// OpcodeVIshl shifts x left by (y mod lane-width): `v = VIshl.lane x, y` on vector. |
| 381 |
OpcodeVIshl |
| 382 |
|
| 383 |
// OpcodeVUshr shifts x right by (y mod lane-width), unsigned: `v = VUshr.lane x, y` on vector. |
| 384 |
OpcodeVUshr |
| 385 |
|
| 386 |
// OpcodeVSshr shifts x right by (y mod lane-width), signed: `v = VSshr.lane x, y` on vector. |
| 387 |
OpcodeVSshr |
| 388 |
|
| 389 |
// OpcodeVFabs takes the absolute value of a floating point value: `v = VFabs.lane x on vector. |
| 390 |
OpcodeVFabs |
| 391 |
|
| 392 |
// OpcodeVFmax takes the maximum of two floating point values: `v = VFmax.lane x, y on vector. |
| 393 |
OpcodeVFmax |
| 394 |
|
| 395 |
// OpcodeVFmin takes the minimum of two floating point values: `v = VFmin.lane x, y on vector. |
| 396 |
OpcodeVFmin |
| 397 |
|
| 398 |
// OpcodeVFneg negates the given floating point vector value: `v = VFneg x`. |
| 399 |
OpcodeVFneg |
| 400 |
|
| 401 |
// OpcodeVFadd performs a floating point addition: `v = VFadd.lane x, y` on vector. |
| 402 |
OpcodeVFadd |
| 403 |
|
| 404 |
// OpcodeVFsub performs a floating point subtraction: `v = VFsub.lane x, y` on vector. |
| 405 |
OpcodeVFsub |
| 406 |
|
| 407 |
// OpcodeVFmul performs a floating point multiplication: `v = VFmul.lane x, y` on vector. |
| 408 |
OpcodeVFmul |
| 409 |
|
| 410 |
// OpcodeVFdiv performs a floating point division: `v = VFdiv.lane x, y` on vector. |
| 411 |
OpcodeVFdiv |
| 412 |
|
| 413 |
// OpcodeVFcmp compares two float values with the given condition: `v = VFcmp.lane Cond, x, y` on float. |
| 414 |
OpcodeVFcmp |
| 415 |
|
| 416 |
// OpcodeVCeil takes the ceiling of the given floating point value: `v = ceil.lane x` on vector. |
| 417 |
OpcodeVCeil |
| 418 |
|
| 419 |
// OpcodeVFloor takes the floor of the given floating point value: `v = floor.lane x` on vector. |
| 420 |
OpcodeVFloor |
| 421 |
|
| 422 |
// OpcodeVTrunc takes the truncation of the given floating point value: `v = trunc.lane x` on vector. |
| 423 |
OpcodeVTrunc |
| 424 |
|
| 425 |
// OpcodeVNearest takes the nearest integer of the given floating point value: `v = nearest.lane x` on vector. |
| 426 |
OpcodeVNearest |
| 427 |
|
| 428 |
// OpcodeVMaxPseudo computes the lane-wise maximum value `v = VMaxPseudo.lane x, y` on vector defined as `x < y ? x : y`. |
| 429 |
OpcodeVMaxPseudo |
| 430 |
|
| 431 |
// OpcodeVMinPseudo computes the lane-wise minimum value `v = VMinPseudo.lane x, y` on vector defined as `y < x ? x : y`. |
| 432 |
OpcodeVMinPseudo |
| 433 |
|
| 434 |
// OpcodeVSqrt takes the minimum of two floating point values: `v = VFmin.lane x, y` on vector. |
| 435 |
OpcodeVSqrt |
| 436 |
|
| 437 |
// OpcodeVFcvtToUintSat converts a floating point value to an unsigned integer: `v = FcvtToUintSat.lane x` on vector. |
| 438 |
OpcodeVFcvtToUintSat |
| 439 |
|
| 440 |
// OpcodeVFcvtToSintSat converts a floating point value to a signed integer: `v = VFcvtToSintSat.lane x` on vector. |
| 441 |
OpcodeVFcvtToSintSat |
| 442 |
|
| 443 |
// OpcodeVFcvtFromUint converts a floating point value from an unsigned integer: `v = FcvtFromUint.lane x` on vector. |
| 444 |
// x is always a 32-bit integer lane, and the result is either a 32-bit or 64-bit floating point-sized vector. |
| 445 |
OpcodeVFcvtFromUint |
| 446 |
|
| 447 |
// OpcodeVFcvtFromSint converts a floating point value from a signed integer: `v = VFcvtFromSint.lane x` on vector. |
| 448 |
// x is always a 32-bit integer lane, and the result is either a 32-bit or 64-bit floating point-sized vector. |
| 449 |
OpcodeVFcvtFromSint |
| 450 |
|
| 451 |
// OpcodeImul performs an integer multiplication: `v = Imul x, y`. |
| 452 |
OpcodeImul |
| 453 |
|
| 454 |
// OpcodeUdiv performs the unsigned integer division `v = Udiv x, y`. |
| 455 |
OpcodeUdiv |
| 456 |
|
| 457 |
// OpcodeSdiv performs the signed integer division `v = Sdiv x, y`. |
| 458 |
OpcodeSdiv |
| 459 |
|
| 460 |
// OpcodeUrem computes the remainder of the unsigned integer division `v = Urem x, y`. |
| 461 |
OpcodeUrem |
| 462 |
|
| 463 |
// OpcodeSrem computes the remainder of the signed integer division `v = Srem x, y`. |
| 464 |
OpcodeSrem |
| 465 |
|
| 466 |
// OpcodeBand performs a binary and: `v = Band x, y`. |
| 467 |
OpcodeBand |
| 468 |
|
| 469 |
// OpcodeBor performs a binary or: `v = Bor x, y`. |
| 470 |
OpcodeBor |
| 471 |
|
| 472 |
// OpcodeBxor performs a binary xor: `v = Bxor x, y`. |
| 473 |
OpcodeBxor |
| 474 |
|
| 475 |
// OpcodeBnot performs a binary not: `v = Bnot x`. |
| 476 |
OpcodeBnot |
| 477 |
|
| 478 |
// OpcodeRotl rotates the given integer value to the left: `v = Rotl x, y`. |
| 479 |
OpcodeRotl |
| 480 |
|
| 481 |
// OpcodeRotr rotates the given integer value to the right: `v = Rotr x, y`. |
| 482 |
OpcodeRotr |
| 483 |
|
| 484 |
// OpcodeIshl does logical shift left: `v = Ishl x, y`. |
| 485 |
OpcodeIshl |
| 486 |
|
| 487 |
// OpcodeUshr does logical shift right: `v = Ushr x, y`. |
| 488 |
OpcodeUshr |
| 489 |
|
| 490 |
// OpcodeSshr does arithmetic shift right: `v = Sshr x, y`. |
| 491 |
OpcodeSshr |
| 492 |
|
| 493 |
// OpcodeClz counts the number of leading zeros: `v = clz x`. |
| 494 |
OpcodeClz |
| 495 |
|
| 496 |
// OpcodeCtz counts the number of trailing zeros: `v = ctz x`. |
| 497 |
OpcodeCtz |
| 498 |
|
| 499 |
// OpcodePopcnt counts the number of 1-bits: `v = popcnt x`. |
| 500 |
OpcodePopcnt |
| 501 |
|
| 502 |
// OpcodeFcmp compares two floating point values: `v = fcmp Cond, x, y`. |
| 503 |
OpcodeFcmp |
| 504 |
|
| 505 |
// OpcodeFadd performs a floating point addition: / `v = Fadd x, y`. |
| 506 |
OpcodeFadd |
| 507 |
|
| 508 |
// OpcodeFsub performs a floating point subtraction: `v = Fsub x, y`. |
| 509 |
OpcodeFsub |
| 510 |
|
| 511 |
// OpcodeFmul performs a floating point multiplication: `v = Fmul x, y`. |
| 512 |
OpcodeFmul |
| 513 |
|
| 514 |
// OpcodeSqmulRoundSat performs a lane-wise saturating rounding multiplication |
| 515 |
// in Q15 format: `v = SqmulRoundSat.lane x,y` on vector. |
| 516 |
OpcodeSqmulRoundSat |
| 517 |
|
| 518 |
// OpcodeFdiv performs a floating point division: `v = Fdiv x, y`. |
| 519 |
OpcodeFdiv |
| 520 |
|
| 521 |
// OpcodeSqrt takes the square root of the given floating point value: `v = sqrt x`. |
| 522 |
OpcodeSqrt |
| 523 |
|
| 524 |
// OpcodeFneg negates the given floating point value: `v = Fneg x`. |
| 525 |
OpcodeFneg |
| 526 |
|
| 527 |
// OpcodeFabs takes the absolute value of the given floating point value: `v = fabs x`. |
| 528 |
OpcodeFabs |
| 529 |
|
| 530 |
// OpcodeFcopysign copies the sign of the second floating point value to the first floating point value: |
| 531 |
// `v = Fcopysign x, y`. |
| 532 |
OpcodeFcopysign |
| 533 |
|
| 534 |
// OpcodeFmin takes the minimum of two floating point values: `v = fmin x, y`. |
| 535 |
OpcodeFmin |
| 536 |
|
| 537 |
// OpcodeFmax takes the maximum of two floating point values: `v = fmax x, y`. |
| 538 |
OpcodeFmax |
| 539 |
|
| 540 |
// OpcodeCeil takes the ceiling of the given floating point value: `v = ceil x`. |
| 541 |
OpcodeCeil |
| 542 |
|
| 543 |
// OpcodeFloor takes the floor of the given floating point value: `v = floor x`. |
| 544 |
OpcodeFloor |
| 545 |
|
| 546 |
// OpcodeTrunc takes the truncation of the given floating point value: `v = trunc x`. |
| 547 |
OpcodeTrunc |
| 548 |
|
| 549 |
// OpcodeNearest takes the nearest integer of the given floating point value: `v = nearest x`. |
| 550 |
OpcodeNearest |
| 551 |
|
| 552 |
// OpcodeBitcast is a bitcast operation: `v = bitcast x`. |
| 553 |
OpcodeBitcast |
| 554 |
|
| 555 |
// OpcodeIreduce narrow the given integer: `v = Ireduce x`. |
| 556 |
OpcodeIreduce |
| 557 |
|
| 558 |
// OpcodeSnarrow converts two input vectors x, y into a smaller lane vector by narrowing each lane, signed `v = Snarrow.lane x, y`. |
| 559 |
OpcodeSnarrow |
| 560 |
|
| 561 |
// OpcodeUnarrow converts two input vectors x, y into a smaller lane vector by narrowing each lane, unsigned `v = Unarrow.lane x, y`. |
| 562 |
OpcodeUnarrow |
| 563 |
|
| 564 |
// OpcodeSwidenLow converts low half of the smaller lane vector to a larger lane vector, sign extended: `v = SwidenLow.lane x`. |
| 565 |
OpcodeSwidenLow |
| 566 |
|
| 567 |
// OpcodeSwidenHigh converts high half of the smaller lane vector to a larger lane vector, sign extended: `v = SwidenHigh.lane x`. |
| 568 |
OpcodeSwidenHigh |
| 569 |
|
| 570 |
// OpcodeUwidenLow converts low half of the smaller lane vector to a larger lane vector, zero (unsigned) extended: `v = UwidenLow.lane x`. |
| 571 |
OpcodeUwidenLow |
| 572 |
|
| 573 |
// OpcodeUwidenHigh converts high half of the smaller lane vector to a larger lane vector, zero (unsigned) extended: `v = UwidenHigh.lane x`. |
| 574 |
OpcodeUwidenHigh |
| 575 |
|
| 576 |
// OpcodeExtIaddPairwise is a lane-wise integer extended pairwise addition producing extended results (twice wider results than the inputs): `v = extiadd_pairwise x, y` on vector. |
| 577 |
OpcodeExtIaddPairwise |
| 578 |
|
| 579 |
// OpcodeWideningPairwiseDotProductS is a lane-wise widening pairwise dot product with signed saturation: `v = WideningPairwiseDotProductS x, y` on vector. |
| 580 |
// Currently, the only lane is i16, and the result is i32. |
| 581 |
OpcodeWideningPairwiseDotProductS |
| 582 |
|
| 583 |
// OpcodeUExtend zero-extends the given integer: `v = UExtend x, from->to`. |
| 584 |
OpcodeUExtend |
| 585 |
|
| 586 |
// OpcodeSExtend sign-extends the given integer: `v = SExtend x, from->to`. |
| 587 |
OpcodeSExtend |
| 588 |
|
| 589 |
// OpcodeFpromote promotes the given floating point value: `v = Fpromote x`. |
| 590 |
OpcodeFpromote |
| 591 |
|
| 592 |
// OpcodeFvpromoteLow converts the two lower single-precision floating point lanes |
| 593 |
// to the two double-precision lanes of the result: `v = FvpromoteLow.lane x` on vector. |
| 594 |
OpcodeFvpromoteLow |
| 595 |
|
| 596 |
// OpcodeFdemote demotes the given float point value: `v = Fdemote x`. |
| 597 |
OpcodeFdemote |
| 598 |
|
| 599 |
// OpcodeFvdemote converts the two double-precision floating point lanes |
| 600 |
// to two lower single-precision lanes of the result `v = Fvdemote.lane x`. |
| 601 |
OpcodeFvdemote |
| 602 |
|
| 603 |
// OpcodeFcvtToUint converts a floating point value to an unsigned integer: `v = FcvtToUint x`. |
| 604 |
OpcodeFcvtToUint |
| 605 |
|
| 606 |
// OpcodeFcvtToSint converts a floating point value to a signed integer: `v = FcvtToSint x`. |
| 607 |
OpcodeFcvtToSint |
| 608 |
|
| 609 |
// OpcodeFcvtToUintSat converts a floating point value to an unsigned integer: `v = FcvtToUintSat x` which saturates on overflow. |
| 610 |
OpcodeFcvtToUintSat |
| 611 |
|
| 612 |
// OpcodeFcvtToSintSat converts a floating point value to a signed integer: `v = FcvtToSintSat x` which saturates on overflow. |
| 613 |
OpcodeFcvtToSintSat |
| 614 |
|
| 615 |
// OpcodeFcvtFromUint converts an unsigned integer to a floating point value: `v = FcvtFromUint x`. |
| 616 |
OpcodeFcvtFromUint |
| 617 |
|
| 618 |
// OpcodeFcvtFromSint converts a signed integer to a floating point value: `v = FcvtFromSint x`. |
| 619 |
OpcodeFcvtFromSint |
| 620 |
|
| 621 |
// OpcodeAtomicRmw is atomic read-modify-write operation: `v = atomic_rmw op, p, offset, value`. |
| 622 |
OpcodeAtomicRmw |
| 623 |
|
| 624 |
// OpcodeAtomicCas is atomic compare-and-swap operation. |
| 625 |
OpcodeAtomicCas |
| 626 |
|
| 627 |
// OpcodeAtomicLoad is atomic load operation. |
| 628 |
OpcodeAtomicLoad |
| 629 |
|
| 630 |
// OpcodeAtomicStore is atomic store operation. |
| 631 |
OpcodeAtomicStore |
| 632 |
|
| 633 |
// OpcodeFence is a memory fence operation. |
| 634 |
OpcodeFence |
| 635 |
|
| 636 |
// OpcodeTailCallReturnCall is the equivalent of OpcodeCall (a "near" call) |
| 637 |
// for tail calls. Semantically, it combines Call + Return into a single operation. |
| 638 |
OpcodeTailCallReturnCall |
| 639 |
|
| 640 |
// OpcodeTailCallReturnCallIndirect is the equivalent of OpcodeCallIndirect (a call to a function address) |
| 641 |
// for tail calls. Semantically, it combines CallIndirect + Return into a single operation. |
| 642 |
OpcodeTailCallReturnCallIndirect |
| 643 |
|
| 644 |
// opcodeEnd marks the end of the opcode list. |
| 645 |
opcodeEnd |
| 646 |
) |
| 647 |
|
| 648 |
// AtomicRmwOp represents the atomic read-modify-write operation. |
| 649 |
type AtomicRmwOp byte |
| 650 |
|
| 651 |
const ( |
| 652 |
// AtomicRmwOpAdd is an atomic add operation. |
| 653 |
AtomicRmwOpAdd AtomicRmwOp = iota |
| 654 |
// AtomicRmwOpSub is an atomic sub operation. |
| 655 |
AtomicRmwOpSub |
| 656 |
// AtomicRmwOpAnd is an atomic and operation. |
| 657 |
AtomicRmwOpAnd |
| 658 |
// AtomicRmwOpOr is an atomic or operation. |
| 659 |
AtomicRmwOpOr |
| 660 |
// AtomicRmwOpXor is an atomic xor operation. |
| 661 |
AtomicRmwOpXor |
| 662 |
// AtomicRmwOpXchg is an atomic swap operation. |
| 663 |
AtomicRmwOpXchg |
| 664 |
) |
| 665 |
|
| 666 |
// String implements the fmt.Stringer. |
| 667 |
func (op AtomicRmwOp) String() string { |
| 668 |
switch op { |
| 669 |
case AtomicRmwOpAdd: |
| 670 |
return "add" |
| 671 |
case AtomicRmwOpSub: |
| 672 |
return "sub" |
| 673 |
case AtomicRmwOpAnd: |
| 674 |
return "and" |
| 675 |
case AtomicRmwOpOr: |
| 676 |
return "or" |
| 677 |
case AtomicRmwOpXor: |
| 678 |
return "xor" |
| 679 |
case AtomicRmwOpXchg: |
| 680 |
return "xchg" |
| 681 |
} |
| 682 |
panic(fmt.Sprintf("unknown AtomicRmwOp: %d", op)) |
| 683 |
} |
| 684 |
|
| 685 |
// returnTypesFn provides the info to determine the type of instruction. |
| 686 |
// t1 is the type of the first result, ts are the types of the remaining results. |
| 687 |
type returnTypesFn func(b *builder, instr *Instruction) (t1 Type, ts []Type) |
| 688 |
|
| 689 |
var ( |
| 690 |
returnTypesFnNoReturns returnTypesFn = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return typeInvalid, nil } |
| 691 |
returnTypesFnSingle = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return instr.typ, nil } |
| 692 |
returnTypesFnI32 = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return TypeI32, nil } |
| 693 |
returnTypesFnF32 = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return TypeF32, nil } |
| 694 |
returnTypesFnF64 = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return TypeF64, nil } |
| 695 |
returnTypesFnV128 = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { return TypeV128, nil } |
| 696 |
returnTypesFnCallIndirect = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { |
| 697 |
sigID := SignatureID(instr.u1) |
| 698 |
sig, ok := b.signatures[sigID] |
| 699 |
if !ok { |
| 700 |
panic("BUG") |
| 701 |
} |
| 702 |
switch len(sig.Results) { |
| 703 |
case 0: |
| 704 |
t1 = typeInvalid |
| 705 |
case 1: |
| 706 |
t1 = sig.Results[0] |
| 707 |
default: |
| 708 |
t1, ts = sig.Results[0], sig.Results[1:] |
| 709 |
} |
| 710 |
return |
| 711 |
} |
| 712 |
returnTypesFnCall = func(b *builder, instr *Instruction) (t1 Type, ts []Type) { |
| 713 |
sigID := SignatureID(instr.u2) |
| 714 |
sig, ok := b.signatures[sigID] |
| 715 |
if !ok { |
| 716 |
panic("BUG") |
| 717 |
} |
| 718 |
switch len(sig.Results) { |
| 719 |
case 0: |
| 720 |
t1 = typeInvalid |
| 721 |
case 1: |
| 722 |
t1 = sig.Results[0] |
| 723 |
default: |
| 724 |
t1, ts = sig.Results[0], sig.Results[1:] |
| 725 |
} |
| 726 |
return |
| 727 |
} |
| 728 |
) |
| 729 |
|
| 730 |
// sideEffect provides the info to determine if an instruction has side effects which |
| 731 |
// is used to determine if it can be optimized out, interchanged with others, etc. |
| 732 |
type sideEffect byte |
| 733 |
|
| 734 |
const ( |
| 735 |
sideEffectUnknown sideEffect = iota |
| 736 |
// sideEffectStrict represents an instruction with side effects, and should be always alive plus cannot be reordered. |
| 737 |
sideEffectStrict |
| 738 |
// sideEffectTraps represents an instruction that can trap, and should be always alive but can be reordered within the group. |
| 739 |
sideEffectTraps |
| 740 |
// sideEffectNone represents an instruction without side effects, and can be eliminated if the result is not used, plus can be reordered within the group. |
| 741 |
sideEffectNone |
| 742 |
) |
| 743 |
|
| 744 |
// instructionSideEffects provides the info to determine if an instruction has side effects. |
| 745 |
// Instructions with side effects must not be eliminated regardless whether the result is used or not. |
| 746 |
var instructionSideEffects = [opcodeEnd]sideEffect{ |
| 747 |
OpcodeUndefined: sideEffectStrict, |
| 748 |
OpcodeJump: sideEffectStrict, |
| 749 |
OpcodeIconst: sideEffectNone, |
| 750 |
OpcodeCall: sideEffectStrict, |
| 751 |
OpcodeCallIndirect: sideEffectStrict, |
| 752 |
OpcodeIadd: sideEffectNone, |
| 753 |
OpcodeImul: sideEffectNone, |
| 754 |
OpcodeIsub: sideEffectNone, |
| 755 |
OpcodeIcmp: sideEffectNone, |
| 756 |
OpcodeExtractlane: sideEffectNone, |
| 757 |
OpcodeInsertlane: sideEffectNone, |
| 758 |
OpcodeBand: sideEffectNone, |
| 759 |
OpcodeBor: sideEffectNone, |
| 760 |
OpcodeBxor: sideEffectNone, |
| 761 |
OpcodeRotl: sideEffectNone, |
| 762 |
OpcodeRotr: sideEffectNone, |
| 763 |
OpcodeFcmp: sideEffectNone, |
| 764 |
OpcodeFadd: sideEffectNone, |
| 765 |
OpcodeClz: sideEffectNone, |
| 766 |
OpcodeCtz: sideEffectNone, |
| 767 |
OpcodePopcnt: sideEffectNone, |
| 768 |
OpcodeLoad: sideEffectNone, |
| 769 |
OpcodeLoadSplat: sideEffectNone, |
| 770 |
OpcodeUload8: sideEffectNone, |
| 771 |
OpcodeUload16: sideEffectNone, |
| 772 |
OpcodeUload32: sideEffectNone, |
| 773 |
OpcodeSload8: sideEffectNone, |
| 774 |
OpcodeSload16: sideEffectNone, |
| 775 |
OpcodeSload32: sideEffectNone, |
| 776 |
OpcodeSExtend: sideEffectNone, |
| 777 |
OpcodeUExtend: sideEffectNone, |
| 778 |
OpcodeSwidenLow: sideEffectNone, |
| 779 |
OpcodeUwidenLow: sideEffectNone, |
| 780 |
OpcodeSwidenHigh: sideEffectNone, |
| 781 |
OpcodeUwidenHigh: sideEffectNone, |
| 782 |
OpcodeSnarrow: sideEffectNone, |
| 783 |
OpcodeUnarrow: sideEffectNone, |
| 784 |
OpcodeSwizzle: sideEffectNone, |
| 785 |
OpcodeShuffle: sideEffectNone, |
| 786 |
OpcodeSplat: sideEffectNone, |
| 787 |
OpcodeFsub: sideEffectNone, |
| 788 |
OpcodeF32const: sideEffectNone, |
| 789 |
OpcodeF64const: sideEffectNone, |
| 790 |
OpcodeIshl: sideEffectNone, |
| 791 |
OpcodeSshr: sideEffectNone, |
| 792 |
OpcodeUshr: sideEffectNone, |
| 793 |
OpcodeStore: sideEffectStrict, |
| 794 |
OpcodeIstore8: sideEffectStrict, |
| 795 |
OpcodeIstore16: sideEffectStrict, |
| 796 |
OpcodeIstore32: sideEffectStrict, |
| 797 |
OpcodeExitWithCode: sideEffectStrict, |
| 798 |
OpcodeExitIfTrueWithCode: sideEffectStrict, |
| 799 |
OpcodeReturn: sideEffectStrict, |
| 800 |
OpcodeBrz: sideEffectStrict, |
| 801 |
OpcodeBrnz: sideEffectStrict, |
| 802 |
OpcodeBrTable: sideEffectStrict, |
| 803 |
OpcodeFdiv: sideEffectNone, |
| 804 |
OpcodeFmul: sideEffectNone, |
| 805 |
OpcodeFmax: sideEffectNone, |
| 806 |
OpcodeSqmulRoundSat: sideEffectNone, |
| 807 |
OpcodeSelect: sideEffectNone, |
| 808 |
OpcodeFmin: sideEffectNone, |
| 809 |
OpcodeFneg: sideEffectNone, |
| 810 |
OpcodeFcvtToSint: sideEffectTraps, |
| 811 |
OpcodeFcvtToUint: sideEffectTraps, |
| 812 |
OpcodeFcvtFromSint: sideEffectNone, |
| 813 |
OpcodeFcvtFromUint: sideEffectNone, |
| 814 |
OpcodeFcvtToSintSat: sideEffectNone, |
| 815 |
OpcodeFcvtToUintSat: sideEffectNone, |
| 816 |
OpcodeVFcvtFromUint: sideEffectNone, |
| 817 |
OpcodeVFcvtFromSint: sideEffectNone, |
| 818 |
OpcodeFdemote: sideEffectNone, |
| 819 |
OpcodeFvpromoteLow: sideEffectNone, |
| 820 |
OpcodeFvdemote: sideEffectNone, |
| 821 |
OpcodeFpromote: sideEffectNone, |
| 822 |
OpcodeBitcast: sideEffectNone, |
| 823 |
OpcodeIreduce: sideEffectNone, |
| 824 |
OpcodeSqrt: sideEffectNone, |
| 825 |
OpcodeCeil: sideEffectNone, |
| 826 |
OpcodeFloor: sideEffectNone, |
| 827 |
OpcodeTrunc: sideEffectNone, |
| 828 |
OpcodeNearest: sideEffectNone, |
| 829 |
OpcodeSdiv: sideEffectTraps, |
| 830 |
OpcodeSrem: sideEffectTraps, |
| 831 |
OpcodeUdiv: sideEffectTraps, |
| 832 |
OpcodeUrem: sideEffectTraps, |
| 833 |
OpcodeFabs: sideEffectNone, |
| 834 |
OpcodeFcopysign: sideEffectNone, |
| 835 |
OpcodeExtIaddPairwise: sideEffectNone, |
| 836 |
OpcodeVconst: sideEffectNone, |
| 837 |
OpcodeVbor: sideEffectNone, |
| 838 |
OpcodeVbxor: sideEffectNone, |
| 839 |
OpcodeVband: sideEffectNone, |
| 840 |
OpcodeVbandnot: sideEffectNone, |
| 841 |
OpcodeVbnot: sideEffectNone, |
| 842 |
OpcodeVbitselect: sideEffectNone, |
| 843 |
OpcodeVanyTrue: sideEffectNone, |
| 844 |
OpcodeVallTrue: sideEffectNone, |
| 845 |
OpcodeVhighBits: sideEffectNone, |
| 846 |
OpcodeVIadd: sideEffectNone, |
| 847 |
OpcodeVSaddSat: sideEffectNone, |
| 848 |
OpcodeVUaddSat: sideEffectNone, |
| 849 |
OpcodeVIsub: sideEffectNone, |
| 850 |
OpcodeVSsubSat: sideEffectNone, |
| 851 |
OpcodeVUsubSat: sideEffectNone, |
| 852 |
OpcodeVIcmp: sideEffectNone, |
| 853 |
OpcodeVImin: sideEffectNone, |
| 854 |
OpcodeVUmin: sideEffectNone, |
| 855 |
OpcodeVImax: sideEffectNone, |
| 856 |
OpcodeVUmax: sideEffectNone, |
| 857 |
OpcodeVAvgRound: sideEffectNone, |
| 858 |
OpcodeVImul: sideEffectNone, |
| 859 |
OpcodeVIabs: sideEffectNone, |
| 860 |
OpcodeVIneg: sideEffectNone, |
| 861 |
OpcodeVIpopcnt: sideEffectNone, |
| 862 |
OpcodeVIshl: sideEffectNone, |
| 863 |
OpcodeVSshr: sideEffectNone, |
| 864 |
OpcodeVUshr: sideEffectNone, |
| 865 |
OpcodeVSqrt: sideEffectNone, |
| 866 |
OpcodeVFabs: sideEffectNone, |
| 867 |
OpcodeVFmin: sideEffectNone, |
| 868 |
OpcodeVFmax: sideEffectNone, |
| 869 |
OpcodeVFneg: sideEffectNone, |
| 870 |
OpcodeVFadd: sideEffectNone, |
| 871 |
OpcodeVFsub: sideEffectNone, |
| 872 |
OpcodeVFmul: sideEffectNone, |
| 873 |
OpcodeVFdiv: sideEffectNone, |
| 874 |
OpcodeVFcmp: sideEffectNone, |
| 875 |
OpcodeVCeil: sideEffectNone, |
| 876 |
OpcodeVFloor: sideEffectNone, |
| 877 |
OpcodeVTrunc: sideEffectNone, |
| 878 |
OpcodeVNearest: sideEffectNone, |
| 879 |
OpcodeVMaxPseudo: sideEffectNone, |
| 880 |
OpcodeVMinPseudo: sideEffectNone, |
| 881 |
OpcodeVFcvtToUintSat: sideEffectNone, |
| 882 |
OpcodeVFcvtToSintSat: sideEffectNone, |
| 883 |
OpcodeVZeroExtLoad: sideEffectNone, |
| 884 |
OpcodeAtomicRmw: sideEffectStrict, |
| 885 |
OpcodeAtomicLoad: sideEffectStrict, |
| 886 |
OpcodeAtomicStore: sideEffectStrict, |
| 887 |
OpcodeAtomicCas: sideEffectStrict, |
| 888 |
OpcodeFence: sideEffectStrict, |
| 889 |
OpcodeTailCallReturnCall: sideEffectStrict, |
| 890 |
OpcodeTailCallReturnCallIndirect: sideEffectStrict, |
| 891 |
OpcodeWideningPairwiseDotProductS: sideEffectNone, |
| 892 |
} |
| 893 |
|
| 894 |
// sideEffect returns true if this instruction has side effects. |
| 895 |
func (i *Instruction) sideEffect() sideEffect { |
| 896 |
if e := instructionSideEffects[i.opcode]; e == sideEffectUnknown { |
| 897 |
panic("BUG: side effect info not registered for " + i.opcode.String()) |
| 898 |
} else { |
| 899 |
return e |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
// instructionReturnTypes provides the function to determine the return types of an instruction. |
| 904 |
var instructionReturnTypes = [opcodeEnd]returnTypesFn{ |
| 905 |
OpcodeExtIaddPairwise: returnTypesFnV128, |
| 906 |
OpcodeVbor: returnTypesFnV128, |
| 907 |
OpcodeVbxor: returnTypesFnV128, |
| 908 |
OpcodeVband: returnTypesFnV128, |
| 909 |
OpcodeVbnot: returnTypesFnV128, |
| 910 |
OpcodeVbandnot: returnTypesFnV128, |
| 911 |
OpcodeVbitselect: returnTypesFnV128, |
| 912 |
OpcodeVanyTrue: returnTypesFnI32, |
| 913 |
OpcodeVallTrue: returnTypesFnI32, |
| 914 |
OpcodeVhighBits: returnTypesFnI32, |
| 915 |
OpcodeVIadd: returnTypesFnV128, |
| 916 |
OpcodeVSaddSat: returnTypesFnV128, |
| 917 |
OpcodeVUaddSat: returnTypesFnV128, |
| 918 |
OpcodeVIsub: returnTypesFnV128, |
| 919 |
OpcodeVSsubSat: returnTypesFnV128, |
| 920 |
OpcodeVUsubSat: returnTypesFnV128, |
| 921 |
OpcodeVIcmp: returnTypesFnV128, |
| 922 |
OpcodeVImin: returnTypesFnV128, |
| 923 |
OpcodeVUmin: returnTypesFnV128, |
| 924 |
OpcodeVImax: returnTypesFnV128, |
| 925 |
OpcodeVUmax: returnTypesFnV128, |
| 926 |
OpcodeVImul: returnTypesFnV128, |
| 927 |
OpcodeVAvgRound: returnTypesFnV128, |
| 928 |
OpcodeVIabs: returnTypesFnV128, |
| 929 |
OpcodeVIneg: returnTypesFnV128, |
| 930 |
OpcodeVIpopcnt: returnTypesFnV128, |
| 931 |
OpcodeVIshl: returnTypesFnV128, |
| 932 |
OpcodeVSshr: returnTypesFnV128, |
| 933 |
OpcodeVUshr: returnTypesFnV128, |
| 934 |
OpcodeExtractlane: returnTypesFnSingle, |
| 935 |
OpcodeInsertlane: returnTypesFnV128, |
| 936 |
OpcodeBand: returnTypesFnSingle, |
| 937 |
OpcodeFcopysign: returnTypesFnSingle, |
| 938 |
OpcodeBitcast: returnTypesFnSingle, |
| 939 |
OpcodeBor: returnTypesFnSingle, |
| 940 |
OpcodeBxor: returnTypesFnSingle, |
| 941 |
OpcodeRotl: returnTypesFnSingle, |
| 942 |
OpcodeRotr: returnTypesFnSingle, |
| 943 |
OpcodeIshl: returnTypesFnSingle, |
| 944 |
OpcodeSshr: returnTypesFnSingle, |
| 945 |
OpcodeSdiv: returnTypesFnSingle, |
| 946 |
OpcodeSrem: returnTypesFnSingle, |
| 947 |
OpcodeUdiv: returnTypesFnSingle, |
| 948 |
OpcodeUrem: returnTypesFnSingle, |
| 949 |
OpcodeUshr: returnTypesFnSingle, |
| 950 |
OpcodeJump: returnTypesFnNoReturns, |
| 951 |
OpcodeUndefined: returnTypesFnNoReturns, |
| 952 |
OpcodeIconst: returnTypesFnSingle, |
| 953 |
OpcodeSelect: returnTypesFnSingle, |
| 954 |
OpcodeSExtend: returnTypesFnSingle, |
| 955 |
OpcodeUExtend: returnTypesFnSingle, |
| 956 |
OpcodeSwidenLow: returnTypesFnV128, |
| 957 |
OpcodeUwidenLow: returnTypesFnV128, |
| 958 |
OpcodeSwidenHigh: returnTypesFnV128, |
| 959 |
OpcodeUwidenHigh: returnTypesFnV128, |
| 960 |
OpcodeSnarrow: returnTypesFnV128, |
| 961 |
OpcodeUnarrow: returnTypesFnV128, |
| 962 |
OpcodeSwizzle: returnTypesFnSingle, |
| 963 |
OpcodeShuffle: returnTypesFnV128, |
| 964 |
OpcodeSplat: returnTypesFnV128, |
| 965 |
OpcodeIreduce: returnTypesFnSingle, |
| 966 |
OpcodeFabs: returnTypesFnSingle, |
| 967 |
OpcodeSqrt: returnTypesFnSingle, |
| 968 |
OpcodeCeil: returnTypesFnSingle, |
| 969 |
OpcodeFloor: returnTypesFnSingle, |
| 970 |
OpcodeTrunc: returnTypesFnSingle, |
| 971 |
OpcodeNearest: returnTypesFnSingle, |
| 972 |
OpcodeCallIndirect: returnTypesFnCallIndirect, |
| 973 |
OpcodeCall: returnTypesFnCall, |
| 974 |
OpcodeLoad: returnTypesFnSingle, |
| 975 |
OpcodeVZeroExtLoad: returnTypesFnV128, |
| 976 |
OpcodeLoadSplat: returnTypesFnV128, |
| 977 |
OpcodeIadd: returnTypesFnSingle, |
| 978 |
OpcodeIsub: returnTypesFnSingle, |
| 979 |
OpcodeImul: returnTypesFnSingle, |
| 980 |
OpcodeIcmp: returnTypesFnI32, |
| 981 |
OpcodeFcmp: returnTypesFnI32, |
| 982 |
OpcodeFadd: returnTypesFnSingle, |
| 983 |
OpcodeFsub: returnTypesFnSingle, |
| 984 |
OpcodeFdiv: returnTypesFnSingle, |
| 985 |
OpcodeFmul: returnTypesFnSingle, |
| 986 |
OpcodeFmax: returnTypesFnSingle, |
| 987 |
OpcodeFmin: returnTypesFnSingle, |
| 988 |
OpcodeSqmulRoundSat: returnTypesFnV128, |
| 989 |
OpcodeF32const: returnTypesFnF32, |
| 990 |
OpcodeF64const: returnTypesFnF64, |
| 991 |
OpcodeClz: returnTypesFnSingle, |
| 992 |
OpcodeCtz: returnTypesFnSingle, |
| 993 |
OpcodePopcnt: returnTypesFnSingle, |
| 994 |
OpcodeStore: returnTypesFnNoReturns, |
| 995 |
OpcodeIstore8: returnTypesFnNoReturns, |
| 996 |
OpcodeIstore16: returnTypesFnNoReturns, |
| 997 |
OpcodeIstore32: returnTypesFnNoReturns, |
| 998 |
OpcodeExitWithCode: returnTypesFnNoReturns, |
| 999 |
OpcodeExitIfTrueWithCode: returnTypesFnNoReturns, |
| 1000 |
OpcodeReturn: returnTypesFnNoReturns, |
| 1001 |
OpcodeBrz: returnTypesFnNoReturns, |
| 1002 |
OpcodeBrnz: returnTypesFnNoReturns, |
| 1003 |
OpcodeBrTable: returnTypesFnNoReturns, |
| 1004 |
OpcodeUload8: returnTypesFnSingle, |
| 1005 |
OpcodeUload16: returnTypesFnSingle, |
| 1006 |
OpcodeUload32: returnTypesFnSingle, |
| 1007 |
OpcodeSload8: returnTypesFnSingle, |
| 1008 |
OpcodeSload16: returnTypesFnSingle, |
| 1009 |
OpcodeSload32: returnTypesFnSingle, |
| 1010 |
OpcodeFcvtToSint: returnTypesFnSingle, |
| 1011 |
OpcodeFcvtToUint: returnTypesFnSingle, |
| 1012 |
OpcodeFcvtFromSint: returnTypesFnSingle, |
| 1013 |
OpcodeFcvtFromUint: returnTypesFnSingle, |
| 1014 |
OpcodeFcvtToSintSat: returnTypesFnSingle, |
| 1015 |
OpcodeFcvtToUintSat: returnTypesFnSingle, |
| 1016 |
OpcodeVFcvtFromUint: returnTypesFnV128, |
| 1017 |
OpcodeVFcvtFromSint: returnTypesFnV128, |
| 1018 |
OpcodeFneg: returnTypesFnSingle, |
| 1019 |
OpcodeFdemote: returnTypesFnF32, |
| 1020 |
OpcodeFvdemote: returnTypesFnV128, |
| 1021 |
OpcodeFvpromoteLow: returnTypesFnV128, |
| 1022 |
OpcodeFpromote: returnTypesFnF64, |
| 1023 |
OpcodeVconst: returnTypesFnV128, |
| 1024 |
OpcodeVFabs: returnTypesFnV128, |
| 1025 |
OpcodeVSqrt: returnTypesFnV128, |
| 1026 |
OpcodeVFmax: returnTypesFnV128, |
| 1027 |
OpcodeVFmin: returnTypesFnV128, |
| 1028 |
OpcodeVFneg: returnTypesFnV128, |
| 1029 |
OpcodeVFadd: returnTypesFnV128, |
| 1030 |
OpcodeVFsub: returnTypesFnV128, |
| 1031 |
OpcodeVFmul: returnTypesFnV128, |
| 1032 |
OpcodeVFdiv: returnTypesFnV128, |
| 1033 |
OpcodeVFcmp: returnTypesFnV128, |
| 1034 |
OpcodeVCeil: returnTypesFnV128, |
| 1035 |
OpcodeVFloor: returnTypesFnV128, |
| 1036 |
OpcodeVTrunc: returnTypesFnV128, |
| 1037 |
OpcodeVNearest: returnTypesFnV128, |
| 1038 |
OpcodeVMaxPseudo: returnTypesFnV128, |
| 1039 |
OpcodeVMinPseudo: returnTypesFnV128, |
| 1040 |
OpcodeVFcvtToUintSat: returnTypesFnV128, |
| 1041 |
OpcodeVFcvtToSintSat: returnTypesFnV128, |
| 1042 |
OpcodeAtomicRmw: returnTypesFnSingle, |
| 1043 |
OpcodeAtomicLoad: returnTypesFnSingle, |
| 1044 |
OpcodeAtomicStore: returnTypesFnNoReturns, |
| 1045 |
OpcodeAtomicCas: returnTypesFnSingle, |
| 1046 |
OpcodeFence: returnTypesFnNoReturns, |
| 1047 |
OpcodeTailCallReturnCallIndirect: returnTypesFnCallIndirect, |
| 1048 |
OpcodeTailCallReturnCall: returnTypesFnCall, |
| 1049 |
OpcodeWideningPairwiseDotProductS: returnTypesFnV128, |
| 1050 |
} |
| 1051 |
|
| 1052 |
// AsLoad initializes this instruction as a store instruction with OpcodeLoad. |
| 1053 |
func (i *Instruction) AsLoad(ptr Value, offset uint32, typ Type) *Instruction { |
| 1054 |
i.opcode = OpcodeLoad |
| 1055 |
i.v = ptr |
| 1056 |
i.u1 = uint64(offset) |
| 1057 |
i.typ = typ |
| 1058 |
return i |
| 1059 |
} |
| 1060 |
|
| 1061 |
// AsExtLoad initializes this instruction as a store instruction with OpcodeLoad. |
| 1062 |
func (i *Instruction) AsExtLoad(op Opcode, ptr Value, offset uint32, dst64bit bool) *Instruction { |
| 1063 |
i.opcode = op |
| 1064 |
i.v = ptr |
| 1065 |
i.u1 = uint64(offset) |
| 1066 |
if dst64bit { |
| 1067 |
i.typ = TypeI64 |
| 1068 |
} else { |
| 1069 |
i.typ = TypeI32 |
| 1070 |
} |
| 1071 |
return i |
| 1072 |
} |
| 1073 |
|
| 1074 |
// AsVZeroExtLoad initializes this instruction as a store instruction with OpcodeVExtLoad. |
| 1075 |
func (i *Instruction) AsVZeroExtLoad(ptr Value, offset uint32, scalarType Type) *Instruction { |
| 1076 |
i.opcode = OpcodeVZeroExtLoad |
| 1077 |
i.v = ptr |
| 1078 |
i.u1 = uint64(offset) |
| 1079 |
i.u2 = uint64(scalarType) |
| 1080 |
i.typ = TypeV128 |
| 1081 |
return i |
| 1082 |
} |
| 1083 |
|
| 1084 |
// VZeroExtLoadData returns the operands for a load instruction. The returned `typ` is the scalar type of the load target. |
| 1085 |
func (i *Instruction) VZeroExtLoadData() (ptr Value, offset uint32, typ Type) { |
| 1086 |
return i.v, uint32(i.u1), Type(i.u2) |
| 1087 |
} |
| 1088 |
|
| 1089 |
// AsLoadSplat initializes this instruction as a store instruction with OpcodeLoadSplat. |
| 1090 |
func (i *Instruction) AsLoadSplat(ptr Value, offset uint32, lane VecLane) *Instruction { |
| 1091 |
i.opcode = OpcodeLoadSplat |
| 1092 |
i.v = ptr |
| 1093 |
i.u1 = uint64(offset) |
| 1094 |
i.u2 = uint64(lane) |
| 1095 |
i.typ = TypeV128 |
| 1096 |
return i |
| 1097 |
} |
| 1098 |
|
| 1099 |
// LoadData returns the operands for a load instruction. |
| 1100 |
func (i *Instruction) LoadData() (ptr Value, offset uint32, typ Type) { |
| 1101 |
return i.v, uint32(i.u1), i.typ |
| 1102 |
} |
| 1103 |
|
| 1104 |
// LoadSplatData returns the operands for a load splat instruction. |
| 1105 |
func (i *Instruction) LoadSplatData() (ptr Value, offset uint32, lane VecLane) { |
| 1106 |
return i.v, uint32(i.u1), VecLane(i.u2) |
| 1107 |
} |
| 1108 |
|
| 1109 |
// AsStore initializes this instruction as a store instruction with OpcodeStore. |
| 1110 |
func (i *Instruction) AsStore(storeOp Opcode, value, ptr Value, offset uint32) *Instruction { |
| 1111 |
i.opcode = storeOp |
| 1112 |
i.v = value |
| 1113 |
i.v2 = ptr |
| 1114 |
|
| 1115 |
var dstSize uint64 |
| 1116 |
switch storeOp { |
| 1117 |
case OpcodeStore: |
| 1118 |
dstSize = uint64(value.Type().Bits()) |
| 1119 |
case OpcodeIstore8: |
| 1120 |
dstSize = 8 |
| 1121 |
case OpcodeIstore16: |
| 1122 |
dstSize = 16 |
| 1123 |
case OpcodeIstore32: |
| 1124 |
dstSize = 32 |
| 1125 |
default: |
| 1126 |
panic("invalid store opcode" + storeOp.String()) |
| 1127 |
} |
| 1128 |
i.u1 = uint64(offset) | dstSize<<32 |
| 1129 |
return i |
| 1130 |
} |
| 1131 |
|
| 1132 |
// StoreData returns the operands for a store instruction. |
| 1133 |
func (i *Instruction) StoreData() (value, ptr Value, offset uint32, storeSizeInBits byte) { |
| 1134 |
return i.v, i.v2, uint32(i.u1), byte(i.u1 >> 32) |
| 1135 |
} |
| 1136 |
|
| 1137 |
// AsIconst64 initializes this instruction as a 64-bit integer constant instruction with OpcodeIconst. |
| 1138 |
func (i *Instruction) AsIconst64(v uint64) *Instruction { |
| 1139 |
i.opcode = OpcodeIconst |
| 1140 |
i.typ = TypeI64 |
| 1141 |
i.u1 = v |
| 1142 |
return i |
| 1143 |
} |
| 1144 |
|
| 1145 |
// AsIconst32 initializes this instruction as a 32-bit integer constant instruction with OpcodeIconst. |
| 1146 |
func (i *Instruction) AsIconst32(v uint32) *Instruction { |
| 1147 |
i.opcode = OpcodeIconst |
| 1148 |
i.typ = TypeI32 |
| 1149 |
i.u1 = uint64(v) |
| 1150 |
return i |
| 1151 |
} |
| 1152 |
|
| 1153 |
// AsIadd initializes this instruction as an integer addition instruction with OpcodeIadd. |
| 1154 |
func (i *Instruction) AsIadd(x, y Value) *Instruction { |
| 1155 |
i.opcode = OpcodeIadd |
| 1156 |
i.v = x |
| 1157 |
i.v2 = y |
| 1158 |
i.typ = x.Type() |
| 1159 |
return i |
| 1160 |
} |
| 1161 |
|
| 1162 |
// AsVIadd initializes this instruction as an integer addition instruction with OpcodeVIadd on a vector. |
| 1163 |
func (i *Instruction) AsVIadd(x, y Value, lane VecLane) *Instruction { |
| 1164 |
i.opcode = OpcodeVIadd |
| 1165 |
i.v = x |
| 1166 |
i.v2 = y |
| 1167 |
i.u1 = uint64(lane) |
| 1168 |
i.typ = TypeV128 |
| 1169 |
return i |
| 1170 |
} |
| 1171 |
|
| 1172 |
// AsWideningPairwiseDotProductS initializes this instruction as a lane-wise integer extended pairwise addition instruction |
| 1173 |
// with OpcodeIaddPairwise on a vector. |
| 1174 |
func (i *Instruction) AsWideningPairwiseDotProductS(x, y Value) *Instruction { |
| 1175 |
i.opcode = OpcodeWideningPairwiseDotProductS |
| 1176 |
i.v = x |
| 1177 |
i.v2 = y |
| 1178 |
i.typ = TypeV128 |
| 1179 |
return i |
| 1180 |
} |
| 1181 |
|
| 1182 |
// AsExtIaddPairwise initializes this instruction as a lane-wise integer extended pairwise addition instruction |
| 1183 |
// with OpcodeIaddPairwise on a vector. |
| 1184 |
func (i *Instruction) AsExtIaddPairwise(x Value, srcLane VecLane, signed bool) *Instruction { |
| 1185 |
i.opcode = OpcodeExtIaddPairwise |
| 1186 |
i.v = x |
| 1187 |
i.u1 = uint64(srcLane) |
| 1188 |
if signed { |
| 1189 |
i.u2 = 1 |
| 1190 |
} |
| 1191 |
i.typ = TypeV128 |
| 1192 |
return i |
| 1193 |
} |
| 1194 |
|
| 1195 |
// ExtIaddPairwiseData returns the operands for a lane-wise integer extended pairwise addition instruction. |
| 1196 |
func (i *Instruction) ExtIaddPairwiseData() (x Value, srcLane VecLane, signed bool) { |
| 1197 |
return i.v, VecLane(i.u1), i.u2 != 0 |
| 1198 |
} |
| 1199 |
|
| 1200 |
// AsVSaddSat initializes this instruction as a vector addition with saturation instruction with OpcodeVSaddSat on a vector. |
| 1201 |
func (i *Instruction) AsVSaddSat(x, y Value, lane VecLane) *Instruction { |
| 1202 |
i.opcode = OpcodeVSaddSat |
| 1203 |
i.v = x |
| 1204 |
i.v2 = y |
| 1205 |
i.u1 = uint64(lane) |
| 1206 |
i.typ = TypeV128 |
| 1207 |
return i |
| 1208 |
} |
| 1209 |
|
| 1210 |
// AsVUaddSat initializes this instruction as a vector addition with saturation instruction with OpcodeVUaddSat on a vector. |
| 1211 |
func (i *Instruction) AsVUaddSat(x, y Value, lane VecLane) *Instruction { |
| 1212 |
i.opcode = OpcodeVUaddSat |
| 1213 |
i.v = x |
| 1214 |
i.v2 = y |
| 1215 |
i.u1 = uint64(lane) |
| 1216 |
i.typ = TypeV128 |
| 1217 |
return i |
| 1218 |
} |
| 1219 |
|
| 1220 |
// AsVIsub initializes this instruction as an integer subtraction instruction with OpcodeVIsub on a vector. |
| 1221 |
func (i *Instruction) AsVIsub(x, y Value, lane VecLane) *Instruction { |
| 1222 |
i.opcode = OpcodeVIsub |
| 1223 |
i.v = x |
| 1224 |
i.v2 = y |
| 1225 |
i.u1 = uint64(lane) |
| 1226 |
i.typ = TypeV128 |
| 1227 |
return i |
| 1228 |
} |
| 1229 |
|
| 1230 |
// AsVSsubSat initializes this instruction as a vector addition with saturation instruction with OpcodeVSsubSat on a vector. |
| 1231 |
func (i *Instruction) AsVSsubSat(x, y Value, lane VecLane) *Instruction { |
| 1232 |
i.opcode = OpcodeVSsubSat |
| 1233 |
i.v = x |
| 1234 |
i.v2 = y |
| 1235 |
i.u1 = uint64(lane) |
| 1236 |
i.typ = TypeV128 |
| 1237 |
return i |
| 1238 |
} |
| 1239 |
|
| 1240 |
// AsVUsubSat initializes this instruction as a vector addition with saturation instruction with OpcodeVUsubSat on a vector. |
| 1241 |
func (i *Instruction) AsVUsubSat(x, y Value, lane VecLane) *Instruction { |
| 1242 |
i.opcode = OpcodeVUsubSat |
| 1243 |
i.v = x |
| 1244 |
i.v2 = y |
| 1245 |
i.u1 = uint64(lane) |
| 1246 |
i.typ = TypeV128 |
| 1247 |
return i |
| 1248 |
} |
| 1249 |
|
| 1250 |
// AsVImin initializes this instruction as a signed integer min instruction with OpcodeVImin on a vector. |
| 1251 |
func (i *Instruction) AsVImin(x, y Value, lane VecLane) *Instruction { |
| 1252 |
i.opcode = OpcodeVImin |
| 1253 |
i.v = x |
| 1254 |
i.v2 = y |
| 1255 |
i.u1 = uint64(lane) |
| 1256 |
i.typ = TypeV128 |
| 1257 |
return i |
| 1258 |
} |
| 1259 |
|
| 1260 |
// AsVUmin initializes this instruction as an unsigned integer min instruction with OpcodeVUmin on a vector. |
| 1261 |
func (i *Instruction) AsVUmin(x, y Value, lane VecLane) *Instruction { |
| 1262 |
i.opcode = OpcodeVUmin |
| 1263 |
i.v = x |
| 1264 |
i.v2 = y |
| 1265 |
i.u1 = uint64(lane) |
| 1266 |
i.typ = TypeV128 |
| 1267 |
return i |
| 1268 |
} |
| 1269 |
|
| 1270 |
// AsVImax initializes this instruction as a signed integer max instruction with OpcodeVImax on a vector. |
| 1271 |
func (i *Instruction) AsVImax(x, y Value, lane VecLane) *Instruction { |
| 1272 |
i.opcode = OpcodeVImax |
| 1273 |
i.v = x |
| 1274 |
i.v2 = y |
| 1275 |
i.u1 = uint64(lane) |
| 1276 |
i.typ = TypeV128 |
| 1277 |
return i |
| 1278 |
} |
| 1279 |
|
| 1280 |
// AsVUmax initializes this instruction as an unsigned integer max instruction with OpcodeVUmax on a vector. |
| 1281 |
func (i *Instruction) AsVUmax(x, y Value, lane VecLane) *Instruction { |
| 1282 |
i.opcode = OpcodeVUmax |
| 1283 |
i.v = x |
| 1284 |
i.v2 = y |
| 1285 |
i.u1 = uint64(lane) |
| 1286 |
i.typ = TypeV128 |
| 1287 |
return i |
| 1288 |
} |
| 1289 |
|
| 1290 |
// AsVAvgRound initializes this instruction as an unsigned integer avg instruction, truncating to zero with OpcodeVAvgRound on a vector. |
| 1291 |
func (i *Instruction) AsVAvgRound(x, y Value, lane VecLane) *Instruction { |
| 1292 |
i.opcode = OpcodeVAvgRound |
| 1293 |
i.v = x |
| 1294 |
i.v2 = y |
| 1295 |
i.u1 = uint64(lane) |
| 1296 |
i.typ = TypeV128 |
| 1297 |
return i |
| 1298 |
} |
| 1299 |
|
| 1300 |
// AsVImul initializes this instruction as an integer multiplication with OpcodeVImul on a vector. |
| 1301 |
func (i *Instruction) AsVImul(x, y Value, lane VecLane) *Instruction { |
| 1302 |
i.opcode = OpcodeVImul |
| 1303 |
i.v = x |
| 1304 |
i.v2 = y |
| 1305 |
i.u1 = uint64(lane) |
| 1306 |
i.typ = TypeV128 |
| 1307 |
return i |
| 1308 |
} |
| 1309 |
|
| 1310 |
// AsSqmulRoundSat initializes this instruction as a lane-wise saturating rounding multiplication |
| 1311 |
// in Q15 format with OpcodeSqmulRoundSat on a vector. |
| 1312 |
func (i *Instruction) AsSqmulRoundSat(x, y Value, lane VecLane) *Instruction { |
| 1313 |
i.opcode = OpcodeSqmulRoundSat |
| 1314 |
i.v = x |
| 1315 |
i.v2 = y |
| 1316 |
i.u1 = uint64(lane) |
| 1317 |
i.typ = TypeV128 |
| 1318 |
return i |
| 1319 |
} |
| 1320 |
|
| 1321 |
// AsVIabs initializes this instruction as a vector absolute value with OpcodeVIabs. |
| 1322 |
func (i *Instruction) AsVIabs(x Value, lane VecLane) *Instruction { |
| 1323 |
i.opcode = OpcodeVIabs |
| 1324 |
i.v = x |
| 1325 |
i.u1 = uint64(lane) |
| 1326 |
i.typ = TypeV128 |
| 1327 |
return i |
| 1328 |
} |
| 1329 |
|
| 1330 |
// AsVIneg initializes this instruction as a vector negation with OpcodeVIneg. |
| 1331 |
func (i *Instruction) AsVIneg(x Value, lane VecLane) *Instruction { |
| 1332 |
i.opcode = OpcodeVIneg |
| 1333 |
i.v = x |
| 1334 |
i.u1 = uint64(lane) |
| 1335 |
i.typ = TypeV128 |
| 1336 |
return i |
| 1337 |
} |
| 1338 |
|
| 1339 |
// AsVIpopcnt initializes this instruction as a Population Count instruction with OpcodeVIpopcnt on a vector. |
| 1340 |
func (i *Instruction) AsVIpopcnt(x Value, lane VecLane) *Instruction { |
| 1341 |
if lane != VecLaneI8x16 { |
| 1342 |
panic("Unsupported lane type " + lane.String()) |
| 1343 |
} |
| 1344 |
i.opcode = OpcodeVIpopcnt |
| 1345 |
i.v = x |
| 1346 |
i.u1 = uint64(lane) |
| 1347 |
i.typ = TypeV128 |
| 1348 |
return i |
| 1349 |
} |
| 1350 |
|
| 1351 |
// AsVSqrt initializes this instruction as a sqrt instruction with OpcodeVSqrt on a vector. |
| 1352 |
func (i *Instruction) AsVSqrt(x Value, lane VecLane) *Instruction { |
| 1353 |
i.opcode = OpcodeVSqrt |
| 1354 |
i.v = x |
| 1355 |
i.u1 = uint64(lane) |
| 1356 |
i.typ = TypeV128 |
| 1357 |
return i |
| 1358 |
} |
| 1359 |
|
| 1360 |
// AsVFabs initializes this instruction as a float abs instruction with OpcodeVFabs on a vector. |
| 1361 |
func (i *Instruction) AsVFabs(x Value, lane VecLane) *Instruction { |
| 1362 |
i.opcode = OpcodeVFabs |
| 1363 |
i.v = x |
| 1364 |
i.u1 = uint64(lane) |
| 1365 |
i.typ = TypeV128 |
| 1366 |
return i |
| 1367 |
} |
| 1368 |
|
| 1369 |
// AsVFneg initializes this instruction as a float neg instruction with OpcodeVFneg on a vector. |
| 1370 |
func (i *Instruction) AsVFneg(x Value, lane VecLane) *Instruction { |
| 1371 |
i.opcode = OpcodeVFneg |
| 1372 |
i.v = x |
| 1373 |
i.u1 = uint64(lane) |
| 1374 |
i.typ = TypeV128 |
| 1375 |
return i |
| 1376 |
} |
| 1377 |
|
| 1378 |
// AsVFmax initializes this instruction as a float max instruction with OpcodeVFmax on a vector. |
| 1379 |
func (i *Instruction) AsVFmax(x, y Value, lane VecLane) *Instruction { |
| 1380 |
i.opcode = OpcodeVFmax |
| 1381 |
i.v = x |
| 1382 |
i.v2 = y |
| 1383 |
i.u1 = uint64(lane) |
| 1384 |
i.typ = TypeV128 |
| 1385 |
return i |
| 1386 |
} |
| 1387 |
|
| 1388 |
// AsVFmin initializes this instruction as a float min instruction with OpcodeVFmin on a vector. |
| 1389 |
func (i *Instruction) AsVFmin(x, y Value, lane VecLane) *Instruction { |
| 1390 |
i.opcode = OpcodeVFmin |
| 1391 |
i.v = x |
| 1392 |
i.v2 = y |
| 1393 |
i.u1 = uint64(lane) |
| 1394 |
i.typ = TypeV128 |
| 1395 |
return i |
| 1396 |
} |
| 1397 |
|
| 1398 |
// AsVFadd initializes this instruction as a floating point add instruction with OpcodeVFadd on a vector. |
| 1399 |
func (i *Instruction) AsVFadd(x, y Value, lane VecLane) *Instruction { |
| 1400 |
i.opcode = OpcodeVFadd |
| 1401 |
i.v = x |
| 1402 |
i.v2 = y |
| 1403 |
i.u1 = uint64(lane) |
| 1404 |
i.typ = TypeV128 |
| 1405 |
return i |
| 1406 |
} |
| 1407 |
|
| 1408 |
// AsVFsub initializes this instruction as a floating point subtraction instruction with OpcodeVFsub on a vector. |
| 1409 |
func (i *Instruction) AsVFsub(x, y Value, lane VecLane) *Instruction { |
| 1410 |
i.opcode = OpcodeVFsub |
| 1411 |
i.v = x |
| 1412 |
i.v2 = y |
| 1413 |
i.u1 = uint64(lane) |
| 1414 |
i.typ = TypeV128 |
| 1415 |
return i |
| 1416 |
} |
| 1417 |
|
| 1418 |
// AsVFmul initializes this instruction as a floating point multiplication instruction with OpcodeVFmul on a vector. |
| 1419 |
func (i *Instruction) AsVFmul(x, y Value, lane VecLane) *Instruction { |
| 1420 |
i.opcode = OpcodeVFmul |
| 1421 |
i.v = x |
| 1422 |
i.v2 = y |
| 1423 |
i.u1 = uint64(lane) |
| 1424 |
i.typ = TypeV128 |
| 1425 |
return i |
| 1426 |
} |
| 1427 |
|
| 1428 |
// AsVFdiv initializes this instruction as a floating point division instruction with OpcodeVFdiv on a vector. |
| 1429 |
func (i *Instruction) AsVFdiv(x, y Value, lane VecLane) *Instruction { |
| 1430 |
i.opcode = OpcodeVFdiv |
| 1431 |
i.v = x |
| 1432 |
i.v2 = y |
| 1433 |
i.u1 = uint64(lane) |
| 1434 |
i.typ = TypeV128 |
| 1435 |
return i |
| 1436 |
} |
| 1437 |
|
| 1438 |
// AsImul initializes this instruction as an integer addition instruction with OpcodeImul. |
| 1439 |
func (i *Instruction) AsImul(x, y Value) *Instruction { |
| 1440 |
i.opcode = OpcodeImul |
| 1441 |
i.v = x |
| 1442 |
i.v2 = y |
| 1443 |
i.typ = x.Type() |
| 1444 |
return i |
| 1445 |
} |
| 1446 |
|
| 1447 |
func (i *Instruction) Insert(b Builder) *Instruction { |
| 1448 |
b.InsertInstruction(i) |
| 1449 |
return i |
| 1450 |
} |
| 1451 |
|
| 1452 |
// AsIsub initializes this instruction as an integer subtraction instruction with OpcodeIsub. |
| 1453 |
func (i *Instruction) AsIsub(x, y Value) *Instruction { |
| 1454 |
i.opcode = OpcodeIsub |
| 1455 |
i.v = x |
| 1456 |
i.v2 = y |
| 1457 |
i.typ = x.Type() |
| 1458 |
return i |
| 1459 |
} |
| 1460 |
|
| 1461 |
// AsIcmp initializes this instruction as an integer comparison instruction with OpcodeIcmp. |
| 1462 |
func (i *Instruction) AsIcmp(x, y Value, c IntegerCmpCond) *Instruction { |
| 1463 |
i.opcode = OpcodeIcmp |
| 1464 |
i.v = x |
| 1465 |
i.v2 = y |
| 1466 |
i.u1 = uint64(c) |
| 1467 |
i.typ = TypeI32 |
| 1468 |
return i |
| 1469 |
} |
| 1470 |
|
| 1471 |
// AsFcmp initializes this instruction as an integer comparison instruction with OpcodeFcmp. |
| 1472 |
func (i *Instruction) AsFcmp(x, y Value, c FloatCmpCond) { |
| 1473 |
i.opcode = OpcodeFcmp |
| 1474 |
i.v = x |
| 1475 |
i.v2 = y |
| 1476 |
i.u1 = uint64(c) |
| 1477 |
i.typ = TypeI32 |
| 1478 |
} |
| 1479 |
|
| 1480 |
// AsVIcmp initializes this instruction as an integer vector comparison instruction with OpcodeVIcmp. |
| 1481 |
func (i *Instruction) AsVIcmp(x, y Value, c IntegerCmpCond, lane VecLane) *Instruction { |
| 1482 |
i.opcode = OpcodeVIcmp |
| 1483 |
i.v = x |
| 1484 |
i.v2 = y |
| 1485 |
i.u1 = uint64(c) |
| 1486 |
i.u2 = uint64(lane) |
| 1487 |
i.typ = TypeV128 |
| 1488 |
return i |
| 1489 |
} |
| 1490 |
|
| 1491 |
// AsVFcmp initializes this instruction as a float comparison instruction with OpcodeVFcmp on Vector. |
| 1492 |
func (i *Instruction) AsVFcmp(x, y Value, c FloatCmpCond, lane VecLane) *Instruction { |
| 1493 |
i.opcode = OpcodeVFcmp |
| 1494 |
i.v = x |
| 1495 |
i.v2 = y |
| 1496 |
i.u1 = uint64(c) |
| 1497 |
i.typ = TypeV128 |
| 1498 |
i.u2 = uint64(lane) |
| 1499 |
return i |
| 1500 |
} |
| 1501 |
|
| 1502 |
// AsVCeil initializes this instruction as an instruction with OpcodeCeil. |
| 1503 |
func (i *Instruction) AsVCeil(x Value, lane VecLane) *Instruction { |
| 1504 |
i.opcode = OpcodeVCeil |
| 1505 |
i.v = x |
| 1506 |
i.typ = x.Type() |
| 1507 |
i.u1 = uint64(lane) |
| 1508 |
return i |
| 1509 |
} |
| 1510 |
|
| 1511 |
// AsVFloor initializes this instruction as an instruction with OpcodeFloor. |
| 1512 |
func (i *Instruction) AsVFloor(x Value, lane VecLane) *Instruction { |
| 1513 |
i.opcode = OpcodeVFloor |
| 1514 |
i.v = x |
| 1515 |
i.typ = x.Type() |
| 1516 |
i.u1 = uint64(lane) |
| 1517 |
return i |
| 1518 |
} |
| 1519 |
|
| 1520 |
// AsVTrunc initializes this instruction as an instruction with OpcodeTrunc. |
| 1521 |
func (i *Instruction) AsVTrunc(x Value, lane VecLane) *Instruction { |
| 1522 |
i.opcode = OpcodeVTrunc |
| 1523 |
i.v = x |
| 1524 |
i.typ = x.Type() |
| 1525 |
i.u1 = uint64(lane) |
| 1526 |
return i |
| 1527 |
} |
| 1528 |
|
| 1529 |
// AsVNearest initializes this instruction as an instruction with OpcodeNearest. |
| 1530 |
func (i *Instruction) AsVNearest(x Value, lane VecLane) *Instruction { |
| 1531 |
i.opcode = OpcodeVNearest |
| 1532 |
i.v = x |
| 1533 |
i.typ = x.Type() |
| 1534 |
i.u1 = uint64(lane) |
| 1535 |
return i |
| 1536 |
} |
| 1537 |
|
| 1538 |
// AsVMaxPseudo initializes this instruction as an instruction with OpcodeVMaxPseudo. |
| 1539 |
func (i *Instruction) AsVMaxPseudo(x, y Value, lane VecLane) *Instruction { |
| 1540 |
i.opcode = OpcodeVMaxPseudo |
| 1541 |
i.typ = x.Type() |
| 1542 |
i.v = x |
| 1543 |
i.v2 = y |
| 1544 |
i.u1 = uint64(lane) |
| 1545 |
return i |
| 1546 |
} |
| 1547 |
|
| 1548 |
// AsVMinPseudo initializes this instruction as an instruction with OpcodeVMinPseudo. |
| 1549 |
func (i *Instruction) AsVMinPseudo(x, y Value, lane VecLane) *Instruction { |
| 1550 |
i.opcode = OpcodeVMinPseudo |
| 1551 |
i.typ = x.Type() |
| 1552 |
i.v = x |
| 1553 |
i.v2 = y |
| 1554 |
i.u1 = uint64(lane) |
| 1555 |
return i |
| 1556 |
} |
| 1557 |
|
| 1558 |
// AsSDiv initializes this instruction as an integer bitwise and instruction with OpcodeSdiv. |
| 1559 |
func (i *Instruction) AsSDiv(x, y, ctx Value) *Instruction { |
| 1560 |
i.opcode = OpcodeSdiv |
| 1561 |
i.v = x |
| 1562 |
i.v2 = y |
| 1563 |
i.v3 = ctx |
| 1564 |
i.typ = x.Type() |
| 1565 |
return i |
| 1566 |
} |
| 1567 |
|
| 1568 |
// AsUDiv initializes this instruction as an integer bitwise and instruction with OpcodeUdiv. |
| 1569 |
func (i *Instruction) AsUDiv(x, y, ctx Value) *Instruction { |
| 1570 |
i.opcode = OpcodeUdiv |
| 1571 |
i.v = x |
| 1572 |
i.v2 = y |
| 1573 |
i.v3 = ctx |
| 1574 |
i.typ = x.Type() |
| 1575 |
return i |
| 1576 |
} |
| 1577 |
|
| 1578 |
// AsSRem initializes this instruction as an integer bitwise and instruction with OpcodeSrem. |
| 1579 |
func (i *Instruction) AsSRem(x, y, ctx Value) *Instruction { |
| 1580 |
i.opcode = OpcodeSrem |
| 1581 |
i.v = x |
| 1582 |
i.v2 = y |
| 1583 |
i.v3 = ctx |
| 1584 |
i.typ = x.Type() |
| 1585 |
return i |
| 1586 |
} |
| 1587 |
|
| 1588 |
// AsURem initializes this instruction as an integer bitwise and instruction with OpcodeUrem. |
| 1589 |
func (i *Instruction) AsURem(x, y, ctx Value) *Instruction { |
| 1590 |
i.opcode = OpcodeUrem |
| 1591 |
i.v = x |
| 1592 |
i.v2 = y |
| 1593 |
i.v3 = ctx |
| 1594 |
i.typ = x.Type() |
| 1595 |
return i |
| 1596 |
} |
| 1597 |
|
| 1598 |
// AsBand initializes this instruction as an integer bitwise and instruction with OpcodeBand. |
| 1599 |
func (i *Instruction) AsBand(x, amount Value) *Instruction { |
| 1600 |
i.opcode = OpcodeBand |
| 1601 |
i.v = x |
| 1602 |
i.v2 = amount |
| 1603 |
i.typ = x.Type() |
| 1604 |
return i |
| 1605 |
} |
| 1606 |
|
| 1607 |
// AsBor initializes this instruction as an integer bitwise or instruction with OpcodeBor. |
| 1608 |
func (i *Instruction) AsBor(x, amount Value) { |
| 1609 |
i.opcode = OpcodeBor |
| 1610 |
i.v = x |
| 1611 |
i.v2 = amount |
| 1612 |
i.typ = x.Type() |
| 1613 |
} |
| 1614 |
|
| 1615 |
// AsBxor initializes this instruction as an integer bitwise xor instruction with OpcodeBxor. |
| 1616 |
func (i *Instruction) AsBxor(x, amount Value) { |
| 1617 |
i.opcode = OpcodeBxor |
| 1618 |
i.v = x |
| 1619 |
i.v2 = amount |
| 1620 |
i.typ = x.Type() |
| 1621 |
} |
| 1622 |
|
| 1623 |
// AsIshl initializes this instruction as an integer shift left instruction with OpcodeIshl. |
| 1624 |
func (i *Instruction) AsIshl(x, amount Value) *Instruction { |
| 1625 |
i.opcode = OpcodeIshl |
| 1626 |
i.v = x |
| 1627 |
i.v2 = amount |
| 1628 |
i.typ = x.Type() |
| 1629 |
return i |
| 1630 |
} |
| 1631 |
|
| 1632 |
// AsVIshl initializes this instruction as an integer shift left instruction with OpcodeVIshl on vector. |
| 1633 |
func (i *Instruction) AsVIshl(x, amount Value, lane VecLane) *Instruction { |
| 1634 |
i.opcode = OpcodeVIshl |
| 1635 |
i.v = x |
| 1636 |
i.v2 = amount |
| 1637 |
i.u1 = uint64(lane) |
| 1638 |
i.typ = x.Type() |
| 1639 |
return i |
| 1640 |
} |
| 1641 |
|
| 1642 |
// AsUshr initializes this instruction as an integer unsigned shift right (logical shift right) instruction with OpcodeUshr. |
| 1643 |
func (i *Instruction) AsUshr(x, amount Value) *Instruction { |
| 1644 |
i.opcode = OpcodeUshr |
| 1645 |
i.v = x |
| 1646 |
i.v2 = amount |
| 1647 |
i.typ = x.Type() |
| 1648 |
return i |
| 1649 |
} |
| 1650 |
|
| 1651 |
// AsVUshr initializes this instruction as an integer unsigned shift right (logical shift right) instruction with OpcodeVUshr on vector. |
| 1652 |
func (i *Instruction) AsVUshr(x, amount Value, lane VecLane) *Instruction { |
| 1653 |
i.opcode = OpcodeVUshr |
| 1654 |
i.v = x |
| 1655 |
i.v2 = amount |
| 1656 |
i.u1 = uint64(lane) |
| 1657 |
i.typ = x.Type() |
| 1658 |
return i |
| 1659 |
} |
| 1660 |
|
| 1661 |
// AsSshr initializes this instruction as an integer signed shift right (arithmetic shift right) instruction with OpcodeSshr. |
| 1662 |
func (i *Instruction) AsSshr(x, amount Value) *Instruction { |
| 1663 |
i.opcode = OpcodeSshr |
| 1664 |
i.v = x |
| 1665 |
i.v2 = amount |
| 1666 |
i.typ = x.Type() |
| 1667 |
return i |
| 1668 |
} |
| 1669 |
|
| 1670 |
// AsVSshr initializes this instruction as an integer signed shift right (arithmetic shift right) instruction with OpcodeVSshr on vector. |
| 1671 |
func (i *Instruction) AsVSshr(x, amount Value, lane VecLane) *Instruction { |
| 1672 |
i.opcode = OpcodeVSshr |
| 1673 |
i.v = x |
| 1674 |
i.v2 = amount |
| 1675 |
i.u1 = uint64(lane) |
| 1676 |
i.typ = x.Type() |
| 1677 |
return i |
| 1678 |
} |
| 1679 |
|
| 1680 |
// AsExtractlane initializes this instruction as an extract lane instruction with OpcodeExtractlane on vector. |
| 1681 |
func (i *Instruction) AsExtractlane(x Value, index byte, lane VecLane, signed bool) *Instruction { |
| 1682 |
i.opcode = OpcodeExtractlane |
| 1683 |
i.v = x |
| 1684 |
// We do not have a field for signedness, but `index` is a byte, |
| 1685 |
// so we just encode the flag in the high bits of `u1`. |
| 1686 |
i.u1 = uint64(index) |
| 1687 |
if signed { |
| 1688 |
i.u1 = i.u1 | 1<<32 |
| 1689 |
} |
| 1690 |
i.u2 = uint64(lane) |
| 1691 |
switch lane { |
| 1692 |
case VecLaneI8x16, VecLaneI16x8, VecLaneI32x4: |
| 1693 |
i.typ = TypeI32 |
| 1694 |
case VecLaneI64x2: |
| 1695 |
i.typ = TypeI64 |
| 1696 |
case VecLaneF32x4: |
| 1697 |
i.typ = TypeF32 |
| 1698 |
case VecLaneF64x2: |
| 1699 |
i.typ = TypeF64 |
| 1700 |
} |
| 1701 |
return i |
| 1702 |
} |
| 1703 |
|
| 1704 |
// AsInsertlane initializes this instruction as an insert lane instruction with OpcodeInsertlane on vector. |
| 1705 |
func (i *Instruction) AsInsertlane(x, y Value, index byte, lane VecLane) *Instruction { |
| 1706 |
i.opcode = OpcodeInsertlane |
| 1707 |
i.v = x |
| 1708 |
i.v2 = y |
| 1709 |
i.u1 = uint64(index) |
| 1710 |
i.u2 = uint64(lane) |
| 1711 |
i.typ = TypeV128 |
| 1712 |
return i |
| 1713 |
} |
| 1714 |
|
| 1715 |
// AsShuffle initializes this instruction as a shuffle instruction with OpcodeShuffle on vector. |
| 1716 |
func (i *Instruction) AsShuffle(x, y Value, lane []byte) *Instruction { |
| 1717 |
i.opcode = OpcodeShuffle |
| 1718 |
i.v = x |
| 1719 |
i.v2 = y |
| 1720 |
// Encode the 16 bytes as 8 bytes in u1, and 8 bytes in u2. |
| 1721 |
i.u1 = uint64(lane[7])<<56 | uint64(lane[6])<<48 | uint64(lane[5])<<40 | uint64(lane[4])<<32 | uint64(lane[3])<<24 | uint64(lane[2])<<16 | uint64(lane[1])<<8 | uint64(lane[0]) |
| 1722 |
i.u2 = uint64(lane[15])<<56 | uint64(lane[14])<<48 | uint64(lane[13])<<40 | uint64(lane[12])<<32 | uint64(lane[11])<<24 | uint64(lane[10])<<16 | uint64(lane[9])<<8 | uint64(lane[8]) |
| 1723 |
i.typ = TypeV128 |
| 1724 |
return i |
| 1725 |
} |
| 1726 |
|
| 1727 |
// AsSwizzle initializes this instruction as an insert lane instruction with OpcodeSwizzle on vector. |
| 1728 |
func (i *Instruction) AsSwizzle(x, y Value, lane VecLane) *Instruction { |
| 1729 |
i.opcode = OpcodeSwizzle |
| 1730 |
i.v = x |
| 1731 |
i.v2 = y |
| 1732 |
i.u1 = uint64(lane) |
| 1733 |
i.typ = TypeV128 |
| 1734 |
return i |
| 1735 |
} |
| 1736 |
|
| 1737 |
// AsSplat initializes this instruction as an insert lane instruction with OpcodeSplat on vector. |
| 1738 |
func (i *Instruction) AsSplat(x Value, lane VecLane) *Instruction { |
| 1739 |
i.opcode = OpcodeSplat |
| 1740 |
i.v = x |
| 1741 |
i.u1 = uint64(lane) |
| 1742 |
i.typ = TypeV128 |
| 1743 |
return i |
| 1744 |
} |
| 1745 |
|
| 1746 |
// AsRotl initializes this instruction as a word rotate left instruction with OpcodeRotl. |
| 1747 |
func (i *Instruction) AsRotl(x, amount Value) { |
| 1748 |
i.opcode = OpcodeRotl |
| 1749 |
i.v = x |
| 1750 |
i.v2 = amount |
| 1751 |
i.typ = x.Type() |
| 1752 |
} |
| 1753 |
|
| 1754 |
// AsRotr initializes this instruction as a word rotate right instruction with OpcodeRotr. |
| 1755 |
func (i *Instruction) AsRotr(x, amount Value) { |
| 1756 |
i.opcode = OpcodeRotr |
| 1757 |
i.v = x |
| 1758 |
i.v2 = amount |
| 1759 |
i.typ = x.Type() |
| 1760 |
} |
| 1761 |
|
| 1762 |
// IcmpData returns the operands and comparison condition of this integer comparison instruction. |
| 1763 |
func (i *Instruction) IcmpData() (x, y Value, c IntegerCmpCond) { |
| 1764 |
return i.v, i.v2, IntegerCmpCond(i.u1) |
| 1765 |
} |
| 1766 |
|
| 1767 |
// FcmpData returns the operands and comparison condition of this floating-point comparison instruction. |
| 1768 |
func (i *Instruction) FcmpData() (x, y Value, c FloatCmpCond) { |
| 1769 |
return i.v, i.v2, FloatCmpCond(i.u1) |
| 1770 |
} |
| 1771 |
|
| 1772 |
// VIcmpData returns the operands and comparison condition of this integer comparison instruction on vector. |
| 1773 |
func (i *Instruction) VIcmpData() (x, y Value, c IntegerCmpCond, l VecLane) { |
| 1774 |
return i.v, i.v2, IntegerCmpCond(i.u1), VecLane(i.u2) |
| 1775 |
} |
| 1776 |
|
| 1777 |
// VFcmpData returns the operands and comparison condition of this float comparison instruction on vector. |
| 1778 |
func (i *Instruction) VFcmpData() (x, y Value, c FloatCmpCond, l VecLane) { |
| 1779 |
return i.v, i.v2, FloatCmpCond(i.u1), VecLane(i.u2) |
| 1780 |
} |
| 1781 |
|
| 1782 |
// ExtractlaneData returns the operands and sign flag of Extractlane on vector. |
| 1783 |
func (i *Instruction) ExtractlaneData() (x Value, index byte, signed bool, l VecLane) { |
| 1784 |
x = i.v |
| 1785 |
index = byte(0b00001111 & i.u1) |
| 1786 |
signed = i.u1>>32 != 0 |
| 1787 |
l = VecLane(i.u2) |
| 1788 |
return |
| 1789 |
} |
| 1790 |
|
| 1791 |
// InsertlaneData returns the operands and sign flag of Insertlane on vector. |
| 1792 |
func (i *Instruction) InsertlaneData() (x, y Value, index byte, l VecLane) { |
| 1793 |
x = i.v |
| 1794 |
y = i.v2 |
| 1795 |
index = byte(i.u1) |
| 1796 |
l = VecLane(i.u2) |
| 1797 |
return |
| 1798 |
} |
| 1799 |
|
| 1800 |
// AsFadd initializes this instruction as a floating-point addition instruction with OpcodeFadd. |
| 1801 |
func (i *Instruction) AsFadd(x, y Value) { |
| 1802 |
i.opcode = OpcodeFadd |
| 1803 |
i.v = x |
| 1804 |
i.v2 = y |
| 1805 |
i.typ = x.Type() |
| 1806 |
} |
| 1807 |
|
| 1808 |
// AsFsub initializes this instruction as a floating-point subtraction instruction with OpcodeFsub. |
| 1809 |
func (i *Instruction) AsFsub(x, y Value) { |
| 1810 |
i.opcode = OpcodeFsub |
| 1811 |
i.v = x |
| 1812 |
i.v2 = y |
| 1813 |
i.typ = x.Type() |
| 1814 |
} |
| 1815 |
|
| 1816 |
// AsFmul initializes this instruction as a floating-point multiplication instruction with OpcodeFmul. |
| 1817 |
func (i *Instruction) AsFmul(x, y Value) { |
| 1818 |
i.opcode = OpcodeFmul |
| 1819 |
i.v = x |
| 1820 |
i.v2 = y |
| 1821 |
i.typ = x.Type() |
| 1822 |
} |
| 1823 |
|
| 1824 |
// AsFdiv initializes this instruction as a floating-point division instruction with OpcodeFdiv. |
| 1825 |
func (i *Instruction) AsFdiv(x, y Value) { |
| 1826 |
i.opcode = OpcodeFdiv |
| 1827 |
i.v = x |
| 1828 |
i.v2 = y |
| 1829 |
i.typ = x.Type() |
| 1830 |
} |
| 1831 |
|
| 1832 |
// AsFmin initializes this instruction to take the minimum of two floating-points with OpcodeFmin. |
| 1833 |
func (i *Instruction) AsFmin(x, y Value) { |
| 1834 |
i.opcode = OpcodeFmin |
| 1835 |
i.v = x |
| 1836 |
i.v2 = y |
| 1837 |
i.typ = x.Type() |
| 1838 |
} |
| 1839 |
|
| 1840 |
// AsFmax initializes this instruction to take the maximum of two floating-points with OpcodeFmax. |
| 1841 |
func (i *Instruction) AsFmax(x, y Value) { |
| 1842 |
i.opcode = OpcodeFmax |
| 1843 |
i.v = x |
| 1844 |
i.v2 = y |
| 1845 |
i.typ = x.Type() |
| 1846 |
} |
| 1847 |
|
| 1848 |
// AsF32const initializes this instruction as a 32-bit floating-point constant instruction with OpcodeF32const. |
| 1849 |
func (i *Instruction) AsF32const(f float32) *Instruction { |
| 1850 |
i.opcode = OpcodeF32const |
| 1851 |
i.typ = TypeF64 |
| 1852 |
i.u1 = uint64(math.Float32bits(f)) |
| 1853 |
return i |
| 1854 |
} |
| 1855 |
|
| 1856 |
// AsF64const initializes this instruction as a 64-bit floating-point constant instruction with OpcodeF64const. |
| 1857 |
func (i *Instruction) AsF64const(f float64) *Instruction { |
| 1858 |
i.opcode = OpcodeF64const |
| 1859 |
i.typ = TypeF64 |
| 1860 |
i.u1 = math.Float64bits(f) |
| 1861 |
return i |
| 1862 |
} |
| 1863 |
|
| 1864 |
// AsVconst initializes this instruction as a vector constant instruction with OpcodeVconst. |
| 1865 |
func (i *Instruction) AsVconst(lo, hi uint64) *Instruction { |
| 1866 |
i.opcode = OpcodeVconst |
| 1867 |
i.typ = TypeV128 |
| 1868 |
i.u1 = lo |
| 1869 |
i.u2 = hi |
| 1870 |
return i |
| 1871 |
} |
| 1872 |
|
| 1873 |
// AsVbnot initializes this instruction as a vector negation instruction with OpcodeVbnot. |
| 1874 |
func (i *Instruction) AsVbnot(v Value) *Instruction { |
| 1875 |
i.opcode = OpcodeVbnot |
| 1876 |
i.typ = TypeV128 |
| 1877 |
i.v = v |
| 1878 |
return i |
| 1879 |
} |
| 1880 |
|
| 1881 |
// AsVband initializes this instruction as an and vector instruction with OpcodeVband. |
| 1882 |
func (i *Instruction) AsVband(x, y Value) *Instruction { |
| 1883 |
i.opcode = OpcodeVband |
| 1884 |
i.typ = TypeV128 |
| 1885 |
i.v = x |
| 1886 |
i.v2 = y |
| 1887 |
return i |
| 1888 |
} |
| 1889 |
|
| 1890 |
// AsVbor initializes this instruction as an or vector instruction with OpcodeVbor. |
| 1891 |
func (i *Instruction) AsVbor(x, y Value) *Instruction { |
| 1892 |
i.opcode = OpcodeVbor |
| 1893 |
i.typ = TypeV128 |
| 1894 |
i.v = x |
| 1895 |
i.v2 = y |
| 1896 |
return i |
| 1897 |
} |
| 1898 |
|
| 1899 |
// AsVbxor initializes this instruction as a xor vector instruction with OpcodeVbxor. |
| 1900 |
func (i *Instruction) AsVbxor(x, y Value) *Instruction { |
| 1901 |
i.opcode = OpcodeVbxor |
| 1902 |
i.typ = TypeV128 |
| 1903 |
i.v = x |
| 1904 |
i.v2 = y |
| 1905 |
return i |
| 1906 |
} |
| 1907 |
|
| 1908 |
// AsVbandnot initializes this instruction as an and-not vector instruction with OpcodeVbandnot. |
| 1909 |
func (i *Instruction) AsVbandnot(x, y Value) *Instruction { |
| 1910 |
i.opcode = OpcodeVbandnot |
| 1911 |
i.typ = TypeV128 |
| 1912 |
i.v = x |
| 1913 |
i.v2 = y |
| 1914 |
return i |
| 1915 |
} |
| 1916 |
|
| 1917 |
// AsVbitselect initializes this instruction as a bit select vector instruction with OpcodeVbitselect. |
| 1918 |
func (i *Instruction) AsVbitselect(c, x, y Value) *Instruction { |
| 1919 |
i.opcode = OpcodeVbitselect |
| 1920 |
i.typ = TypeV128 |
| 1921 |
i.v = c |
| 1922 |
i.v2 = x |
| 1923 |
i.v3 = y |
| 1924 |
return i |
| 1925 |
} |
| 1926 |
|
| 1927 |
// AsVanyTrue initializes this instruction as an anyTrue vector instruction with OpcodeVanyTrue. |
| 1928 |
func (i *Instruction) AsVanyTrue(x Value) *Instruction { |
| 1929 |
i.opcode = OpcodeVanyTrue |
| 1930 |
i.typ = TypeI32 |
| 1931 |
i.v = x |
| 1932 |
return i |
| 1933 |
} |
| 1934 |
|
| 1935 |
// AsVallTrue initializes this instruction as an allTrue vector instruction with OpcodeVallTrue. |
| 1936 |
func (i *Instruction) AsVallTrue(x Value, lane VecLane) *Instruction { |
| 1937 |
i.opcode = OpcodeVallTrue |
| 1938 |
i.typ = TypeI32 |
| 1939 |
i.v = x |
| 1940 |
i.u1 = uint64(lane) |
| 1941 |
return i |
| 1942 |
} |
| 1943 |
|
| 1944 |
// AsVhighBits initializes this instruction as a highBits vector instruction with OpcodeVhighBits. |
| 1945 |
func (i *Instruction) AsVhighBits(x Value, lane VecLane) *Instruction { |
| 1946 |
i.opcode = OpcodeVhighBits |
| 1947 |
i.typ = TypeI32 |
| 1948 |
i.v = x |
| 1949 |
i.u1 = uint64(lane) |
| 1950 |
return i |
| 1951 |
} |
| 1952 |
|
| 1953 |
// VconstData returns the operands of this vector constant instruction. |
| 1954 |
func (i *Instruction) VconstData() (lo, hi uint64) { |
| 1955 |
return i.u1, i.u2 |
| 1956 |
} |
| 1957 |
|
| 1958 |
// AsReturn initializes this instruction as a return instruction with OpcodeReturn. |
| 1959 |
func (i *Instruction) AsReturn(vs wazevoapi.VarLength[Value]) *Instruction { |
| 1960 |
i.opcode = OpcodeReturn |
| 1961 |
i.vs = vs |
| 1962 |
return i |
| 1963 |
} |
| 1964 |
|
| 1965 |
// AsIreduce initializes this instruction as a reduction instruction with OpcodeIreduce. |
| 1966 |
func (i *Instruction) AsIreduce(v Value, dstType Type) *Instruction { |
| 1967 |
i.opcode = OpcodeIreduce |
| 1968 |
i.v = v |
| 1969 |
i.typ = dstType |
| 1970 |
return i |
| 1971 |
} |
| 1972 |
|
| 1973 |
// AsWiden initializes this instruction as a signed or unsigned widen instruction |
| 1974 |
// on low half or high half of the given vector with OpcodeSwidenLow, OpcodeUwidenLow, OpcodeSwidenHigh, OpcodeUwidenHigh. |
| 1975 |
func (i *Instruction) AsWiden(v Value, lane VecLane, signed, low bool) *Instruction { |
| 1976 |
switch { |
| 1977 |
case signed && low: |
| 1978 |
i.opcode = OpcodeSwidenLow |
| 1979 |
case !signed && low: |
| 1980 |
i.opcode = OpcodeUwidenLow |
| 1981 |
case signed && !low: |
| 1982 |
i.opcode = OpcodeSwidenHigh |
| 1983 |
case !signed && !low: |
| 1984 |
i.opcode = OpcodeUwidenHigh |
| 1985 |
} |
| 1986 |
i.v = v |
| 1987 |
i.u1 = uint64(lane) |
| 1988 |
return i |
| 1989 |
} |
| 1990 |
|
| 1991 |
// AsAtomicLoad initializes this instruction as an atomic load. |
| 1992 |
// The size is in bytes and must be 1, 2, 4, or 8. |
| 1993 |
func (i *Instruction) AsAtomicLoad(addr Value, size uint64, typ Type) *Instruction { |
| 1994 |
i.opcode = OpcodeAtomicLoad |
| 1995 |
i.u1 = size |
| 1996 |
i.v = addr |
| 1997 |
i.typ = typ |
| 1998 |
return i |
| 1999 |
} |
| 2000 |
|
| 2001 |
// AsAtomicLoad initializes this instruction as an atomic store. |
| 2002 |
// The size is in bytes and must be 1, 2, 4, or 8. |
| 2003 |
func (i *Instruction) AsAtomicStore(addr, val Value, size uint64) *Instruction { |
| 2004 |
i.opcode = OpcodeAtomicStore |
| 2005 |
i.u1 = size |
| 2006 |
i.v = addr |
| 2007 |
i.v2 = val |
| 2008 |
i.typ = val.Type() |
| 2009 |
return i |
| 2010 |
} |
| 2011 |
|
| 2012 |
// AsAtomicRmw initializes this instruction as an atomic read-modify-write. |
| 2013 |
// The size is in bytes and must be 1, 2, 4, or 8. |
| 2014 |
func (i *Instruction) AsAtomicRmw(op AtomicRmwOp, addr, val Value, size uint64) *Instruction { |
| 2015 |
i.opcode = OpcodeAtomicRmw |
| 2016 |
i.u1 = uint64(op) |
| 2017 |
i.u2 = size |
| 2018 |
i.v = addr |
| 2019 |
i.v2 = val |
| 2020 |
i.typ = val.Type() |
| 2021 |
return i |
| 2022 |
} |
| 2023 |
|
| 2024 |
// AsAtomicCas initializes this instruction as an atomic compare-and-swap. |
| 2025 |
// The size is in bytes and must be 1, 2, 4, or 8. |
| 2026 |
func (i *Instruction) AsAtomicCas(addr, exp, repl Value, size uint64) *Instruction { |
| 2027 |
i.opcode = OpcodeAtomicCas |
| 2028 |
i.u1 = size |
| 2029 |
i.v = addr |
| 2030 |
i.v2 = exp |
| 2031 |
i.v3 = repl |
| 2032 |
i.typ = repl.Type() |
| 2033 |
return i |
| 2034 |
} |
| 2035 |
|
| 2036 |
// AsFence initializes this instruction as a memory fence. |
| 2037 |
// A single byte immediate may be used to indicate fence ordering in the future |
| 2038 |
// but is currently always 0 and ignored. |
| 2039 |
func (i *Instruction) AsFence(order byte) *Instruction { |
| 2040 |
i.opcode = OpcodeFence |
| 2041 |
i.u1 = uint64(order) |
| 2042 |
return i |
| 2043 |
} |
| 2044 |
|
| 2045 |
// AtomicRmwData returns the data for this atomic read-modify-write instruction. |
| 2046 |
func (i *Instruction) AtomicRmwData() (op AtomicRmwOp, size uint64) { |
| 2047 |
return AtomicRmwOp(i.u1), i.u2 |
| 2048 |
} |
| 2049 |
|
| 2050 |
// AtomicTargetSize returns the target memory size of the atomic instruction. |
| 2051 |
func (i *Instruction) AtomicTargetSize() (size uint64) { |
| 2052 |
return i.u1 |
| 2053 |
} |
| 2054 |
|
| 2055 |
// AsTailCallReturnCall initializes this instruction as a call instruction with OpcodeTailCallReturnCall. |
| 2056 |
func (i *Instruction) AsTailCallReturnCall(ref FuncRef, sig *Signature, args Values) { |
| 2057 |
i.opcode = OpcodeTailCallReturnCall |
| 2058 |
i.u1 = uint64(ref) |
| 2059 |
i.vs = args |
| 2060 |
i.u2 = uint64(sig.ID) |
| 2061 |
sig.used = true |
| 2062 |
} |
| 2063 |
|
| 2064 |
// AsTailCallReturnCallIndirect initializes this instruction as a call-indirect instruction with OpcodeTailCallReturnCallIndirect. |
| 2065 |
func (i *Instruction) AsTailCallReturnCallIndirect(funcPtr Value, sig *Signature, args Values) *Instruction { |
| 2066 |
i.opcode = OpcodeTailCallReturnCallIndirect |
| 2067 |
i.vs = args |
| 2068 |
i.v = funcPtr |
| 2069 |
i.u1 = uint64(sig.ID) |
| 2070 |
sig.used = true |
| 2071 |
return i |
| 2072 |
} |
| 2073 |
|
| 2074 |
// ReturnVals returns the return values of OpcodeReturn. |
| 2075 |
func (i *Instruction) ReturnVals() []Value { |
| 2076 |
return i.vs.View() |
| 2077 |
} |
| 2078 |
|
| 2079 |
// AsExitWithCode initializes this instruction as a trap instruction with OpcodeExitWithCode. |
| 2080 |
func (i *Instruction) AsExitWithCode(ctx Value, code wazevoapi.ExitCode) { |
| 2081 |
i.opcode = OpcodeExitWithCode |
| 2082 |
i.v = ctx |
| 2083 |
i.u1 = uint64(code) |
| 2084 |
} |
| 2085 |
|
| 2086 |
// AsExitIfTrueWithCode initializes this instruction as a trap instruction with OpcodeExitIfTrueWithCode. |
| 2087 |
func (i *Instruction) AsExitIfTrueWithCode(ctx, c Value, code wazevoapi.ExitCode) *Instruction { |
| 2088 |
i.opcode = OpcodeExitIfTrueWithCode |
| 2089 |
i.v = ctx |
| 2090 |
i.v2 = c |
| 2091 |
i.u1 = uint64(code) |
| 2092 |
return i |
| 2093 |
} |
| 2094 |
|
| 2095 |
// ExitWithCodeData returns the context and exit code of OpcodeExitWithCode. |
| 2096 |
func (i *Instruction) ExitWithCodeData() (ctx Value, code wazevoapi.ExitCode) { |
| 2097 |
return i.v, wazevoapi.ExitCode(i.u1) |
| 2098 |
} |
| 2099 |
|
| 2100 |
// ExitIfTrueWithCodeData returns the context and exit code of OpcodeExitWithCode. |
| 2101 |
func (i *Instruction) ExitIfTrueWithCodeData() (ctx, c Value, code wazevoapi.ExitCode) { |
| 2102 |
return i.v, i.v2, wazevoapi.ExitCode(i.u1) |
| 2103 |
} |
| 2104 |
|
| 2105 |
// InvertBrx inverts either OpcodeBrz or OpcodeBrnz to the other. |
| 2106 |
func (i *Instruction) InvertBrx() { |
| 2107 |
switch i.opcode { |
| 2108 |
case OpcodeBrz: |
| 2109 |
i.opcode = OpcodeBrnz |
| 2110 |
case OpcodeBrnz: |
| 2111 |
i.opcode = OpcodeBrz |
| 2112 |
default: |
| 2113 |
panic("BUG") |
| 2114 |
} |
| 2115 |
} |
| 2116 |
|
| 2117 |
// BranchData returns the branch data for this instruction necessary for backends. |
| 2118 |
func (i *Instruction) BranchData() (condVal Value, blockArgs []Value, target BasicBlockID) { |
| 2119 |
switch i.opcode { |
| 2120 |
case OpcodeJump: |
| 2121 |
condVal = ValueInvalid |
| 2122 |
case OpcodeBrz, OpcodeBrnz: |
| 2123 |
condVal = i.v |
| 2124 |
default: |
| 2125 |
panic("BUG") |
| 2126 |
} |
| 2127 |
blockArgs = i.vs.View() |
| 2128 |
target = BasicBlockID(i.rValue) |
| 2129 |
return |
| 2130 |
} |
| 2131 |
|
| 2132 |
// BrTableData returns the branch table data for this instruction necessary for backends. |
| 2133 |
func (i *Instruction) BrTableData() (index Value, targets Values) { |
| 2134 |
if i.opcode != OpcodeBrTable { |
| 2135 |
panic("BUG: BrTableData only available for OpcodeBrTable") |
| 2136 |
} |
| 2137 |
index = i.v |
| 2138 |
targets = i.rValues |
| 2139 |
return |
| 2140 |
} |
| 2141 |
|
| 2142 |
// AsJump initializes this instruction as a jump instruction with OpcodeJump. |
| 2143 |
func (i *Instruction) AsJump(vs Values, target BasicBlock) *Instruction { |
| 2144 |
i.opcode = OpcodeJump |
| 2145 |
i.vs = vs |
| 2146 |
i.rValue = Value(target.ID()) |
| 2147 |
return i |
| 2148 |
} |
| 2149 |
|
| 2150 |
// IsFallthroughJump returns true if this instruction is a fallthrough jump. |
| 2151 |
func (i *Instruction) IsFallthroughJump() bool { |
| 2152 |
if i.opcode != OpcodeJump { |
| 2153 |
panic("BUG: IsFallthrough only available for OpcodeJump") |
| 2154 |
} |
| 2155 |
return i.opcode == OpcodeJump && i.u1 != 0 |
| 2156 |
} |
| 2157 |
|
| 2158 |
// AsFallthroughJump marks this instruction as a fallthrough jump. |
| 2159 |
func (i *Instruction) AsFallthroughJump() { |
| 2160 |
if i.opcode != OpcodeJump { |
| 2161 |
panic("BUG: AsFallthroughJump only available for OpcodeJump") |
| 2162 |
} |
| 2163 |
i.u1 = 1 |
| 2164 |
} |
| 2165 |
|
| 2166 |
// AsBrz initializes this instruction as a branch-if-zero instruction with OpcodeBrz. |
| 2167 |
func (i *Instruction) AsBrz(v Value, args Values, target BasicBlock) { |
| 2168 |
i.opcode = OpcodeBrz |
| 2169 |
i.v = v |
| 2170 |
i.vs = args |
| 2171 |
i.rValue = Value(target.ID()) |
| 2172 |
} |
| 2173 |
|
| 2174 |
// AsBrnz initializes this instruction as a branch-if-not-zero instruction with OpcodeBrnz. |
| 2175 |
func (i *Instruction) AsBrnz(v Value, args Values, target BasicBlock) *Instruction { |
| 2176 |
i.opcode = OpcodeBrnz |
| 2177 |
i.v = v |
| 2178 |
i.vs = args |
| 2179 |
i.rValue = Value(target.ID()) |
| 2180 |
return i |
| 2181 |
} |
| 2182 |
|
| 2183 |
// AsBrTable initializes this instruction as a branch-table instruction with OpcodeBrTable. |
| 2184 |
// targets is a list of basic block IDs cast to Values. |
| 2185 |
func (i *Instruction) AsBrTable(index Value, targets Values) { |
| 2186 |
i.opcode = OpcodeBrTable |
| 2187 |
i.v = index |
| 2188 |
i.rValues = targets |
| 2189 |
} |
| 2190 |
|
| 2191 |
// AsCall initializes this instruction as a call instruction with OpcodeCall. |
| 2192 |
func (i *Instruction) AsCall(ref FuncRef, sig *Signature, args Values) { |
| 2193 |
i.opcode = OpcodeCall |
| 2194 |
i.u1 = uint64(ref) |
| 2195 |
i.vs = args |
| 2196 |
i.u2 = uint64(sig.ID) |
| 2197 |
sig.used = true |
| 2198 |
} |
| 2199 |
|
| 2200 |
// CallData returns the call data for this instruction necessary for backends. |
| 2201 |
func (i *Instruction) CallData() (ref FuncRef, sigID SignatureID, args []Value) { |
| 2202 |
if i.opcode != OpcodeCall && i.opcode != OpcodeTailCallReturnCall { |
| 2203 |
panic("BUG: CallData only available for OpcodeCall") |
| 2204 |
} |
| 2205 |
ref = FuncRef(i.u1) |
| 2206 |
sigID = SignatureID(i.u2) |
| 2207 |
args = i.vs.View() |
| 2208 |
return |
| 2209 |
} |
| 2210 |
|
| 2211 |
// AsCallIndirect initializes this instruction as a call-indirect instruction with OpcodeCallIndirect. |
| 2212 |
func (i *Instruction) AsCallIndirect(funcPtr Value, sig *Signature, args Values) *Instruction { |
| 2213 |
i.opcode = OpcodeCallIndirect |
| 2214 |
i.typ = TypeF64 |
| 2215 |
i.vs = args |
| 2216 |
i.v = funcPtr |
| 2217 |
i.u1 = uint64(sig.ID) |
| 2218 |
sig.used = true |
| 2219 |
return i |
| 2220 |
} |
| 2221 |
|
| 2222 |
// AsCallGoRuntimeMemmove is the same as AsCallIndirect, but with a special flag set to indicate that it is a call to the Go runtime memmove function. |
| 2223 |
func (i *Instruction) AsCallGoRuntimeMemmove(funcPtr Value, sig *Signature, args Values) *Instruction { |
| 2224 |
i.AsCallIndirect(funcPtr, sig, args) |
| 2225 |
i.u2 = 1 |
| 2226 |
return i |
| 2227 |
} |
| 2228 |
|
| 2229 |
// CallIndirectData returns the call indirect data for this instruction necessary for backends. |
| 2230 |
func (i *Instruction) CallIndirectData() (funcPtr Value, sigID SignatureID, args []Value, isGoMemmove bool) { |
| 2231 |
if i.opcode != OpcodeCallIndirect && i.opcode != OpcodeTailCallReturnCallIndirect { |
| 2232 |
panic("BUG: CallIndirectData only available for OpcodeCallIndirect and OpcodeTailCallReturnCallIndirect") |
| 2233 |
} |
| 2234 |
funcPtr = i.v |
| 2235 |
sigID = SignatureID(i.u1) |
| 2236 |
args = i.vs.View() |
| 2237 |
isGoMemmove = i.u2 == 1 |
| 2238 |
return |
| 2239 |
} |
| 2240 |
|
| 2241 |
// AsClz initializes this instruction as a Count Leading Zeroes instruction with OpcodeClz. |
| 2242 |
func (i *Instruction) AsClz(x Value) { |
| 2243 |
i.opcode = OpcodeClz |
| 2244 |
i.v = x |
| 2245 |
i.typ = x.Type() |
| 2246 |
} |
| 2247 |
|
| 2248 |
// AsCtz initializes this instruction as a Count Trailing Zeroes instruction with OpcodeCtz. |
| 2249 |
func (i *Instruction) AsCtz(x Value) { |
| 2250 |
i.opcode = OpcodeCtz |
| 2251 |
i.v = x |
| 2252 |
i.typ = x.Type() |
| 2253 |
} |
| 2254 |
|
| 2255 |
// AsPopcnt initializes this instruction as a Population Count instruction with OpcodePopcnt. |
| 2256 |
func (i *Instruction) AsPopcnt(x Value) { |
| 2257 |
i.opcode = OpcodePopcnt |
| 2258 |
i.v = x |
| 2259 |
i.typ = x.Type() |
| 2260 |
} |
| 2261 |
|
| 2262 |
// AsFneg initializes this instruction as an instruction with OpcodeFneg. |
| 2263 |
func (i *Instruction) AsFneg(x Value) *Instruction { |
| 2264 |
i.opcode = OpcodeFneg |
| 2265 |
i.v = x |
| 2266 |
i.typ = x.Type() |
| 2267 |
return i |
| 2268 |
} |
| 2269 |
|
| 2270 |
// AsSqrt initializes this instruction as an instruction with OpcodeSqrt. |
| 2271 |
func (i *Instruction) AsSqrt(x Value) *Instruction { |
| 2272 |
i.opcode = OpcodeSqrt |
| 2273 |
i.v = x |
| 2274 |
i.typ = x.Type() |
| 2275 |
return i |
| 2276 |
} |
| 2277 |
|
| 2278 |
// AsFabs initializes this instruction as an instruction with OpcodeFabs. |
| 2279 |
func (i *Instruction) AsFabs(x Value) *Instruction { |
| 2280 |
i.opcode = OpcodeFabs |
| 2281 |
i.v = x |
| 2282 |
i.typ = x.Type() |
| 2283 |
return i |
| 2284 |
} |
| 2285 |
|
| 2286 |
// AsFcopysign initializes this instruction as an instruction with OpcodeFcopysign. |
| 2287 |
func (i *Instruction) AsFcopysign(x, y Value) *Instruction { |
| 2288 |
i.opcode = OpcodeFcopysign |
| 2289 |
i.v = x |
| 2290 |
i.v2 = y |
| 2291 |
i.typ = x.Type() |
| 2292 |
return i |
| 2293 |
} |
| 2294 |
|
| 2295 |
// AsCeil initializes this instruction as an instruction with OpcodeCeil. |
| 2296 |
func (i *Instruction) AsCeil(x Value) *Instruction { |
| 2297 |
i.opcode = OpcodeCeil |
| 2298 |
i.v = x |
| 2299 |
i.typ = x.Type() |
| 2300 |
return i |
| 2301 |
} |
| 2302 |
|
| 2303 |
// AsFloor initializes this instruction as an instruction with OpcodeFloor. |
| 2304 |
func (i *Instruction) AsFloor(x Value) *Instruction { |
| 2305 |
i.opcode = OpcodeFloor |
| 2306 |
i.v = x |
| 2307 |
i.typ = x.Type() |
| 2308 |
return i |
| 2309 |
} |
| 2310 |
|
| 2311 |
// AsTrunc initializes this instruction as an instruction with OpcodeTrunc. |
| 2312 |
func (i *Instruction) AsTrunc(x Value) *Instruction { |
| 2313 |
i.opcode = OpcodeTrunc |
| 2314 |
i.v = x |
| 2315 |
i.typ = x.Type() |
| 2316 |
return i |
| 2317 |
} |
| 2318 |
|
| 2319 |
// AsNearest initializes this instruction as an instruction with OpcodeNearest. |
| 2320 |
func (i *Instruction) AsNearest(x Value) *Instruction { |
| 2321 |
i.opcode = OpcodeNearest |
| 2322 |
i.v = x |
| 2323 |
i.typ = x.Type() |
| 2324 |
return i |
| 2325 |
} |
| 2326 |
|
| 2327 |
// AsBitcast initializes this instruction as an instruction with OpcodeBitcast. |
| 2328 |
func (i *Instruction) AsBitcast(x Value, dstType Type) *Instruction { |
| 2329 |
i.opcode = OpcodeBitcast |
| 2330 |
i.v = x |
| 2331 |
i.typ = dstType |
| 2332 |
return i |
| 2333 |
} |
| 2334 |
|
| 2335 |
// BitcastData returns the operands for a bitcast instruction. |
| 2336 |
func (i *Instruction) BitcastData() (x Value, dstType Type) { |
| 2337 |
return i.v, i.typ |
| 2338 |
} |
| 2339 |
|
| 2340 |
// AsFdemote initializes this instruction as an instruction with OpcodeFdemote. |
| 2341 |
func (i *Instruction) AsFdemote(x Value) { |
| 2342 |
i.opcode = OpcodeFdemote |
| 2343 |
i.v = x |
| 2344 |
i.typ = TypeF32 |
| 2345 |
} |
| 2346 |
|
| 2347 |
// AsFpromote initializes this instruction as an instruction with OpcodeFpromote. |
| 2348 |
func (i *Instruction) AsFpromote(x Value) { |
| 2349 |
i.opcode = OpcodeFpromote |
| 2350 |
i.v = x |
| 2351 |
i.typ = TypeF64 |
| 2352 |
} |
| 2353 |
|
| 2354 |
// AsFcvtFromInt initializes this instruction as an instruction with either OpcodeFcvtFromUint or OpcodeFcvtFromSint |
| 2355 |
func (i *Instruction) AsFcvtFromInt(x Value, signed bool, dst64bit bool) *Instruction { |
| 2356 |
if signed { |
| 2357 |
i.opcode = OpcodeFcvtFromSint |
| 2358 |
} else { |
| 2359 |
i.opcode = OpcodeFcvtFromUint |
| 2360 |
} |
| 2361 |
i.v = x |
| 2362 |
if dst64bit { |
| 2363 |
i.typ = TypeF64 |
| 2364 |
} else { |
| 2365 |
i.typ = TypeF32 |
| 2366 |
} |
| 2367 |
return i |
| 2368 |
} |
| 2369 |
|
| 2370 |
// AsFcvtToInt initializes this instruction as an instruction with either OpcodeFcvtToUint or OpcodeFcvtToSint |
| 2371 |
func (i *Instruction) AsFcvtToInt(x, ctx Value, signed bool, dst64bit bool, sat bool) *Instruction { |
| 2372 |
switch { |
| 2373 |
case signed && !sat: |
| 2374 |
i.opcode = OpcodeFcvtToSint |
| 2375 |
case !signed && !sat: |
| 2376 |
i.opcode = OpcodeFcvtToUint |
| 2377 |
case signed && sat: |
| 2378 |
i.opcode = OpcodeFcvtToSintSat |
| 2379 |
case !signed && sat: |
| 2380 |
i.opcode = OpcodeFcvtToUintSat |
| 2381 |
} |
| 2382 |
i.v = x |
| 2383 |
i.v2 = ctx |
| 2384 |
if dst64bit { |
| 2385 |
i.typ = TypeI64 |
| 2386 |
} else { |
| 2387 |
i.typ = TypeI32 |
| 2388 |
} |
| 2389 |
return i |
| 2390 |
} |
| 2391 |
|
| 2392 |
// AsVFcvtToIntSat initializes this instruction as an instruction with either OpcodeVFcvtToSintSat or OpcodeVFcvtToUintSat |
| 2393 |
func (i *Instruction) AsVFcvtToIntSat(x Value, lane VecLane, signed bool) *Instruction { |
| 2394 |
if signed { |
| 2395 |
i.opcode = OpcodeVFcvtToSintSat |
| 2396 |
} else { |
| 2397 |
i.opcode = OpcodeVFcvtToUintSat |
| 2398 |
} |
| 2399 |
i.v = x |
| 2400 |
i.u1 = uint64(lane) |
| 2401 |
return i |
| 2402 |
} |
| 2403 |
|
| 2404 |
// AsVFcvtFromInt initializes this instruction as an instruction with either OpcodeVFcvtToSintSat or OpcodeVFcvtToUintSat |
| 2405 |
func (i *Instruction) AsVFcvtFromInt(x Value, lane VecLane, signed bool) *Instruction { |
| 2406 |
if signed { |
| 2407 |
i.opcode = OpcodeVFcvtFromSint |
| 2408 |
} else { |
| 2409 |
i.opcode = OpcodeVFcvtFromUint |
| 2410 |
} |
| 2411 |
i.v = x |
| 2412 |
i.u1 = uint64(lane) |
| 2413 |
return i |
| 2414 |
} |
| 2415 |
|
| 2416 |
// AsNarrow initializes this instruction as an instruction with either OpcodeSnarrow or OpcodeUnarrow |
| 2417 |
func (i *Instruction) AsNarrow(x, y Value, lane VecLane, signed bool) *Instruction { |
| 2418 |
if signed { |
| 2419 |
i.opcode = OpcodeSnarrow |
| 2420 |
} else { |
| 2421 |
i.opcode = OpcodeUnarrow |
| 2422 |
} |
| 2423 |
i.v = x |
| 2424 |
i.v2 = y |
| 2425 |
i.u1 = uint64(lane) |
| 2426 |
return i |
| 2427 |
} |
| 2428 |
|
| 2429 |
// AsFvpromoteLow initializes this instruction as an instruction with OpcodeFvpromoteLow |
| 2430 |
func (i *Instruction) AsFvpromoteLow(x Value, lane VecLane) *Instruction { |
| 2431 |
i.opcode = OpcodeFvpromoteLow |
| 2432 |
i.v = x |
| 2433 |
i.u1 = uint64(lane) |
| 2434 |
return i |
| 2435 |
} |
| 2436 |
|
| 2437 |
// AsFvdemote initializes this instruction as an instruction with OpcodeFvdemote |
| 2438 |
func (i *Instruction) AsFvdemote(x Value, lane VecLane) *Instruction { |
| 2439 |
i.opcode = OpcodeFvdemote |
| 2440 |
i.v = x |
| 2441 |
i.u1 = uint64(lane) |
| 2442 |
return i |
| 2443 |
} |
| 2444 |
|
| 2445 |
// AsSExtend initializes this instruction as a sign extension instruction with OpcodeSExtend. |
| 2446 |
func (i *Instruction) AsSExtend(v Value, from, to byte) *Instruction { |
| 2447 |
i.opcode = OpcodeSExtend |
| 2448 |
i.v = v |
| 2449 |
i.u1 = uint64(from)<<8 | uint64(to) |
| 2450 |
if to == 64 { |
| 2451 |
i.typ = TypeI64 |
| 2452 |
} else { |
| 2453 |
i.typ = TypeI32 |
| 2454 |
} |
| 2455 |
return i |
| 2456 |
} |
| 2457 |
|
| 2458 |
// AsUExtend initializes this instruction as an unsigned extension instruction with OpcodeUExtend. |
| 2459 |
func (i *Instruction) AsUExtend(v Value, from, to byte) *Instruction { |
| 2460 |
i.opcode = OpcodeUExtend |
| 2461 |
i.v = v |
| 2462 |
i.u1 = uint64(from)<<8 | uint64(to) |
| 2463 |
if to == 64 { |
| 2464 |
i.typ = TypeI64 |
| 2465 |
} else { |
| 2466 |
i.typ = TypeI32 |
| 2467 |
} |
| 2468 |
return i |
| 2469 |
} |
| 2470 |
|
| 2471 |
func (i *Instruction) ExtendData() (from, to byte, signed bool) { |
| 2472 |
if i.opcode != OpcodeSExtend && i.opcode != OpcodeUExtend { |
| 2473 |
panic("BUG: ExtendData only available for OpcodeSExtend and OpcodeUExtend") |
| 2474 |
} |
| 2475 |
from = byte(i.u1 >> 8) |
| 2476 |
to = byte(i.u1) |
| 2477 |
signed = i.opcode == OpcodeSExtend |
| 2478 |
return |
| 2479 |
} |
| 2480 |
|
| 2481 |
// AsSelect initializes this instruction as an unsigned extension instruction with OpcodeSelect. |
| 2482 |
func (i *Instruction) AsSelect(c, x, y Value) *Instruction { |
| 2483 |
i.opcode = OpcodeSelect |
| 2484 |
i.v = c |
| 2485 |
i.v2 = x |
| 2486 |
i.v3 = y |
| 2487 |
i.typ = x.Type() |
| 2488 |
return i |
| 2489 |
} |
| 2490 |
|
| 2491 |
// SelectData returns the select data for this instruction necessary for backends. |
| 2492 |
func (i *Instruction) SelectData() (c, x, y Value) { |
| 2493 |
c = i.v |
| 2494 |
x = i.v2 |
| 2495 |
y = i.v3 |
| 2496 |
return |
| 2497 |
} |
| 2498 |
|
| 2499 |
// ExtendFromToBits returns the from and to bit size for the extension instruction. |
| 2500 |
func (i *Instruction) ExtendFromToBits() (from, to byte) { |
| 2501 |
from = byte(i.u1 >> 8) |
| 2502 |
to = byte(i.u1) |
| 2503 |
return |
| 2504 |
} |
| 2505 |
|
| 2506 |
// Format returns a string representation of this instruction with the given builder. |
| 2507 |
// For debugging purposes only. |
| 2508 |
func (i *Instruction) Format(b Builder) string { |
| 2509 |
var instSuffix string |
| 2510 |
switch i.opcode { |
| 2511 |
case OpcodeExitWithCode: |
| 2512 |
instSuffix = fmt.Sprintf(" %s, %s", i.v.Format(b), wazevoapi.ExitCode(i.u1)) |
| 2513 |
case OpcodeExitIfTrueWithCode: |
| 2514 |
instSuffix = fmt.Sprintf(" %s, %s, %s", i.v2.Format(b), i.v.Format(b), wazevoapi.ExitCode(i.u1)) |
| 2515 |
case OpcodeIadd, OpcodeIsub, OpcodeImul, OpcodeFadd, OpcodeFsub, OpcodeFmin, OpcodeFmax, OpcodeFdiv, OpcodeFmul: |
| 2516 |
instSuffix = fmt.Sprintf(" %s, %s", i.v.Format(b), i.v2.Format(b)) |
| 2517 |
case OpcodeIcmp: |
| 2518 |
instSuffix = fmt.Sprintf(" %s, %s, %s", IntegerCmpCond(i.u1), i.v.Format(b), i.v2.Format(b)) |
| 2519 |
case OpcodeFcmp: |
| 2520 |
instSuffix = fmt.Sprintf(" %s, %s, %s", FloatCmpCond(i.u1), i.v.Format(b), i.v2.Format(b)) |
| 2521 |
case OpcodeSExtend, OpcodeUExtend: |
| 2522 |
instSuffix = fmt.Sprintf(" %s, %d->%d", i.v.Format(b), i.u1>>8, i.u1&0xff) |
| 2523 |
case OpcodeCall, OpcodeCallIndirect: |
| 2524 |
view := i.vs.View() |
| 2525 |
vs := make([]string, len(view)) |
| 2526 |
for idx := range vs { |
| 2527 |
vs[idx] = view[idx].Format(b) |
| 2528 |
} |
| 2529 |
if i.opcode == OpcodeCallIndirect { |
| 2530 |
instSuffix = fmt.Sprintf(" %s:%s, %s", i.v.Format(b), SignatureID(i.u1), strings.Join(vs, ", ")) |
| 2531 |
} else { |
| 2532 |
instSuffix = fmt.Sprintf(" %s:%s, %s", FuncRef(i.u1), SignatureID(i.u2), strings.Join(vs, ", ")) |
| 2533 |
} |
| 2534 |
case OpcodeStore, OpcodeIstore8, OpcodeIstore16, OpcodeIstore32: |
| 2535 |
instSuffix = fmt.Sprintf(" %s, %s, %#x", i.v.Format(b), i.v2.Format(b), uint32(i.u1)) |
| 2536 |
case OpcodeLoad, OpcodeVZeroExtLoad: |
| 2537 |
instSuffix = fmt.Sprintf(" %s, %#x", i.v.Format(b), int32(i.u1)) |
| 2538 |
case OpcodeLoadSplat: |
| 2539 |
instSuffix = fmt.Sprintf(".%s %s, %#x", VecLane(i.u2), i.v.Format(b), int32(i.u1)) |
| 2540 |
case OpcodeUload8, OpcodeUload16, OpcodeUload32, OpcodeSload8, OpcodeSload16, OpcodeSload32: |
| 2541 |
instSuffix = fmt.Sprintf(" %s, %#x", i.v.Format(b), int32(i.u1)) |
| 2542 |
case OpcodeSelect, OpcodeVbitselect: |
| 2543 |
instSuffix = fmt.Sprintf(" %s, %s, %s", i.v.Format(b), i.v2.Format(b), i.v3.Format(b)) |
| 2544 |
case OpcodeIconst: |
| 2545 |
switch i.typ { |
| 2546 |
case TypeI32: |
| 2547 |
instSuffix = fmt.Sprintf("_32 %#x", uint32(i.u1)) |
| 2548 |
case TypeI64: |
| 2549 |
instSuffix = fmt.Sprintf("_64 %#x", i.u1) |
| 2550 |
} |
| 2551 |
case OpcodeVconst: |
| 2552 |
instSuffix = fmt.Sprintf(" %016x %016x", i.u1, i.u2) |
| 2553 |
case OpcodeF32const: |
| 2554 |
instSuffix = fmt.Sprintf(" %f", math.Float32frombits(uint32(i.u1))) |
| 2555 |
case OpcodeF64const: |
| 2556 |
instSuffix = fmt.Sprintf(" %f", math.Float64frombits(i.u1)) |
| 2557 |
case OpcodeReturn: |
| 2558 |
view := i.vs.View() |
| 2559 |
if len(view) == 0 { |
| 2560 |
break |
| 2561 |
} |
| 2562 |
vs := make([]string, len(view)) |
| 2563 |
for idx := range vs { |
| 2564 |
vs[idx] = view[idx].Format(b) |
| 2565 |
} |
| 2566 |
instSuffix = fmt.Sprintf(" %s", strings.Join(vs, ", ")) |
| 2567 |
case OpcodeJump: |
| 2568 |
view := i.vs.View() |
| 2569 |
vs := make([]string, len(view)+1) |
| 2570 |
if i.IsFallthroughJump() { |
| 2571 |
vs[0] = " fallthrough" |
| 2572 |
} else { |
| 2573 |
blockId := BasicBlockID(i.rValue) |
| 2574 |
vs[0] = " " + b.BasicBlock(blockId).Name() |
| 2575 |
} |
| 2576 |
for idx := range view { |
| 2577 |
vs[idx+1] = view[idx].Format(b) |
| 2578 |
} |
| 2579 |
|
| 2580 |
instSuffix = strings.Join(vs, ", ") |
| 2581 |
case OpcodeBrz, OpcodeBrnz: |
| 2582 |
view := i.vs.View() |
| 2583 |
vs := make([]string, len(view)+2) |
| 2584 |
vs[0] = " " + i.v.Format(b) |
| 2585 |
blockId := BasicBlockID(i.rValue) |
| 2586 |
vs[1] = b.BasicBlock(blockId).Name() |
| 2587 |
for idx := range view { |
| 2588 |
vs[idx+2] = view[idx].Format(b) |
| 2589 |
} |
| 2590 |
instSuffix = strings.Join(vs, ", ") |
| 2591 |
case OpcodeBrTable: |
| 2592 |
// `BrTable index, [label1, label2, ... labelN]` |
| 2593 |
instSuffix = fmt.Sprintf(" %s", i.v.Format(b)) |
| 2594 |
instSuffix += ", [" |
| 2595 |
for i, target := range i.rValues.View() { |
| 2596 |
blk := b.BasicBlock(BasicBlockID(target)) |
| 2597 |
if i == 0 { |
| 2598 |
instSuffix += blk.Name() |
| 2599 |
} else { |
| 2600 |
instSuffix += ", " + blk.Name() |
| 2601 |
} |
| 2602 |
} |
| 2603 |
instSuffix += "]" |
| 2604 |
case OpcodeBand, OpcodeBor, OpcodeBxor, OpcodeRotr, OpcodeRotl, OpcodeIshl, OpcodeSshr, OpcodeUshr, |
| 2605 |
OpcodeSdiv, OpcodeUdiv, OpcodeFcopysign, OpcodeSrem, OpcodeUrem, |
| 2606 |
OpcodeVbnot, OpcodeVbxor, OpcodeVbor, OpcodeVband, OpcodeVbandnot, OpcodeVIcmp, OpcodeVFcmp: |
| 2607 |
instSuffix = fmt.Sprintf(" %s, %s", i.v.Format(b), i.v2.Format(b)) |
| 2608 |
case OpcodeUndefined: |
| 2609 |
case OpcodeClz, OpcodeCtz, OpcodePopcnt, OpcodeFneg, OpcodeFcvtToSint, OpcodeFcvtToUint, OpcodeFcvtFromSint, |
| 2610 |
OpcodeFcvtFromUint, OpcodeFcvtToSintSat, OpcodeFcvtToUintSat, OpcodeFdemote, OpcodeFpromote, OpcodeIreduce, OpcodeBitcast, OpcodeSqrt, OpcodeFabs, |
| 2611 |
OpcodeCeil, OpcodeFloor, OpcodeTrunc, OpcodeNearest: |
| 2612 |
instSuffix = " " + i.v.Format(b) |
| 2613 |
case OpcodeVIadd, OpcodeExtIaddPairwise, OpcodeVSaddSat, OpcodeVUaddSat, OpcodeVIsub, OpcodeVSsubSat, OpcodeVUsubSat, |
| 2614 |
OpcodeVImin, OpcodeVUmin, OpcodeVImax, OpcodeVUmax, OpcodeVImul, OpcodeVAvgRound, |
| 2615 |
OpcodeVFadd, OpcodeVFsub, OpcodeVFmul, OpcodeVFdiv, |
| 2616 |
OpcodeVIshl, OpcodeVSshr, OpcodeVUshr, |
| 2617 |
OpcodeVFmin, OpcodeVFmax, OpcodeVMinPseudo, OpcodeVMaxPseudo, |
| 2618 |
OpcodeSnarrow, OpcodeUnarrow, OpcodeSwizzle, OpcodeSqmulRoundSat: |
| 2619 |
instSuffix = fmt.Sprintf(".%s %s, %s", VecLane(i.u1), i.v.Format(b), i.v2.Format(b)) |
| 2620 |
case OpcodeVIabs, OpcodeVIneg, OpcodeVIpopcnt, OpcodeVhighBits, OpcodeVallTrue, OpcodeVanyTrue, |
| 2621 |
OpcodeVFabs, OpcodeVFneg, OpcodeVSqrt, OpcodeVCeil, OpcodeVFloor, OpcodeVTrunc, OpcodeVNearest, |
| 2622 |
OpcodeVFcvtToUintSat, OpcodeVFcvtToSintSat, OpcodeVFcvtFromUint, OpcodeVFcvtFromSint, |
| 2623 |
OpcodeFvpromoteLow, OpcodeFvdemote, OpcodeSwidenLow, OpcodeUwidenLow, OpcodeSwidenHigh, OpcodeUwidenHigh, |
| 2624 |
OpcodeSplat: |
| 2625 |
instSuffix = fmt.Sprintf(".%s %s", VecLane(i.u1), i.v.Format(b)) |
| 2626 |
case OpcodeExtractlane: |
| 2627 |
var signedness string |
| 2628 |
if i.u1 != 0 { |
| 2629 |
signedness = "signed" |
| 2630 |
} else { |
| 2631 |
signedness = "unsigned" |
| 2632 |
} |
| 2633 |
instSuffix = fmt.Sprintf(".%s %d, %s (%s)", VecLane(i.u2), 0x0000FFFF&i.u1, i.v.Format(b), signedness) |
| 2634 |
case OpcodeInsertlane: |
| 2635 |
instSuffix = fmt.Sprintf(".%s %d, %s, %s", VecLane(i.u2), i.u1, i.v.Format(b), i.v2.Format(b)) |
| 2636 |
case OpcodeShuffle: |
| 2637 |
lanes := make([]byte, 16) |
| 2638 |
for idx := 0; idx < 8; idx++ { |
| 2639 |
lanes[idx] = byte(i.u1 >> (8 * idx)) |
| 2640 |
} |
| 2641 |
for idx := 0; idx < 8; idx++ { |
| 2642 |
lanes[idx+8] = byte(i.u2 >> (8 * idx)) |
| 2643 |
} |
| 2644 |
// Prints Shuffle.[0 1 2 3 4 5 6 7 ...] v2, v3 |
| 2645 |
instSuffix = fmt.Sprintf(".%v %s, %s", lanes, i.v.Format(b), i.v2.Format(b)) |
| 2646 |
case OpcodeAtomicRmw: |
| 2647 |
instSuffix = fmt.Sprintf(" %s_%d, %s, %s", AtomicRmwOp(i.u1), 8*i.u2, i.v.Format(b), i.v2.Format(b)) |
| 2648 |
case OpcodeAtomicLoad: |
| 2649 |
instSuffix = fmt.Sprintf("_%d, %s", 8*i.u1, i.v.Format(b)) |
| 2650 |
case OpcodeAtomicStore: |
| 2651 |
instSuffix = fmt.Sprintf("_%d, %s, %s", 8*i.u1, i.v.Format(b), i.v2.Format(b)) |
| 2652 |
case OpcodeAtomicCas: |
| 2653 |
instSuffix = fmt.Sprintf("_%d, %s, %s, %s", 8*i.u1, i.v.Format(b), i.v2.Format(b), i.v3.Format(b)) |
| 2654 |
case OpcodeFence: |
| 2655 |
instSuffix = fmt.Sprintf(" %d", i.u1) |
| 2656 |
case OpcodeTailCallReturnCall, OpcodeTailCallReturnCallIndirect: |
| 2657 |
view := i.vs.View() |
| 2658 |
vs := make([]string, len(view)) |
| 2659 |
for idx := range vs { |
| 2660 |
vs[idx] = view[idx].Format(b) |
| 2661 |
} |
| 2662 |
if i.opcode == OpcodeCallIndirect { |
| 2663 |
instSuffix = fmt.Sprintf(" %s:%s, %s", i.v.Format(b), SignatureID(i.u1), strings.Join(vs, ", ")) |
| 2664 |
} else { |
| 2665 |
instSuffix = fmt.Sprintf(" %s:%s, %s", FuncRef(i.u1), SignatureID(i.u2), strings.Join(vs, ", ")) |
| 2666 |
} |
| 2667 |
case OpcodeWideningPairwiseDotProductS: |
| 2668 |
instSuffix = fmt.Sprintf(" %s, %s", i.v.Format(b), i.v2.Format(b)) |
| 2669 |
default: |
| 2670 |
panic(fmt.Sprintf("TODO: format for %s", i.opcode)) |
| 2671 |
} |
| 2672 |
|
| 2673 |
instr := i.opcode.String() + instSuffix |
| 2674 |
|
| 2675 |
var rvs []string |
| 2676 |
r1, rs := i.Returns() |
| 2677 |
if r1.Valid() { |
| 2678 |
rvs = append(rvs, r1.formatWithType(b)) |
| 2679 |
} |
| 2680 |
|
| 2681 |
for _, v := range rs { |
| 2682 |
rvs = append(rvs, v.formatWithType(b)) |
| 2683 |
} |
| 2684 |
|
| 2685 |
if len(rvs) > 0 { |
| 2686 |
return fmt.Sprintf("%s = %s", strings.Join(rvs, ", "), instr) |
| 2687 |
} else { |
| 2688 |
return instr |
| 2689 |
} |
| 2690 |
} |
| 2691 |
|
| 2692 |
// addArgumentBranchInst adds an argument to this instruction. |
| 2693 |
func (i *Instruction) addArgumentBranchInst(b *builder, v Value) { |
| 2694 |
switch i.opcode { |
| 2695 |
case OpcodeJump, OpcodeBrz, OpcodeBrnz: |
| 2696 |
i.vs = i.vs.Append(&b.varLengthPool, v) |
| 2697 |
default: |
| 2698 |
panic("BUG: " + i.opcode.String()) |
| 2699 |
} |
| 2700 |
} |
| 2701 |
|
| 2702 |
// Constant returns true if this instruction is a constant instruction. |
| 2703 |
func (i *Instruction) Constant() bool { |
| 2704 |
switch i.opcode { |
| 2705 |
case OpcodeIconst, OpcodeF32const, OpcodeF64const: |
| 2706 |
return true |
| 2707 |
} |
| 2708 |
return false |
| 2709 |
} |
| 2710 |
|
| 2711 |
// ConstantVal returns the constant value of this instruction. |
| 2712 |
// How to interpret the return value depends on the opcode. |
| 2713 |
func (i *Instruction) ConstantVal() (ret uint64) { |
| 2714 |
switch i.opcode { |
| 2715 |
case OpcodeIconst, OpcodeF32const, OpcodeF64const: |
| 2716 |
ret = i.u1 |
| 2717 |
default: |
| 2718 |
panic("TODO") |
| 2719 |
} |
| 2720 |
return |
| 2721 |
} |
| 2722 |
|
| 2723 |
// String implements fmt.Stringer. |
| 2724 |
func (o Opcode) String() (ret string) { |
| 2725 |
switch o { |
| 2726 |
case OpcodeInvalid: |
| 2727 |
return "invalid" |
| 2728 |
case OpcodeUndefined: |
| 2729 |
return "Undefined" |
| 2730 |
case OpcodeJump: |
| 2731 |
return "Jump" |
| 2732 |
case OpcodeBrz: |
| 2733 |
return "Brz" |
| 2734 |
case OpcodeBrnz: |
| 2735 |
return "Brnz" |
| 2736 |
case OpcodeBrTable: |
| 2737 |
return "BrTable" |
| 2738 |
case OpcodeExitWithCode: |
| 2739 |
return "Exit" |
| 2740 |
case OpcodeExitIfTrueWithCode: |
| 2741 |
return "ExitIfTrue" |
| 2742 |
case OpcodeReturn: |
| 2743 |
return "Return" |
| 2744 |
case OpcodeCall: |
| 2745 |
return "Call" |
| 2746 |
case OpcodeCallIndirect: |
| 2747 |
return "CallIndirect" |
| 2748 |
case OpcodeSplat: |
| 2749 |
return "Splat" |
| 2750 |
case OpcodeSwizzle: |
| 2751 |
return "Swizzle" |
| 2752 |
case OpcodeInsertlane: |
| 2753 |
return "Insertlane" |
| 2754 |
case OpcodeExtractlane: |
| 2755 |
return "Extractlane" |
| 2756 |
case OpcodeLoad: |
| 2757 |
return "Load" |
| 2758 |
case OpcodeLoadSplat: |
| 2759 |
return "LoadSplat" |
| 2760 |
case OpcodeStore: |
| 2761 |
return "Store" |
| 2762 |
case OpcodeUload8: |
| 2763 |
return "Uload8" |
| 2764 |
case OpcodeSload8: |
| 2765 |
return "Sload8" |
| 2766 |
case OpcodeIstore8: |
| 2767 |
return "Istore8" |
| 2768 |
case OpcodeUload16: |
| 2769 |
return "Uload16" |
| 2770 |
case OpcodeSload16: |
| 2771 |
return "Sload16" |
| 2772 |
case OpcodeIstore16: |
| 2773 |
return "Istore16" |
| 2774 |
case OpcodeUload32: |
| 2775 |
return "Uload32" |
| 2776 |
case OpcodeSload32: |
| 2777 |
return "Sload32" |
| 2778 |
case OpcodeIstore32: |
| 2779 |
return "Istore32" |
| 2780 |
case OpcodeIconst: |
| 2781 |
return "Iconst" |
| 2782 |
case OpcodeF32const: |
| 2783 |
return "F32const" |
| 2784 |
case OpcodeF64const: |
| 2785 |
return "F64const" |
| 2786 |
case OpcodeVconst: |
| 2787 |
return "Vconst" |
| 2788 |
case OpcodeShuffle: |
| 2789 |
return "Shuffle" |
| 2790 |
case OpcodeSelect: |
| 2791 |
return "Select" |
| 2792 |
case OpcodeVanyTrue: |
| 2793 |
return "VanyTrue" |
| 2794 |
case OpcodeVallTrue: |
| 2795 |
return "VallTrue" |
| 2796 |
case OpcodeVhighBits: |
| 2797 |
return "VhighBits" |
| 2798 |
case OpcodeIcmp: |
| 2799 |
return "Icmp" |
| 2800 |
case OpcodeIcmpImm: |
| 2801 |
return "IcmpImm" |
| 2802 |
case OpcodeVIcmp: |
| 2803 |
return "VIcmp" |
| 2804 |
case OpcodeIadd: |
| 2805 |
return "Iadd" |
| 2806 |
case OpcodeIsub: |
| 2807 |
return "Isub" |
| 2808 |
case OpcodeImul: |
| 2809 |
return "Imul" |
| 2810 |
case OpcodeUdiv: |
| 2811 |
return "Udiv" |
| 2812 |
case OpcodeSdiv: |
| 2813 |
return "Sdiv" |
| 2814 |
case OpcodeUrem: |
| 2815 |
return "Urem" |
| 2816 |
case OpcodeSrem: |
| 2817 |
return "Srem" |
| 2818 |
case OpcodeBand: |
| 2819 |
return "Band" |
| 2820 |
case OpcodeBor: |
| 2821 |
return "Bor" |
| 2822 |
case OpcodeBxor: |
| 2823 |
return "Bxor" |
| 2824 |
case OpcodeBnot: |
| 2825 |
return "Bnot" |
| 2826 |
case OpcodeRotl: |
| 2827 |
return "Rotl" |
| 2828 |
case OpcodeRotr: |
| 2829 |
return "Rotr" |
| 2830 |
case OpcodeIshl: |
| 2831 |
return "Ishl" |
| 2832 |
case OpcodeUshr: |
| 2833 |
return "Ushr" |
| 2834 |
case OpcodeSshr: |
| 2835 |
return "Sshr" |
| 2836 |
case OpcodeClz: |
| 2837 |
return "Clz" |
| 2838 |
case OpcodeCtz: |
| 2839 |
return "Ctz" |
| 2840 |
case OpcodePopcnt: |
| 2841 |
return "Popcnt" |
| 2842 |
case OpcodeFcmp: |
| 2843 |
return "Fcmp" |
| 2844 |
case OpcodeFadd: |
| 2845 |
return "Fadd" |
| 2846 |
case OpcodeFsub: |
| 2847 |
return "Fsub" |
| 2848 |
case OpcodeFmul: |
| 2849 |
return "Fmul" |
| 2850 |
case OpcodeFdiv: |
| 2851 |
return "Fdiv" |
| 2852 |
case OpcodeSqmulRoundSat: |
| 2853 |
return "SqmulRoundSat" |
| 2854 |
case OpcodeSqrt: |
| 2855 |
return "Sqrt" |
| 2856 |
case OpcodeFneg: |
| 2857 |
return "Fneg" |
| 2858 |
case OpcodeFabs: |
| 2859 |
return "Fabs" |
| 2860 |
case OpcodeFcopysign: |
| 2861 |
return "Fcopysign" |
| 2862 |
case OpcodeFmin: |
| 2863 |
return "Fmin" |
| 2864 |
case OpcodeFmax: |
| 2865 |
return "Fmax" |
| 2866 |
case OpcodeCeil: |
| 2867 |
return "Ceil" |
| 2868 |
case OpcodeFloor: |
| 2869 |
return "Floor" |
| 2870 |
case OpcodeTrunc: |
| 2871 |
return "Trunc" |
| 2872 |
case OpcodeNearest: |
| 2873 |
return "Nearest" |
| 2874 |
case OpcodeBitcast: |
| 2875 |
return "Bitcast" |
| 2876 |
case OpcodeIreduce: |
| 2877 |
return "Ireduce" |
| 2878 |
case OpcodeSnarrow: |
| 2879 |
return "Snarrow" |
| 2880 |
case OpcodeUnarrow: |
| 2881 |
return "Unarrow" |
| 2882 |
case OpcodeSwidenLow: |
| 2883 |
return "SwidenLow" |
| 2884 |
case OpcodeSwidenHigh: |
| 2885 |
return "SwidenHigh" |
| 2886 |
case OpcodeUwidenLow: |
| 2887 |
return "UwidenLow" |
| 2888 |
case OpcodeUwidenHigh: |
| 2889 |
return "UwidenHigh" |
| 2890 |
case OpcodeExtIaddPairwise: |
| 2891 |
return "IaddPairwise" |
| 2892 |
case OpcodeWideningPairwiseDotProductS: |
| 2893 |
return "WideningPairwiseDotProductS" |
| 2894 |
case OpcodeUExtend: |
| 2895 |
return "UExtend" |
| 2896 |
case OpcodeSExtend: |
| 2897 |
return "SExtend" |
| 2898 |
case OpcodeFpromote: |
| 2899 |
return "Fpromote" |
| 2900 |
case OpcodeFdemote: |
| 2901 |
return "Fdemote" |
| 2902 |
case OpcodeFvdemote: |
| 2903 |
return "Fvdemote" |
| 2904 |
case OpcodeFcvtToUint: |
| 2905 |
return "FcvtToUint" |
| 2906 |
case OpcodeFcvtToSint: |
| 2907 |
return "FcvtToSint" |
| 2908 |
case OpcodeFcvtToUintSat: |
| 2909 |
return "FcvtToUintSat" |
| 2910 |
case OpcodeFcvtToSintSat: |
| 2911 |
return "FcvtToSintSat" |
| 2912 |
case OpcodeFcvtFromUint: |
| 2913 |
return "FcvtFromUint" |
| 2914 |
case OpcodeFcvtFromSint: |
| 2915 |
return "FcvtFromSint" |
| 2916 |
case OpcodeAtomicRmw: |
| 2917 |
return "AtomicRmw" |
| 2918 |
case OpcodeAtomicCas: |
| 2919 |
return "AtomicCas" |
| 2920 |
case OpcodeAtomicLoad: |
| 2921 |
return "AtomicLoad" |
| 2922 |
case OpcodeAtomicStore: |
| 2923 |
return "AtomicStore" |
| 2924 |
case OpcodeFence: |
| 2925 |
return "Fence" |
| 2926 |
case OpcodeTailCallReturnCall: |
| 2927 |
return "ReturnCall" |
| 2928 |
case OpcodeTailCallReturnCallIndirect: |
| 2929 |
return "ReturnCallIndirect" |
| 2930 |
case OpcodeVbor: |
| 2931 |
return "Vbor" |
| 2932 |
case OpcodeVbxor: |
| 2933 |
return "Vbxor" |
| 2934 |
case OpcodeVband: |
| 2935 |
return "Vband" |
| 2936 |
case OpcodeVbandnot: |
| 2937 |
return "Vbandnot" |
| 2938 |
case OpcodeVbnot: |
| 2939 |
return "Vbnot" |
| 2940 |
case OpcodeVbitselect: |
| 2941 |
return "Vbitselect" |
| 2942 |
case OpcodeVIadd: |
| 2943 |
return "VIadd" |
| 2944 |
case OpcodeVSaddSat: |
| 2945 |
return "VSaddSat" |
| 2946 |
case OpcodeVUaddSat: |
| 2947 |
return "VUaddSat" |
| 2948 |
case OpcodeVSsubSat: |
| 2949 |
return "VSsubSat" |
| 2950 |
case OpcodeVUsubSat: |
| 2951 |
return "VUsubSat" |
| 2952 |
case OpcodeVAvgRound: |
| 2953 |
return "OpcodeVAvgRound" |
| 2954 |
case OpcodeVIsub: |
| 2955 |
return "VIsub" |
| 2956 |
case OpcodeVImin: |
| 2957 |
return "VImin" |
| 2958 |
case OpcodeVUmin: |
| 2959 |
return "VUmin" |
| 2960 |
case OpcodeVImax: |
| 2961 |
return "VImax" |
| 2962 |
case OpcodeVUmax: |
| 2963 |
return "VUmax" |
| 2964 |
case OpcodeVImul: |
| 2965 |
return "VImul" |
| 2966 |
case OpcodeVIabs: |
| 2967 |
return "VIabs" |
| 2968 |
case OpcodeVIneg: |
| 2969 |
return "VIneg" |
| 2970 |
case OpcodeVIpopcnt: |
| 2971 |
return "VIpopcnt" |
| 2972 |
case OpcodeVIshl: |
| 2973 |
return "VIshl" |
| 2974 |
case OpcodeVUshr: |
| 2975 |
return "VUshr" |
| 2976 |
case OpcodeVSshr: |
| 2977 |
return "VSshr" |
| 2978 |
case OpcodeVFabs: |
| 2979 |
return "VFabs" |
| 2980 |
case OpcodeVFmax: |
| 2981 |
return "VFmax" |
| 2982 |
case OpcodeVFmin: |
| 2983 |
return "VFmin" |
| 2984 |
case OpcodeVFneg: |
| 2985 |
return "VFneg" |
| 2986 |
case OpcodeVFadd: |
| 2987 |
return "VFadd" |
| 2988 |
case OpcodeVFsub: |
| 2989 |
return "VFsub" |
| 2990 |
case OpcodeVFmul: |
| 2991 |
return "VFmul" |
| 2992 |
case OpcodeVFdiv: |
| 2993 |
return "VFdiv" |
| 2994 |
case OpcodeVFcmp: |
| 2995 |
return "VFcmp" |
| 2996 |
case OpcodeVCeil: |
| 2997 |
return "VCeil" |
| 2998 |
case OpcodeVFloor: |
| 2999 |
return "VFloor" |
| 3000 |
case OpcodeVTrunc: |
| 3001 |
return "VTrunc" |
| 3002 |
case OpcodeVNearest: |
| 3003 |
return "VNearest" |
| 3004 |
case OpcodeVMaxPseudo: |
| 3005 |
return "VMaxPseudo" |
| 3006 |
case OpcodeVMinPseudo: |
| 3007 |
return "VMinPseudo" |
| 3008 |
case OpcodeVSqrt: |
| 3009 |
return "VSqrt" |
| 3010 |
case OpcodeVFcvtToUintSat: |
| 3011 |
return "VFcvtToUintSat" |
| 3012 |
case OpcodeVFcvtToSintSat: |
| 3013 |
return "VFcvtToSintSat" |
| 3014 |
case OpcodeVFcvtFromUint: |
| 3015 |
return "VFcvtFromUint" |
| 3016 |
case OpcodeVFcvtFromSint: |
| 3017 |
return "VFcvtFromSint" |
| 3018 |
case OpcodeFvpromoteLow: |
| 3019 |
return "FvpromoteLow" |
| 3020 |
case OpcodeVZeroExtLoad: |
| 3021 |
return "VZeroExtLoad" |
| 3022 |
} |
| 3023 |
panic(fmt.Sprintf("unknown opcode %d", o)) |
| 3024 |
} |