Source file src/cmd/compile/internal/ssa/_gen/genericOps.go

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

View as plain text