| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
// Generic opcodes typically specify a width. The inputs and outputs |
| 8 |
// of that op are the given number of bits wide. There is no notion of |
| 9 |
// "sign", so Add32 can be used both for signed and unsigned 32-bit |
| 10 |
// addition. |
| 11 |
|
| 12 |
// Signed/unsigned is explicit with the extension ops |
| 13 |
// (SignExt*/ZeroExt*) and implicit as the arg to some opcodes |
| 14 |
// (e.g. the second argument to shifts is unsigned). If not mentioned, |
| 15 |
// all args take signed inputs, or don't care whether their inputs |
| 16 |
// are signed or unsigned. |
| 17 |
|
| 18 |
var genericOps = []opData{ |
| 19 |
// Pseudo-op. |
| 20 |
{name: "Last", argLength: -1}, // return last element of tuple; for "let" bindings |
| 21 |
|
| 22 |
// 2-input arithmetic |
| 23 |
// Types must be consistent with Go typing. Add, for example, must take two values |
| 24 |
// of the same type and produces that same type. |
| 25 |
{name: "Add8", argLength: 2, commutative: true}, // arg0 + arg1 |
| 26 |
{name: "Add16", argLength: 2, commutative: true}, |
| 27 |
{name: "Add32", argLength: 2, commutative: true}, |
| 28 |
{name: "Add64", argLength: 2, commutative: true}, |
| 29 |
{name: "AddPtr", argLength: 2}, // For address calculations. arg0 is a pointer and arg1 is an int. |
| 30 |
{name: "Add32F", argLength: 2, commutative: true}, |
| 31 |
{name: "Add64F", argLength: 2, commutative: true}, |
| 32 |
|
| 33 |
{name: "Sub8", argLength: 2}, // arg0 - arg1 |
| 34 |
{name: "Sub16", argLength: 2}, |
| 35 |
{name: "Sub32", argLength: 2}, |
| 36 |
{name: "Sub64", argLength: 2}, |
| 37 |
{name: "SubPtr", argLength: 2}, |
| 38 |
{name: "Sub32F", argLength: 2}, |
| 39 |
{name: "Sub64F", argLength: 2}, |
| 40 |
|
| 41 |
{name: "Mul8", argLength: 2, commutative: true}, // arg0 * arg1 |
| 42 |
{name: "Mul16", argLength: 2, commutative: true}, |
| 43 |
{name: "Mul32", argLength: 2, commutative: true}, |
| 44 |
{name: "Mul64", argLength: 2, commutative: true}, |
| 45 |
{name: "Mul32F", argLength: 2, commutative: true}, |
| 46 |
{name: "Mul64F", argLength: 2, commutative: true}, |
| 47 |
|
| 48 |
{name: "Div32F", argLength: 2}, // arg0 / arg1 |
| 49 |
{name: "Div64F", argLength: 2}, |
| 50 |
|
| 51 |
{name: "Hmul32", argLength: 2, commutative: true}, |
| 52 |
{name: "Hmul32u", argLength: 2, commutative: true}, |
| 53 |
{name: "Hmul64", argLength: 2, commutative: true}, |
| 54 |
{name: "Hmul64u", argLength: 2, commutative: true}, |
| 55 |
|
| 56 |
{name: "Mul32uhilo", argLength: 2, typ: "(UInt32,UInt32)", commutative: true}, // arg0 * arg1, returns (hi, lo) |
| 57 |
{name: "Mul64uhilo", argLength: 2, typ: "(UInt64,UInt64)", commutative: true}, // arg0 * arg1, returns (hi, lo) |
| 58 |
|
| 59 |
{name: "Mul32uover", argLength: 2, typ: "(UInt32,Bool)", commutative: true}, // Let x = arg0*arg1 (full 32x32-> 64 unsigned multiply), returns (uint32(x), (uint32(x) != x)) |
| 60 |
{name: "Mul64uover", argLength: 2, typ: "(UInt64,Bool)", commutative: true}, // Let x = arg0*arg1 (full 64x64->128 unsigned multiply), returns (uint64(x), (uint64(x) != x)) |
| 61 |
|
| 62 |
// Weird special instructions for use in the strength reduction of divides. |
| 63 |
// These ops compute unsigned (arg0 + arg1) / 2, correct to all |
| 64 |
// 32/64 bits, even when the intermediate result of the add has 33/65 bits. |
| 65 |
// These ops can assume arg0 >= arg1. |
| 66 |
// Note: these ops aren't commutative! |
| 67 |
{name: "Avg32u", argLength: 2, typ: "UInt32"}, // 32-bit platforms only |
| 68 |
{name: "Avg64u", argLength: 2, typ: "UInt64"}, // 64-bit platforms only |
| 69 |
|
| 70 |
// For Div16, Div32 and Div64, AuxInt non-zero means that the divisor has been proved to be not -1 |
| 71 |
// or that the dividend is not the most negative value. |
| 72 |
{name: "Div8", argLength: 2}, // arg0 / arg1, signed |
| 73 |
{name: "Div8u", argLength: 2}, // arg0 / arg1, unsigned |
| 74 |
{name: "Div16", argLength: 2, aux: "Bool"}, |
| 75 |
{name: "Div16u", argLength: 2}, |
| 76 |
{name: "Div32", argLength: 2, aux: "Bool"}, |
| 77 |
{name: "Div32u", argLength: 2}, |
| 78 |
{name: "Div64", argLength: 2, aux: "Bool"}, |
| 79 |
{name: "Div64u", argLength: 2}, |
| 80 |
{name: "Div128u", argLength: 3}, // arg0:arg1 / arg2 (128-bit divided by 64-bit), returns (q, r) |
| 81 |
|
| 82 |
// For Mod16, Mod32 and Mod64, AuxInt non-zero means that the divisor has been proved to be not -1. |
| 83 |
{name: "Mod8", argLength: 2}, // arg0 % arg1, signed |
| 84 |
{name: "Mod8u", argLength: 2}, // arg0 % arg1, unsigned |
| 85 |
{name: "Mod16", argLength: 2, aux: "Bool"}, |
| 86 |
{name: "Mod16u", argLength: 2}, |
| 87 |
{name: "Mod32", argLength: 2, aux: "Bool"}, |
| 88 |
{name: "Mod32u", argLength: 2}, |
| 89 |
{name: "Mod64", argLength: 2, aux: "Bool"}, |
| 90 |
{name: "Mod64u", argLength: 2}, |
| 91 |
|
| 92 |
{name: "And8", argLength: 2, commutative: true}, // arg0 & arg1 |
| 93 |
{name: "And16", argLength: 2, commutative: true}, |
| 94 |
{name: "And32", argLength: 2, commutative: true}, |
| 95 |
{name: "And64", argLength: 2, commutative: true}, |
| 96 |
|
| 97 |
{name: "Or8", argLength: 2, commutative: true}, // arg0 | arg1 |
| 98 |
{name: "Or16", argLength: 2, commutative: true}, |
| 99 |
{name: "Or32", argLength: 2, commutative: true}, |
| 100 |
{name: "Or64", argLength: 2, commutative: true}, |
| 101 |
|
| 102 |
{name: "Xor8", argLength: 2, commutative: true}, // arg0 ^ arg1 |
| 103 |
{name: "Xor16", argLength: 2, commutative: true}, |
| 104 |
{name: "Xor32", argLength: 2, commutative: true}, |
| 105 |
{name: "Xor64", argLength: 2, commutative: true}, |
| 106 |
|
| 107 |
// For shifts, AxB means the shifted value has A bits and the shift amount has B bits. |
| 108 |
// Shift amounts are considered unsigned. |
| 109 |
// If arg1 is known to be nonnegative and less than the number of bits in arg0, |
| 110 |
// then auxInt may be set to 1. |
| 111 |
// This enables better code generation on some platforms. |
| 112 |
{name: "Lsh8x8", argLength: 2, aux: "Bool"}, // arg0 << arg1 |
| 113 |
{name: "Lsh8x16", argLength: 2, aux: "Bool"}, |
| 114 |
{name: "Lsh8x32", argLength: 2, aux: "Bool"}, |
| 115 |
{name: "Lsh8x64", argLength: 2, aux: "Bool"}, |
| 116 |
{name: "Lsh16x8", argLength: 2, aux: "Bool"}, |
| 117 |
{name: "Lsh16x16", argLength: 2, aux: "Bool"}, |
| 118 |
{name: "Lsh16x32", argLength: 2, aux: "Bool"}, |
| 119 |
{name: "Lsh16x64", argLength: 2, aux: "Bool"}, |
| 120 |
{name: "Lsh32x8", argLength: 2, aux: "Bool"}, |
| 121 |
{name: "Lsh32x16", argLength: 2, aux: "Bool"}, |
| 122 |
{name: "Lsh32x32", argLength: 2, aux: "Bool"}, |
| 123 |
{name: "Lsh32x64", argLength: 2, aux: "Bool"}, |
| 124 |
{name: "Lsh64x8", argLength: 2, aux: "Bool"}, |
| 125 |
{name: "Lsh64x16", argLength: 2, aux: "Bool"}, |
| 126 |
{name: "Lsh64x32", argLength: 2, aux: "Bool"}, |
| 127 |
{name: "Lsh64x64", argLength: 2, aux: "Bool"}, |
| 128 |
|
| 129 |
{name: "Rsh8x8", argLength: 2, aux: "Bool"}, // arg0 >> arg1, signed |
| 130 |
{name: "Rsh8x16", argLength: 2, aux: "Bool"}, |
| 131 |
{name: "Rsh8x32", argLength: 2, aux: "Bool"}, |
| 132 |
{name: "Rsh8x64", argLength: 2, aux: "Bool"}, |
| 133 |
{name: "Rsh16x8", argLength: 2, aux: "Bool"}, |
| 134 |
{name: "Rsh16x16", argLength: 2, aux: "Bool"}, |
| 135 |
{name: "Rsh16x32", argLength: 2, aux: "Bool"}, |
| 136 |
{name: "Rsh16x64", argLength: 2, aux: "Bool"}, |
| 137 |
{name: "Rsh32x8", argLength: 2, aux: "Bool"}, |
| 138 |
{name: "Rsh32x16", argLength: 2, aux: "Bool"}, |
| 139 |
{name: "Rsh32x32", argLength: 2, aux: "Bool"}, |
| 140 |
{name: "Rsh32x64", argLength: 2, aux: "Bool"}, |
| 141 |
{name: "Rsh64x8", argLength: 2, aux: "Bool"}, |
| 142 |
{name: "Rsh64x16", argLength: 2, aux: "Bool"}, |
| 143 |
{name: "Rsh64x32", argLength: 2, aux: "Bool"}, |
| 144 |
{name: "Rsh64x64", argLength: 2, aux: "Bool"}, |
| 145 |
|
| 146 |
{name: "Rsh8Ux8", argLength: 2, aux: "Bool"}, // arg0 >> arg1, unsigned |
| 147 |
{name: "Rsh8Ux16", argLength: 2, aux: "Bool"}, |
| 148 |
{name: "Rsh8Ux32", argLength: 2, aux: "Bool"}, |
| 149 |
{name: "Rsh8Ux64", argLength: 2, aux: "Bool"}, |
| 150 |
{name: "Rsh16Ux8", argLength: 2, aux: "Bool"}, |
| 151 |
{name: "Rsh16Ux16", argLength: 2, aux: "Bool"}, |
| 152 |
{name: "Rsh16Ux32", argLength: 2, aux: "Bool"}, |
| 153 |
{name: "Rsh16Ux64", argLength: 2, aux: "Bool"}, |
| 154 |
{name: "Rsh32Ux8", argLength: 2, aux: "Bool"}, |
| 155 |
{name: "Rsh32Ux16", argLength: 2, aux: "Bool"}, |
| 156 |
{name: "Rsh32Ux32", argLength: 2, aux: "Bool"}, |
| 157 |
{name: "Rsh32Ux64", argLength: 2, aux: "Bool"}, |
| 158 |
{name: "Rsh64Ux8", argLength: 2, aux: "Bool"}, |
| 159 |
{name: "Rsh64Ux16", argLength: 2, aux: "Bool"}, |
| 160 |
{name: "Rsh64Ux32", argLength: 2, aux: "Bool"}, |
| 161 |
{name: "Rsh64Ux64", argLength: 2, aux: "Bool"}, |
| 162 |
|
| 163 |
// 2-input comparisons |
| 164 |
{name: "Eq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 == arg1 |
| 165 |
{name: "Eq16", argLength: 2, commutative: true, typ: "Bool"}, |
| 166 |
{name: "Eq32", argLength: 2, commutative: true, typ: "Bool"}, |
| 167 |
{name: "Eq64", argLength: 2, commutative: true, typ: "Bool"}, |
| 168 |
{name: "EqPtr", argLength: 2, commutative: true, typ: "Bool"}, |
| 169 |
{name: "EqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend |
| 170 |
{name: "EqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend |
| 171 |
{name: "Eq32F", argLength: 2, commutative: true, typ: "Bool"}, |
| 172 |
{name: "Eq64F", argLength: 2, commutative: true, typ: "Bool"}, |
| 173 |
|
| 174 |
{name: "Neq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1 |
| 175 |
{name: "Neq16", argLength: 2, commutative: true, typ: "Bool"}, |
| 176 |
{name: "Neq32", argLength: 2, commutative: true, typ: "Bool"}, |
| 177 |
{name: "Neq64", argLength: 2, commutative: true, typ: "Bool"}, |
| 178 |
{name: "NeqPtr", argLength: 2, commutative: true, typ: "Bool"}, |
| 179 |
{name: "NeqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend |
| 180 |
{name: "NeqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend |
| 181 |
{name: "Neq32F", argLength: 2, commutative: true, typ: "Bool"}, |
| 182 |
{name: "Neq64F", argLength: 2, commutative: true, typ: "Bool"}, |
| 183 |
|
| 184 |
{name: "Less8", argLength: 2, typ: "Bool"}, // arg0 < arg1, signed |
| 185 |
{name: "Less8U", argLength: 2, typ: "Bool"}, // arg0 < arg1, unsigned |
| 186 |
{name: "Less16", argLength: 2, typ: "Bool"}, |
| 187 |
{name: "Less16U", argLength: 2, typ: "Bool"}, |
| 188 |
{name: "Less32", argLength: 2, typ: "Bool"}, |
| 189 |
{name: "Less32U", argLength: 2, typ: "Bool"}, |
| 190 |
{name: "Less64", argLength: 2, typ: "Bool"}, |
| 191 |
{name: "Less64U", argLength: 2, typ: "Bool"}, |
| 192 |
{name: "Less32F", argLength: 2, typ: "Bool"}, |
| 193 |
{name: "Less64F", argLength: 2, typ: "Bool"}, |
| 194 |
|
| 195 |
{name: "Leq8", argLength: 2, typ: "Bool"}, // arg0 <= arg1, signed |
| 196 |
{name: "Leq8U", argLength: 2, typ: "Bool"}, // arg0 <= arg1, unsigned |
| 197 |
{name: "Leq16", argLength: 2, typ: "Bool"}, |
| 198 |
{name: "Leq16U", argLength: 2, typ: "Bool"}, |
| 199 |
{name: "Leq32", argLength: 2, typ: "Bool"}, |
| 200 |
{name: "Leq32U", argLength: 2, typ: "Bool"}, |
| 201 |
{name: "Leq64", argLength: 2, typ: "Bool"}, |
| 202 |
{name: "Leq64U", argLength: 2, typ: "Bool"}, |
| 203 |
{name: "Leq32F", argLength: 2, typ: "Bool"}, |
| 204 |
{name: "Leq64F", argLength: 2, typ: "Bool"}, |
| 205 |
|
| 206 |
// the type of a CondSelect is the same as the type of its first |
| 207 |
// two arguments, which should be register-width scalars; the third |
| 208 |
// argument should be a boolean |
| 209 |
{name: "CondSelect", argLength: 3}, // arg2 ? arg0 : arg1 |
| 210 |
|
| 211 |
// boolean ops |
| 212 |
{name: "AndB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 && arg1 (not shortcircuited) |
| 213 |
{name: "OrB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 || arg1 (not shortcircuited) |
| 214 |
{name: "EqB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 == arg1 |
| 215 |
{name: "NeqB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1 |
| 216 |
{name: "Not", argLength: 1, typ: "Bool"}, // !arg0, boolean |
| 217 |
|
| 218 |
// 1-input ops |
| 219 |
{name: "Neg8", argLength: 1}, // -arg0 |
| 220 |
{name: "Neg16", argLength: 1}, |
| 221 |
{name: "Neg32", argLength: 1}, |
| 222 |
{name: "Neg64", argLength: 1}, |
| 223 |
{name: "Neg32F", argLength: 1}, |
| 224 |
{name: "Neg64F", argLength: 1}, |
| 225 |
|
| 226 |
{name: "Com8", argLength: 1}, // ^arg0 |
| 227 |
{name: "Com16", argLength: 1}, |
| 228 |
{name: "Com32", argLength: 1}, |
| 229 |
{name: "Com64", argLength: 1}, |
| 230 |
|
| 231 |
{name: "Ctz8", argLength: 1}, // Count trailing (low order) zeroes (returns 0-8) |
| 232 |
{name: "Ctz16", argLength: 1}, // Count trailing (low order) zeroes (returns 0-16) |
| 233 |
{name: "Ctz32", argLength: 1}, // Count trailing (low order) zeroes (returns 0-32) |
| 234 |
{name: "Ctz64", argLength: 1}, // Count trailing (low order) zeroes (returns 0-64) |
| 235 |
{name: "Ctz64On32", argLength: 2}, // Count trailing (low order) zeroes (returns 0-64) in arg[1]<<32+arg[0] |
| 236 |
{name: "Ctz8NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-7 |
| 237 |
{name: "Ctz16NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-15 |
| 238 |
{name: "Ctz32NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-31 |
| 239 |
{name: "Ctz64NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-63 |
| 240 |
{name: "BitLen8", argLength: 1}, // Number of bits in arg[0] (returns 0-8) |
| 241 |
{name: "BitLen16", argLength: 1}, // Number of bits in arg[0] (returns 0-16) |
| 242 |
{name: "BitLen32", argLength: 1}, // Number of bits in arg[0] (returns 0-32) |
| 243 |
{name: "BitLen64", argLength: 1}, // Number of bits in arg[0] (returns 0-64) |
| 244 |
|
| 245 |
{name: "Bswap16", argLength: 1}, // Swap bytes |
| 246 |
{name: "Bswap32", argLength: 1}, // Swap bytes |
| 247 |
{name: "Bswap64", argLength: 1}, // Swap bytes |
| 248 |
|
| 249 |
{name: "BitRev8", argLength: 1}, // Reverse the bits in arg[0] |
| 250 |
{name: "BitRev16", argLength: 1}, // Reverse the bits in arg[0] |
| 251 |
{name: "BitRev32", argLength: 1}, // Reverse the bits in arg[0] |
| 252 |
{name: "BitRev64", argLength: 1}, // Reverse the bits in arg[0] |
| 253 |
|
| 254 |
{name: "PopCount8", argLength: 1}, // Count bits in arg[0] |
| 255 |
{name: "PopCount16", argLength: 1}, // Count bits in arg[0] |
| 256 |
{name: "PopCount32", argLength: 1}, // Count bits in arg[0] |
| 257 |
{name: "PopCount64", argLength: 1}, // Count bits in arg[0] |
| 258 |
|
| 259 |
// RotateLeftX instructions rotate the X bits of arg[0] to the left |
| 260 |
// by the low lg_2(X) bits of arg[1], interpreted as an unsigned value. |
| 261 |
// Note that this works out regardless of the bit width or signedness of |
| 262 |
// arg[1]. In particular, RotateLeft by x is the same as RotateRight by -x. |
| 263 |
{name: "RotateLeft64", argLength: 2}, |
| 264 |
{name: "RotateLeft32", argLength: 2}, |
| 265 |
{name: "RotateLeft16", argLength: 2}, |
| 266 |
{name: "RotateLeft8", argLength: 2}, |
| 267 |
|
| 268 |
// Square root. |
| 269 |
// Special cases: |
| 270 |
// +∞ → +∞ |
| 271 |
// ±0 → ±0 (sign preserved) |
| 272 |
// x<0 → NaN |
| 273 |
// NaN → NaN |
| 274 |
{name: "Sqrt", argLength: 1}, // √arg0 (floating point, double precision) |
| 275 |
{name: "Sqrt32", argLength: 1}, // √arg0 (floating point, single precision) |
| 276 |
|
| 277 |
// Round to integer, float64 only. |
| 278 |
// Special cases: |
| 279 |
// ±∞ → ±∞ (sign preserved) |
| 280 |
// ±0 → ±0 (sign preserved) |
| 281 |
// NaN → NaN |
| 282 |
{name: "Floor", argLength: 1}, // round arg0 toward -∞ |
| 283 |
{name: "Ceil", argLength: 1}, // round arg0 toward +∞ |
| 284 |
{name: "Trunc", argLength: 1}, // round arg0 toward 0 |
| 285 |
{name: "Round", argLength: 1}, // round arg0 to nearest, ties away from 0 |
| 286 |
{name: "RoundToEven", argLength: 1}, // round arg0 to nearest, ties to even |
| 287 |
|
| 288 |
// Modify the sign bit |
| 289 |
{name: "Abs", argLength: 1}, // absolute value arg0 |
| 290 |
{name: "Copysign", argLength: 2}, // copy sign from arg0 to arg1 |
| 291 |
|
| 292 |
// Integer min/max implementation, if hardware is available. |
| 293 |
{name: "Min64", argLength: 2}, // min(arg0,arg1), signed |
| 294 |
{name: "Max64", argLength: 2}, // max(arg0,arg1), signed |
| 295 |
{name: "Min64u", argLength: 2}, // min(arg0,arg1), unsigned |
| 296 |
{name: "Max64u", argLength: 2}, // max(arg0,arg1), unsigned |
| 297 |
|
| 298 |
// Float min/max implementation, if hardware is available. |
| 299 |
{name: "Min64F", argLength: 2}, // min(arg0,arg1) |
| 300 |
{name: "Min32F", argLength: 2}, // min(arg0,arg1) |
| 301 |
{name: "Max64F", argLength: 2}, // max(arg0,arg1) |
| 302 |
{name: "Max32F", argLength: 2}, // max(arg0,arg1) |
| 303 |
|
| 304 |
// 3-input opcode. |
| 305 |
// Fused-multiply-add, float64 only. |
| 306 |
// When a*b+c is exactly zero (before rounding), then the result is +0 or -0. |
| 307 |
// The 0's sign is determined according to the standard rules for the |
| 308 |
// addition (-0 if both a*b and c are -0, +0 otherwise). |
| 309 |
// |
| 310 |
// Otherwise, when a*b+c rounds to zero, then the resulting 0's sign is |
| 311 |
// determined by the sign of the exact result a*b+c. |
| 312 |
// See section 6.3 in ieee754. |
| 313 |
// |
| 314 |
// When the multiply is an infinity times a zero, the result is NaN. |
| 315 |
// See section 7.2 in ieee754. |
| 316 |
{name: "FMA", argLength: 3}, // compute (a*b)+c without intermediate rounding |
| 317 |
|
| 318 |
// Data movement. Max argument length for Phi is indefinite. |
| 319 |
{name: "Phi", argLength: -1, zeroWidth: true}, // select an argument based on which predecessor block we came from |
| 320 |
{name: "Copy", argLength: 1}, // output = arg0 |
| 321 |
// Convert converts between pointers and integers. |
| 322 |
// We have a special op for this so as to not confuse GC |
| 323 |
// (particularly stack maps). It takes a memory arg so it |
| 324 |
// gets correctly ordered with respect to GC safepoints. |
| 325 |
// It gets compiled to nothing, so its result must in the same |
| 326 |
// register as its argument. regalloc knows it can use any |
| 327 |
// allocatable integer register for OpConvert. |
| 328 |
// arg0=ptr/int arg1=mem, output=int/ptr |
| 329 |
{name: "Convert", argLength: 2, zeroWidth: true, resultInArg0: true}, |
| 330 |
|
| 331 |
// constants. Constant values are stored in the aux or |
| 332 |
// auxint fields. |
| 333 |
{name: "ConstBool", aux: "Bool"}, // auxint is 0 for false and 1 for true |
| 334 |
{name: "ConstString", aux: "String"}, // value is aux.(string) |
| 335 |
{name: "ConstNil", typ: "BytePtr"}, // nil pointer |
| 336 |
{name: "Const8", aux: "Int8"}, // auxint is sign-extended 8 bits |
| 337 |
{name: "Const16", aux: "Int16"}, // auxint is sign-extended 16 bits |
| 338 |
{name: "Const32", aux: "Int32"}, // auxint is sign-extended 32 bits |
| 339 |
// Note: ConstX are sign-extended even when the type of the value is unsigned. |
| 340 |
// For instance, uint8(0xaa) is stored as auxint=0xffffffffffffffaa. |
| 341 |
{name: "Const64", aux: "Int64"}, // value is auxint |
| 342 |
// Note: for both Const32F and Const64F, we disallow encoding NaNs. |
| 343 |
// Signaling NaNs are tricky because if you do anything with them, they become quiet. |
| 344 |
// Particularly, converting a 32 bit sNaN to 64 bit and back converts it to a qNaN. |
| 345 |
// See issue 36399 and 36400. |
| 346 |
// Encodings of +inf, -inf, and -0 are fine. |
| 347 |
{name: "Const32F", aux: "Float32"}, // value is math.Float64frombits(uint64(auxint)) and is exactly representable as float 32 |
| 348 |
{name: "Const64F", aux: "Float64"}, // value is math.Float64frombits(uint64(auxint)) |
| 349 |
{name: "ConstInterface"}, // nil interface |
| 350 |
{name: "ConstSlice"}, // nil slice |
| 351 |
|
| 352 |
// Constant-like things |
| 353 |
{name: "InitMem", zeroWidth: true}, // memory input to the function. |
| 354 |
{name: "Arg", aux: "SymOff", symEffect: "Read", zeroWidth: true}, // argument to the function. aux=GCNode of arg, off = offset in that arg. |
| 355 |
|
| 356 |
// Like Arg, these are generic ops that survive lowering. AuxInt is a register index, and the actual output register for each index is defined by the architecture. |
| 357 |
// AuxInt = integer argument index (not a register number). ABI-specified spill loc obtained from function |
| 358 |
{name: "ArgIntReg", aux: "NameOffsetInt8", zeroWidth: true}, // argument to the function in an int reg. |
| 359 |
{name: "ArgFloatReg", aux: "NameOffsetInt8", zeroWidth: true}, // argument to the function in a float reg. |
| 360 |
|
| 361 |
// The address of a variable. arg0 is the base pointer. |
| 362 |
// If the variable is a global, the base pointer will be SB and |
| 363 |
// the Aux field will be a *obj.LSym. |
| 364 |
// If the variable is a local, the base pointer will be SP and |
| 365 |
// the Aux field will be a *ir.Name |
| 366 |
{name: "Addr", argLength: 1, aux: "Sym", symEffect: "Addr"}, // Address of a variable. Arg0=SB. Aux identifies the variable. |
| 367 |
{name: "LocalAddr", argLength: 2, aux: "Sym", symEffect: "Addr"}, // Address of a variable. Arg0=SP. Arg1=mem. Aux identifies the variable. |
| 368 |
|
| 369 |
{name: "SP", zeroWidth: true, fixedReg: true}, // stack pointer |
| 370 |
{name: "SB", typ: "Uintptr", zeroWidth: true, fixedReg: true}, // static base pointer (a.k.a. globals pointer) |
| 371 |
{name: "Invalid"}, // unused value |
| 372 |
{name: "SPanchored", typ: "Uintptr", argLength: 2, zeroWidth: true}, // arg0 = SP, arg1 = mem. Result is identical to arg0, but cannot be scheduled before memory state arg1. |
| 373 |
|
| 374 |
// Memory operations |
| 375 |
{name: "Load", argLength: 2}, // Load from arg0. arg1=memory |
| 376 |
{name: "Dereference", argLength: 2}, // Load from arg0. arg1=memory. Helper op for arg/result passing, result is an otherwise not-SSA-able "value". |
| 377 |
{name: "Store", argLength: 3, typ: "Mem", aux: "Typ"}, // Store arg1 to arg0. arg2=memory, aux=type. Returns memory. |
| 378 |
|
| 379 |
// masked memory operations. |
| 380 |
// TODO add 16 and 8 |
| 381 |
{name: "LoadMasked8", argLength: 3}, // Load from arg0, arg1 = mask of 8-bits, arg2 = memory |
| 382 |
{name: "LoadMasked16", argLength: 3}, // Load from arg0, arg1 = mask of 16-bits, arg2 = memory |
| 383 |
{name: "LoadMasked32", argLength: 3}, // Load from arg0, arg1 = mask of 32-bits, arg2 = memory |
| 384 |
{name: "LoadMasked64", argLength: 3}, // Load from arg0, arg1 = mask of 64-bits, arg2 = memory |
| 385 |
{name: "StoreMasked8", argLength: 4, typ: "Mem", aux: "Typ"}, // Store arg2 to arg0, arg1=mask of 8-bits, arg3 = memory |
| 386 |
{name: "StoreMasked16", argLength: 4, typ: "Mem", aux: "Typ"}, // Store arg2 to arg0, arg1=mask of 16-bits, arg3 = memory |
| 387 |
{name: "StoreMasked32", argLength: 4, typ: "Mem", aux: "Typ"}, // Store arg2 to arg0, arg1=mask of 32-bits, arg3 = memory |
| 388 |
{name: "StoreMasked64", argLength: 4, typ: "Mem", aux: "Typ"}, // Store arg2 to arg0, arg1=mask of 64-bits, arg3 = memory |
| 389 |
|
| 390 |
// Normally we require that the source and destination of Move do not overlap. |
| 391 |
// There is an exception when we know all the loads will happen before all |
| 392 |
// the stores. In that case, overlap is ok. See |
| 393 |
// memmove inlining in generic.rules. When inlineablememmovesize (in ../rewrite.go) |
| 394 |
// returns true, we must do all loads before all stores, when lowering Move. |
| 395 |
// The type of Move is used for the write barrier pass to insert write barriers |
| 396 |
// and for alignment on some architectures. |
| 397 |
// For pointerless types, it is possible for the type to be inaccurate. |
| 398 |
// For type alignment and pointer information, use the type in Aux; |
| 399 |
// for type size, use the size in AuxInt. |
| 400 |
// The "inline runtime.memmove" rewrite rule generates Moves with inaccurate types, |
| 401 |
// such as type byte instead of the more accurate type [8]byte. |
| 402 |
{name: "Move", argLength: 3, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size, aux=type. Returns memory. |
| 403 |
{name: "Zero", argLength: 2, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=mem, auxint=size, aux=type. Returns memory. |
| 404 |
|
| 405 |
// Memory operations with write barriers. |
| 406 |
// Expand to runtime calls. Write barrier will be removed if write on stack. |
| 407 |
{name: "StoreWB", argLength: 3, typ: "Mem", aux: "Typ"}, // Store arg1 to arg0. arg2=memory, aux=type. Returns memory. |
| 408 |
{name: "MoveWB", argLength: 3, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size, aux=type. Returns memory. |
| 409 |
{name: "ZeroWB", argLength: 2, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=mem, auxint=size, aux=type. Returns memory. |
| 410 |
{name: "WBend", argLength: 1, typ: "Mem"}, // Write barrier code is done, interrupting is now allowed. |
| 411 |
|
| 412 |
// WB invokes runtime.gcWriteBarrier. This is not a normal |
| 413 |
// call: it takes arguments in registers, doesn't clobber |
| 414 |
// general-purpose registers (the exact clobber set is |
| 415 |
// arch-dependent), and is not a safe-point. |
| 416 |
{name: "WB", argLength: 1, typ: "(BytePtr,Mem)", aux: "Int64"}, // arg0=mem, auxint=# of buffer entries needed. Returns buffer pointer and memory. |
| 417 |
|
| 418 |
{name: "HasCPUFeature", argLength: 0, typ: "bool", aux: "Sym", symEffect: "None"}, // aux=place that this feature flag can be loaded from |
| 419 |
|
| 420 |
// PanicBounds and PanicExtend generate a runtime panic. |
| 421 |
// Their arguments provide index values to use in panic messages. |
| 422 |
// Both PanicBounds and PanicExtend have an AuxInt value from the BoundsKind type (in ../op.go). |
| 423 |
// PanicBounds' index is int sized. |
| 424 |
// PanicExtend's index is int64 sized. (PanicExtend is only used on 32-bit archs.) |
| 425 |
{name: "PanicBounds", argLength: 3, aux: "Int64", typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. |
| 426 |
{name: "PanicExtend", argLength: 4, aux: "Int64", typ: "Mem", call: true}, // arg0=idxHi, arg1=idxLo, arg2=len, arg3=mem, returns memory. |
| 427 |
|
| 428 |
// Function calls. Arguments to the call have already been written to the stack. |
| 429 |
// Return values appear on the stack. The method receiver, if any, is treated |
| 430 |
// as a phantom first argument. |
| 431 |
// TODO(josharian): ClosureCall and InterCall should have Int32 aux |
| 432 |
// to match StaticCall's 32 bit arg size limit. |
| 433 |
// TODO(drchase,josharian): could the arg size limit be bundled into the rules for CallOff? |
| 434 |
|
| 435 |
// Before lowering, LECalls receive their fixed inputs (first), memory (last), |
| 436 |
// and a variable number of input values in the middle. |
| 437 |
// They produce a variable number of result values. |
| 438 |
// These values are not necessarily "SSA-able"; they can be too large, |
| 439 |
// but in that case inputs are loaded immediately before with OpDereference, |
| 440 |
// and outputs are stored immediately with OpStore. |
| 441 |
// |
| 442 |
// After call expansion, Calls have the same fixed-middle-memory arrangement of inputs, |
| 443 |
// with the difference that the "middle" is only the register-resident inputs, |
| 444 |
// and the non-register inputs are instead stored at ABI-defined offsets from SP |
| 445 |
// (and the stores thread through the memory that is ultimately an input to the call). |
| 446 |
// Outputs follow a similar pattern; register-resident outputs are the leading elements |
| 447 |
// of a Result-typed output, with memory last, and any memory-resident outputs have been |
| 448 |
// stored to ABI-defined locations. Each non-memory input or output fits in a register. |
| 449 |
// |
| 450 |
// Subsequent architecture-specific lowering only changes the opcode. |
| 451 |
|
| 452 |
{name: "ClosureCall", argLength: -1, aux: "CallOff", call: true}, // arg0=code pointer, arg1=context ptr, arg2..argN-1 are register inputs, argN=memory. auxint=arg size. Returns Result of register results, plus memory. |
| 453 |
{name: "StaticCall", argLength: -1, aux: "CallOff", call: true}, // call function aux.(*obj.LSym), arg0..argN-1 are register inputs, argN=memory. auxint=arg size. Returns Result of register results, plus memory. |
| 454 |
{name: "InterCall", argLength: -1, aux: "CallOff", call: true}, // interface call. arg0=code pointer, arg1..argN-1 are register inputs, argN=memory, auxint=arg size. Returns Result of register results, plus memory. |
| 455 |
{name: "TailCall", argLength: -1, aux: "CallOff", call: true}, // tail call function aux.(*obj.LSym), arg0..argN-1 are register inputs, argN=memory. auxint=arg size. Returns Result of register results, plus memory. |
| 456 |
|
| 457 |
{name: "ClosureLECall", argLength: -1, aux: "CallOff", call: true}, // late-expanded closure call. arg0=code pointer, arg1=context ptr, arg2..argN-1 are inputs, argN is mem. auxint = arg size. Result is tuple of result(s), plus mem. |
| 458 |
{name: "StaticLECall", argLength: -1, aux: "CallOff", call: true}, // late-expanded static call function aux.(*ssa.AuxCall.Fn). arg0..argN-1 are inputs, argN is mem. auxint = arg size. Result is tuple of result(s), plus mem. |
| 459 |
{name: "InterLECall", argLength: -1, aux: "CallOff", call: true}, // late-expanded interface call. arg0=code pointer, arg1..argN-1 are inputs, argN is mem. auxint = arg size. Result is tuple of result(s), plus mem. |
| 460 |
{name: "TailLECall", argLength: -1, aux: "CallOff", call: true}, // late-expanded static tail call function aux.(*ssa.AuxCall.Fn). arg0..argN-1 are inputs, argN is mem. auxint = arg size. Result is tuple of result(s), plus mem. |
| 461 |
|
| 462 |
// Conversions: signed extensions, zero (unsigned) extensions, truncations |
| 463 |
{name: "SignExt8to16", argLength: 1, typ: "Int16"}, |
| 464 |
{name: "SignExt8to32", argLength: 1, typ: "Int32"}, |
| 465 |
{name: "SignExt8to64", argLength: 1, typ: "Int64"}, |
| 466 |
{name: "SignExt16to32", argLength: 1, typ: "Int32"}, |
| 467 |
{name: "SignExt16to64", argLength: 1, typ: "Int64"}, |
| 468 |
{name: "SignExt32to64", argLength: 1, typ: "Int64"}, |
| 469 |
{name: "ZeroExt8to16", argLength: 1, typ: "UInt16"}, |
| 470 |
{name: "ZeroExt8to32", argLength: 1, typ: "UInt32"}, |
| 471 |
{name: "ZeroExt8to64", argLength: 1, typ: "UInt64"}, |
| 472 |
{name: "ZeroExt16to32", argLength: 1, typ: "UInt32"}, |
| 473 |
{name: "ZeroExt16to64", argLength: 1, typ: "UInt64"}, |
| 474 |
{name: "ZeroExt32to64", argLength: 1, typ: "UInt64"}, |
| 475 |
{name: "Trunc16to8", argLength: 1}, |
| 476 |
{name: "Trunc32to8", argLength: 1}, |
| 477 |
{name: "Trunc32to16", argLength: 1}, |
| 478 |
{name: "Trunc64to8", argLength: 1}, |
| 479 |
{name: "Trunc64to16", argLength: 1}, |
| 480 |
{name: "Trunc64to32", argLength: 1}, |
| 481 |
|
| 482 |
{name: "Cvt32to32F", argLength: 1}, |
| 483 |
{name: "Cvt32to64F", argLength: 1}, |
| 484 |
{name: "Cvt64to32F", argLength: 1}, |
| 485 |
{name: "Cvt64to64F", argLength: 1}, |
| 486 |
{name: "Cvt32Fto32", argLength: 1}, |
| 487 |
{name: "Cvt32Fto64", argLength: 1}, |
| 488 |
{name: "Cvt64Fto32", argLength: 1}, |
| 489 |
{name: "Cvt64Fto64", argLength: 1}, |
| 490 |
{name: "Cvt32Fto64F", argLength: 1}, |
| 491 |
{name: "Cvt64Fto32F", argLength: 1}, |
| 492 |
{name: "CvtBoolToUint8", argLength: 1}, |
| 493 |
|
| 494 |
// Force rounding to precision of type. |
| 495 |
{name: "Round32F", argLength: 1}, |
| 496 |
{name: "Round64F", argLength: 1}, |
| 497 |
|
| 498 |
// Automatically inserted safety checks |
| 499 |
{name: "IsNonNil", argLength: 1, typ: "Bool"}, // arg0 != nil |
| 500 |
{name: "IsInBounds", argLength: 2, typ: "Bool"}, // 0 <= arg0 < arg1. arg1 is guaranteed >= 0. |
| 501 |
{name: "IsSliceInBounds", argLength: 2, typ: "Bool"}, // 0 <= arg0 <= arg1. arg1 is guaranteed >= 0. |
| 502 |
{name: "NilCheck", argLength: 2, nilCheck: true}, // arg0=ptr, arg1=mem. Panics if arg0 is nil. Returns the ptr unmodified. |
| 503 |
|
| 504 |
// Pseudo-ops |
| 505 |
{name: "GetG", argLength: 1, zeroWidth: true}, // runtime.getg() (read g pointer). arg0=mem |
| 506 |
{name: "GetClosurePtr"}, // get closure pointer from dedicated register |
| 507 |
{name: "GetCallerPC"}, // for GetCallerPC intrinsic |
| 508 |
{name: "GetCallerSP", argLength: 1}, // for GetCallerSP intrinsic. arg0=mem. |
| 509 |
|
| 510 |
// Indexing operations |
| 511 |
{name: "PtrIndex", argLength: 2}, // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type |
| 512 |
{name: "OffPtr", argLength: 1, aux: "Int64"}, // arg0 + auxint (arg0 and result are pointers) |
| 513 |
|
| 514 |
// Slices |
| 515 |
{name: "SliceMake", argLength: 3}, // arg0=ptr, arg1=len, arg2=cap |
| 516 |
{name: "SlicePtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0) |
| 517 |
{name: "SliceLen", argLength: 1}, // len(arg0) |
| 518 |
{name: "SliceCap", argLength: 1}, // cap(arg0) |
| 519 |
// SlicePtrUnchecked, like SlicePtr, extracts the pointer from a slice. |
| 520 |
// SlicePtr values are assumed non-nil, because they are guarded by bounds checks. |
| 521 |
// SlicePtrUnchecked values can be nil. |
| 522 |
{name: "SlicePtrUnchecked", argLength: 1}, |
| 523 |
|
| 524 |
// Complex (part/whole) |
| 525 |
{name: "ComplexMake", argLength: 2}, // arg0=real, arg1=imag |
| 526 |
{name: "ComplexReal", argLength: 1}, // real(arg0) |
| 527 |
{name: "ComplexImag", argLength: 1}, // imag(arg0) |
| 528 |
|
| 529 |
// Strings |
| 530 |
{name: "StringMake", argLength: 2}, // arg0=ptr, arg1=len |
| 531 |
{name: "StringPtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0) |
| 532 |
{name: "StringLen", argLength: 1, typ: "Int"}, // len(arg0) |
| 533 |
|
| 534 |
// Interfaces |
| 535 |
{name: "IMake", argLength: 2}, // arg0=itab, arg1=data |
| 536 |
{name: "ITab", argLength: 1, typ: "Uintptr"}, // arg0=interface, returns itable field |
| 537 |
{name: "IData", argLength: 1}, // arg0=interface, returns data field |
| 538 |
|
| 539 |
// Structs |
| 540 |
{name: "StructMake", argLength: -1}, // args...=field0..n-1. Returns struct with n fields. Must have >0 size (use Empty otherwise). |
| 541 |
{name: "StructSelect", argLength: 1, aux: "Int64"}, // arg0=struct, auxint=field index. Returns the auxint'th field. |
| 542 |
|
| 543 |
// Arrays |
| 544 |
{name: "ArrayMake1", argLength: 1}, // Returns array with 1 element. Use Empty if the element is zero-sized. |
| 545 |
{name: "ArraySelect", argLength: 1, aux: "Int64"}, // arg0=array, auxint=index. Returns a[i]. |
| 546 |
|
| 547 |
// Spill&restore ops for the register allocator. These are |
| 548 |
// semantically identical to OpCopy; they do not take/return |
| 549 |
// stores like regular memory ops do. We can get away without memory |
| 550 |
// args because we know there is no aliasing of spill slots on the stack. |
| 551 |
{name: "StoreReg", argLength: 1}, |
| 552 |
{name: "LoadReg", argLength: 1}, |
| 553 |
|
| 554 |
// Used during ssa construction. Like Copy, but the arg has not been specified yet. |
| 555 |
{name: "FwdRef", aux: "Sym", symEffect: "None"}, |
| 556 |
|
| 557 |
// Unknown value. Used for Values whose values don't matter because they are dead code. |
| 558 |
{name: "Unknown"}, |
| 559 |
|
| 560 |
{name: "VarDef", argLength: 1, aux: "Sym", typ: "Mem", symEffect: "None", zeroWidth: true}, // aux is a *ir.Name of a variable that is about to be initialized. arg0=mem, returns mem |
| 561 |
// TODO: what's the difference between VarLive and KeepAlive? |
| 562 |
{name: "VarLive", argLength: 1, aux: "Sym", symEffect: "Read", zeroWidth: true}, // aux is a *ir.Name of a variable that must be kept live. arg0=mem, returns mem |
| 563 |
{name: "KeepAlive", argLength: 2, typ: "Mem", zeroWidth: true}, // arg[0] is a value that must be kept alive until this mark. arg[1]=mem, returns mem |
| 564 |
|
| 565 |
// InlMark marks the start of an inlined function body. Its AuxInt field |
| 566 |
// distinguishes which entry in the local inline tree it is marking. |
| 567 |
{name: "InlMark", argLength: 1, aux: "Int32", typ: "Void"}, // arg[0]=mem, returns void. |
| 568 |
|
| 569 |
// Ops for breaking 64-bit operations on 32-bit architectures |
| 570 |
{name: "Int64Make", argLength: 2, typ: "UInt64"}, // arg0=hi, arg1=lo |
| 571 |
{name: "Int64Hi", argLength: 1, typ: "UInt32"}, // high 32-bit of arg0 |
| 572 |
{name: "Int64Lo", argLength: 1, typ: "UInt32"}, // low 32-bit of arg0 |
| 573 |
|
| 574 |
{name: "Add32carry", argLength: 2, commutative: true, typ: "(UInt32,Flags)"}, // arg0 + arg1, returns (value, carry) |
| 575 |
{name: "Add32withcarry", argLength: 3, commutative: true}, // arg0 + arg1 + arg2, arg2=carry (0 or 1) |
| 576 |
{name: "Add32carrywithcarry", argLength: 3, commutative: true, typ: "(UInt32,Flags)"}, // arg0 + arg1 + arg2, arg2=carry, returns (value, carry) |
| 577 |
|
| 578 |
{name: "Sub32carry", argLength: 2, typ: "(UInt32,Flags)"}, // arg0 - arg1, returns (value, carry) |
| 579 |
{name: "Sub32withcarry", argLength: 3}, // arg0 - arg1 - arg2, arg2=carry (0 or 1) |
| 580 |
|
| 581 |
{name: "Add64carry", argLength: 3, commutative: true, typ: "(UInt64,UInt64)"}, // arg0 + arg1 + arg2, arg2 must be 0 or 1. returns (value, value>>64) |
| 582 |
{name: "Sub64borrow", argLength: 3, typ: "(UInt64,UInt64)"}, // arg0 - (arg1 + arg2), arg2 must be 0 or 1. returns (value, value>>64&1) |
| 583 |
|
| 584 |
{name: "Signmask", argLength: 1, typ: "Int32"}, // 0 if arg0 >= 0, -1 if arg0 < 0 |
| 585 |
{name: "Zeromask", argLength: 1, typ: "UInt32"}, // 0 if arg0 == 0, 0xffffffff if arg0 != 0 |
| 586 |
{name: "Slicemask", argLength: 1}, // 0 if arg0 == 0, -1 if arg0 > 0, undef if arg0<0. Type is native int size. |
| 587 |
|
| 588 |
{name: "SpectreIndex", argLength: 2}, // arg0 if 0 <= arg0 < arg1, 0 otherwise. Type is native int size. |
| 589 |
{name: "SpectreSliceIndex", argLength: 2}, // arg0 if 0 <= arg0 <= arg1, 0 otherwise. Type is native int size. |
| 590 |
|
| 591 |
{name: "Cvt32Uto32F", argLength: 1}, // uint32 -> float32, only used on 32-bit arch |
| 592 |
{name: "Cvt32Uto64F", argLength: 1}, // uint32 -> float64, only used on 32-bit arch |
| 593 |
{name: "Cvt32Fto32U", argLength: 1}, // float32 -> uint32, only used on 32-bit arch |
| 594 |
{name: "Cvt64Fto32U", argLength: 1}, // float64 -> uint32, only used on 32-bit arch |
| 595 |
{name: "Cvt64Uto32F", argLength: 1}, // uint64 -> float32, only used on archs that has the instruction |
| 596 |
{name: "Cvt64Uto64F", argLength: 1}, // uint64 -> float64, only used on archs that has the instruction |
| 597 |
{name: "Cvt32Fto64U", argLength: 1}, // float32 -> uint64, only used on archs that has the instruction |
| 598 |
{name: "Cvt64Fto64U", argLength: 1}, // float64 -> uint64, only used on archs that has the instruction |
| 599 |
|
| 600 |
// pseudo-ops for breaking Tuple |
| 601 |
{name: "Select0", argLength: 1, zeroWidth: true}, // the first component of a tuple |
| 602 |
{name: "Select1", argLength: 1, zeroWidth: true}, // the second component of a tuple |
| 603 |
{name: "MakeTuple", argLength: 2}, // arg0 arg1 are components of a "Tuple" (like the result from a 128bits op). |
| 604 |
{name: "SelectN", argLength: 1, aux: "Int64"}, // arg0=result, auxint=field index. Returns the auxint'th member. |
| 605 |
{name: "SelectNAddr", argLength: 1, aux: "Int64"}, // arg0=result, auxint=field index. Returns the address of auxint'th member. Used for un-SSA-able result types. |
| 606 |
{name: "MakeResult", argLength: -1}, // arg0 .. are components of a "Result" (like the result from a Call). The last arg should be memory (like the result from a call). |
| 607 |
|
| 608 |
// Atomic operations used for semantically inlining sync/atomic and |
| 609 |
// internal/runtime/atomic. Atomic loads return a new memory so that |
| 610 |
// the loads are properly ordered with respect to other loads and |
| 611 |
// stores. |
| 612 |
{name: "AtomicLoad8", argLength: 2, typ: "(UInt8,Mem)"}, // Load from arg0. arg1=memory. Returns loaded value and new memory. |
| 613 |
{name: "AtomicLoad32", argLength: 2, typ: "(UInt32,Mem)"}, // Load from arg0. arg1=memory. Returns loaded value and new memory. |
| 614 |
{name: "AtomicLoad64", argLength: 2, typ: "(UInt64,Mem)"}, // Load from arg0. arg1=memory. Returns loaded value and new memory. |
| 615 |
{name: "AtomicLoadPtr", argLength: 2, typ: "(BytePtr,Mem)"}, // Load from arg0. arg1=memory. Returns loaded value and new memory. |
| 616 |
{name: "AtomicLoadAcq32", argLength: 2, typ: "(UInt32,Mem)"}, // Load from arg0. arg1=memory. Lock acquisition, returns loaded value and new memory. |
| 617 |
{name: "AtomicLoadAcq64", argLength: 2, typ: "(UInt64,Mem)"}, // Load from arg0. arg1=memory. Lock acquisition, returns loaded value and new memory. |
| 618 |
{name: "AtomicStore8", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 619 |
{name: "AtomicStore32", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 620 |
{name: "AtomicStore64", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 621 |
{name: "AtomicStorePtrNoWB", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 622 |
{name: "AtomicStoreRel32", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Lock release, returns memory. |
| 623 |
{name: "AtomicStoreRel64", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Lock release, returns memory. |
| 624 |
{name: "AtomicExchange8", argLength: 3, typ: "(UInt8,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 625 |
{name: "AtomicExchange32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 626 |
{name: "AtomicExchange64", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 627 |
{name: "AtomicAdd32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Do *arg0 += arg1. arg2=memory. Returns sum and new memory. |
| 628 |
{name: "AtomicAdd64", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Do *arg0 += arg1. arg2=memory. Returns sum and new memory. |
| 629 |
{name: "AtomicCompareAndSwap32", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Returns true if store happens and new memory. |
| 630 |
{name: "AtomicCompareAndSwap64", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Returns true if store happens and new memory. |
| 631 |
{name: "AtomicCompareAndSwapRel32", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Lock release, reports whether store happens and new memory. |
| 632 |
|
| 633 |
// Older atomic logical operations which don't return the old value. |
| 634 |
{name: "AtomicAnd8", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns memory. |
| 635 |
{name: "AtomicOr8", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns memory. |
| 636 |
{name: "AtomicAnd32", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns memory. |
| 637 |
{name: "AtomicOr32", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns memory. |
| 638 |
|
| 639 |
// Newer atomic logical operations which return the old value. |
| 640 |
{name: "AtomicAnd64value", argLength: 3, typ: "(Uint64, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 641 |
{name: "AtomicAnd32value", argLength: 3, typ: "(Uint32, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 642 |
{name: "AtomicAnd8value", argLength: 3, typ: "(Uint8, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 643 |
{name: "AtomicOr64value", argLength: 3, typ: "(Uint64, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 644 |
{name: "AtomicOr32value", argLength: 3, typ: "(Uint32, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 645 |
{name: "AtomicOr8value", argLength: 3, typ: "(Uint8, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 646 |
|
| 647 |
// Atomic operation variants |
| 648 |
// These variants have the same semantics as above atomic operations. |
| 649 |
// But they are used for generating more efficient code on certain modern machines, with run-time CPU feature detection. |
| 650 |
// On ARM64, these are used when the LSE hardware feature is available (either known at compile time or detected at runtime). If LSE is not available, |
| 651 |
// then the basic atomic operations are used instead. |
| 652 |
{name: "AtomicStore8Variant", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 653 |
{name: "AtomicStore32Variant", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 654 |
{name: "AtomicStore64Variant", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory. |
| 655 |
|
| 656 |
{name: "AtomicAdd32Variant", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Do *arg0 += arg1. arg2=memory. Returns sum and new memory. |
| 657 |
{name: "AtomicAdd64Variant", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Do *arg0 += arg1. arg2=memory. Returns sum and new memory. |
| 658 |
{name: "AtomicExchange8Variant", argLength: 3, typ: "(UInt8,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 659 |
{name: "AtomicExchange32Variant", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 660 |
{name: "AtomicExchange64Variant", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory. |
| 661 |
{name: "AtomicCompareAndSwap32Variant", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Returns true if store happens and new memory. |
| 662 |
{name: "AtomicCompareAndSwap64Variant", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Returns true if store happens and new memory. |
| 663 |
{name: "AtomicAnd64valueVariant", argLength: 3, typ: "(Uint64, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 664 |
{name: "AtomicOr64valueVariant", argLength: 3, typ: "(Uint64, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 665 |
{name: "AtomicAnd32valueVariant", argLength: 3, typ: "(Uint32, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 666 |
{name: "AtomicOr32valueVariant", argLength: 3, typ: "(Uint32, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 667 |
{name: "AtomicAnd8valueVariant", argLength: 3, typ: "(Uint8, Mem)", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 668 |
{name: "AtomicOr8valueVariant", argLength: 3, typ: "(Uint8, Mem)", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns old contents of *arg0 and new memory. |
| 669 |
|
| 670 |
// Publication barrier |
| 671 |
{name: "PubBarrier", argLength: 1, hasSideEffects: true}, // Do data barrier. arg0=memory. |
| 672 |
|
| 673 |
// Clobber experiment op |
| 674 |
{name: "Clobber", argLength: 0, typ: "Void", aux: "SymOff", symEffect: "None"}, // write an invalid pointer value to the given pointer slot of a stack variable |
| 675 |
{name: "ClobberReg", argLength: 0, typ: "Void"}, // clobber a register |
| 676 |
|
| 677 |
// Prefetch instruction |
| 678 |
{name: "PrefetchCache", argLength: 2, hasSideEffects: true}, // Do prefetch arg0 to cache. arg0=addr, arg1=memory. |
| 679 |
{name: "PrefetchCacheStreamed", argLength: 2, hasSideEffects: true}, // Do non-temporal or streamed prefetch arg0 to cache. arg0=addr, arg1=memory. |
| 680 |
|
| 681 |
// Helper instruction which is semantically equivalent to calling runtime.memequal, but some targets may prefer to custom lower it later, e.g. for specific constant sizes. |
| 682 |
{name: "MemEq", argLength: 4, commutative: true, typ: "Bool"}, // arg0=ptr0, arg1=ptr1, arg2=size, arg3=memory. |
| 683 |
|
| 684 |
// Value of a zero-sized type. |
| 685 |
{name: "Empty", argLength: 0}, |
| 686 |
|
| 687 |
// SIMD |
| 688 |
{name: "ZeroSIMD", argLength: 0}, // zero value of a vector |
| 689 |
|
| 690 |
// Convert integers to masks |
| 691 |
{name: "Cvt16toMask8x16", argLength: 1}, // arg0 = integer mask value |
| 692 |
{name: "Cvt32toMask8x32", argLength: 1}, // arg0 = integer mask value |
| 693 |
{name: "Cvt64toMask8x64", argLength: 1}, // arg0 = integer mask value |
| 694 |
{name: "Cvt8toMask16x8", argLength: 1}, // arg0 = integer mask value |
| 695 |
{name: "Cvt16toMask16x16", argLength: 1}, // arg0 = integer mask value |
| 696 |
{name: "Cvt32toMask16x32", argLength: 1}, // arg0 = integer mask value |
| 697 |
{name: "Cvt8toMask32x4", argLength: 1}, // arg0 = integer mask value |
| 698 |
{name: "Cvt8toMask32x8", argLength: 1}, // arg0 = integer mask value |
| 699 |
{name: "Cvt16toMask32x16", argLength: 1}, // arg0 = integer mask value |
| 700 |
{name: "Cvt8toMask64x2", argLength: 1}, // arg0 = integer mask value |
| 701 |
{name: "Cvt8toMask64x4", argLength: 1}, // arg0 = integer mask value |
| 702 |
{name: "Cvt8toMask64x8", argLength: 1}, // arg0 = integer mask value |
| 703 |
|
| 704 |
// Convert masks to integers |
| 705 |
{name: "CvtMask8x16to16", argLength: 1}, // arg0 = mask |
| 706 |
{name: "CvtMask8x32to32", argLength: 1}, // arg0 = mask |
| 707 |
{name: "CvtMask8x64to64", argLength: 1}, // arg0 = mask |
| 708 |
{name: "CvtMask16x8to8", argLength: 1}, // arg0 = mask |
| 709 |
{name: "CvtMask16x16to16", argLength: 1}, // arg0 = mask |
| 710 |
{name: "CvtMask16x32to32", argLength: 1}, // arg0 = mask |
| 711 |
{name: "CvtMask32x4to8", argLength: 1}, // arg0 = mask |
| 712 |
{name: "CvtMask32x8to8", argLength: 1}, // arg0 = mask |
| 713 |
{name: "CvtMask32x16to16", argLength: 1}, // arg0 = mask |
| 714 |
{name: "CvtMask64x2to8", argLength: 1}, // arg0 = mask |
| 715 |
{name: "CvtMask64x4to8", argLength: 1}, // arg0 = mask |
| 716 |
{name: "CvtMask64x8to8", argLength: 1}, // arg0 = mask |
| 717 |
|
| 718 |
// Returns true if arg0 is all zero. |
| 719 |
{name: "IsZeroVec", argLength: 1}, |
| 720 |
|
| 721 |
// Returns a mask indicating whether arg0's elements are NaN. |
| 722 |
{name: "IsNaNFloat32x4", argLength: 1}, |
| 723 |
{name: "IsNaNFloat32x8", argLength: 1}, |
| 724 |
{name: "IsNaNFloat32x16", argLength: 1}, |
| 725 |
{name: "IsNaNFloat64x2", argLength: 1}, |
| 726 |
{name: "IsNaNFloat64x4", argLength: 1}, |
| 727 |
{name: "IsNaNFloat64x8", argLength: 1}, |
| 728 |
} |
| 729 |
|
| 730 |
// kind controls successors implicit exit |
| 731 |
// ------------------------------------------------------------ |
| 732 |
// Exit [return mem] [] yes |
| 733 |
// Ret [return mem] [] yes |
| 734 |
// RetJmp [return mem] [] yes |
| 735 |
// Plain [] [next] |
| 736 |
// If [boolean Value] [then, else] |
| 737 |
// First [] [always, never] |
| 738 |
// Defer [mem] [nopanic, recovery] (control opcode should be OpStaticCall to runtime.defer*) |
| 739 |
// JumpTable [integer Value] [succ1,succ2,..] |
| 740 |
|
| 741 |
var genericBlocks = []blockData{ |
| 742 |
{name: "Plain"}, // a single successor |
| 743 |
{name: "If", controls: 1}, // if Controls[0] goto Succs[0] else goto Succs[1] |
| 744 |
{name: "Defer", controls: 1}, // Succs[0]=defer queued, Succs[1]=defer recovery branch (jmp performed by runtime). Controls[0] is call op (of memory type). |
| 745 |
{name: "Ret", controls: 1}, // no successors, Controls[0] value is memory result |
| 746 |
{name: "RetJmp", controls: 1}, // no successors, Controls[0] value is a tail call |
| 747 |
{name: "Exit", controls: 1}, // no successors, Controls[0] value generates a panic |
| 748 |
{name: "JumpTable", controls: 1}, // multiple successors, the integer Controls[0] selects which one |
| 749 |
|
| 750 |
// transient block state used for dead code removal |
| 751 |
{name: "First"}, // 2 successors, always takes the first one (second is dead) |
| 752 |
} |
| 753 |
|
| 754 |
func init() { |
| 755 |
genericOps = append(genericOps, simdGenericOps()...) |
| 756 |
archs = append(archs, arch{ |
| 757 |
name: "generic", |
| 758 |
ops: genericOps, |
| 759 |
blocks: genericBlocks, |
| 760 |
generic: true, |
| 761 |
}) |
| 762 |
} |