github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/cmd/compile/internal/ssa/gen/genericOps.go (about)

     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  // +build ignore
     6  
     7  package main
     8  
     9  // Generic opcodes typically specify a width. The inputs and outputs
    10  // of that op are the given number of bits wide. There is no notion of
    11  // "sign", so Add32 can be used both for signed and unsigned 32-bit
    12  // addition.
    13  
    14  // Signed/unsigned is explicit with the extension ops
    15  // (SignExt*/ZeroExt*) and implicit as the arg to some opcodes
    16  // (e.g. the second argument to shifts is unsigned). If not mentioned,
    17  // all args take signed inputs, or don't care whether their inputs
    18  // are signed or unsigned.
    19  
    20  // Unused portions of AuxInt are filled by sign-extending the used portion.
    21  // Users of AuxInt which interpret AuxInt as unsigned (e.g. shifts) must be careful.
    22  var genericOps = []opData{
    23  	// 2-input arithmetic
    24  	// Types must be consistent with Go typing. Add, for example, must take two values
    25  	// of the same type and produces that same type.
    26  	{name: "Add8", argLength: 2, commutative: true}, // arg0 + arg1
    27  	{name: "Add16", argLength: 2, commutative: true},
    28  	{name: "Add32", argLength: 2, commutative: true},
    29  	{name: "Add64", argLength: 2, commutative: true},
    30  	{name: "AddPtr", argLength: 2}, // For address calculations.  arg0 is a pointer and arg1 is an int.
    31  	{name: "Add32F", argLength: 2},
    32  	{name: "Add64F", argLength: 2},
    33  
    34  	{name: "Sub8", argLength: 2}, // arg0 - arg1
    35  	{name: "Sub16", argLength: 2},
    36  	{name: "Sub32", argLength: 2},
    37  	{name: "Sub64", argLength: 2},
    38  	{name: "SubPtr", argLength: 2},
    39  	{name: "Sub32F", argLength: 2},
    40  	{name: "Sub64F", argLength: 2},
    41  
    42  	{name: "Mul8", argLength: 2, commutative: true}, // arg0 * arg1
    43  	{name: "Mul16", argLength: 2, commutative: true},
    44  	{name: "Mul32", argLength: 2, commutative: true},
    45  	{name: "Mul64", argLength: 2, commutative: true},
    46  	{name: "Mul32F", argLength: 2},
    47  	{name: "Mul64F", argLength: 2},
    48  
    49  	{name: "Div32F", argLength: 2}, // arg0 / arg1
    50  	{name: "Div64F", argLength: 2},
    51  
    52  	{name: "Hmul8", argLength: 2},  // (arg0 * arg1) >> width, signed
    53  	{name: "Hmul8u", argLength: 2}, // (arg0 * arg1) >> width, unsigned
    54  	{name: "Hmul16", argLength: 2},
    55  	{name: "Hmul16u", argLength: 2},
    56  	{name: "Hmul32", argLength: 2},
    57  	{name: "Hmul32u", argLength: 2},
    58  	{name: "Hmul64", argLength: 2},
    59  	{name: "Hmul64u", argLength: 2},
    60  
    61  	{name: "Mul32uhilo", argLength: 2, typ: "(UInt32,UInt32)"}, // arg0 * arg1, returns (hi, lo)
    62  	{name: "Mul64uhilo", argLength: 2, typ: "(UInt64,UInt64)"}, // arg0 * arg1, returns (hi, lo)
    63  
    64  	// Weird special instruction for strength reduction of divides.
    65  	{name: "Avg64u", argLength: 2}, // (uint64(arg0) + uint64(arg1)) / 2, correct to all 64 bits.
    66  
    67  	{name: "Div8", argLength: 2},  // arg0 / arg1, signed
    68  	{name: "Div8u", argLength: 2}, // arg0 / arg1, unsigned
    69  	{name: "Div16", argLength: 2},
    70  	{name: "Div16u", argLength: 2},
    71  	{name: "Div32", argLength: 2},
    72  	{name: "Div32u", argLength: 2},
    73  	{name: "Div64", argLength: 2},
    74  	{name: "Div64u", argLength: 2},
    75  	{name: "Div128u", argLength: 3}, // arg0:arg1 / arg2 (128-bit divided by 64-bit), returns (q, r)
    76  
    77  	{name: "Mod8", argLength: 2},  // arg0 % arg1, signed
    78  	{name: "Mod8u", argLength: 2}, // arg0 % arg1, unsigned
    79  	{name: "Mod16", argLength: 2},
    80  	{name: "Mod16u", argLength: 2},
    81  	{name: "Mod32", argLength: 2},
    82  	{name: "Mod32u", argLength: 2},
    83  	{name: "Mod64", argLength: 2},
    84  	{name: "Mod64u", argLength: 2},
    85  
    86  	{name: "And8", argLength: 2, commutative: true}, // arg0 & arg1
    87  	{name: "And16", argLength: 2, commutative: true},
    88  	{name: "And32", argLength: 2, commutative: true},
    89  	{name: "And64", argLength: 2, commutative: true},
    90  
    91  	{name: "Or8", argLength: 2, commutative: true}, // arg0 | arg1
    92  	{name: "Or16", argLength: 2, commutative: true},
    93  	{name: "Or32", argLength: 2, commutative: true},
    94  	{name: "Or64", argLength: 2, commutative: true},
    95  
    96  	{name: "Xor8", argLength: 2, commutative: true}, // arg0 ^ arg1
    97  	{name: "Xor16", argLength: 2, commutative: true},
    98  	{name: "Xor32", argLength: 2, commutative: true},
    99  	{name: "Xor64", argLength: 2, commutative: true},
   100  
   101  	// For shifts, AxB means the shifted value has A bits and the shift amount has B bits.
   102  	// Shift amounts are considered unsigned.
   103  	{name: "Lsh8x8", argLength: 2}, // arg0 << arg1
   104  	{name: "Lsh8x16", argLength: 2},
   105  	{name: "Lsh8x32", argLength: 2},
   106  	{name: "Lsh8x64", argLength: 2},
   107  	{name: "Lsh16x8", argLength: 2},
   108  	{name: "Lsh16x16", argLength: 2},
   109  	{name: "Lsh16x32", argLength: 2},
   110  	{name: "Lsh16x64", argLength: 2},
   111  	{name: "Lsh32x8", argLength: 2},
   112  	{name: "Lsh32x16", argLength: 2},
   113  	{name: "Lsh32x32", argLength: 2},
   114  	{name: "Lsh32x64", argLength: 2},
   115  	{name: "Lsh64x8", argLength: 2},
   116  	{name: "Lsh64x16", argLength: 2},
   117  	{name: "Lsh64x32", argLength: 2},
   118  	{name: "Lsh64x64", argLength: 2},
   119  
   120  	{name: "Rsh8x8", argLength: 2}, // arg0 >> arg1, signed
   121  	{name: "Rsh8x16", argLength: 2},
   122  	{name: "Rsh8x32", argLength: 2},
   123  	{name: "Rsh8x64", argLength: 2},
   124  	{name: "Rsh16x8", argLength: 2},
   125  	{name: "Rsh16x16", argLength: 2},
   126  	{name: "Rsh16x32", argLength: 2},
   127  	{name: "Rsh16x64", argLength: 2},
   128  	{name: "Rsh32x8", argLength: 2},
   129  	{name: "Rsh32x16", argLength: 2},
   130  	{name: "Rsh32x32", argLength: 2},
   131  	{name: "Rsh32x64", argLength: 2},
   132  	{name: "Rsh64x8", argLength: 2},
   133  	{name: "Rsh64x16", argLength: 2},
   134  	{name: "Rsh64x32", argLength: 2},
   135  	{name: "Rsh64x64", argLength: 2},
   136  
   137  	{name: "Rsh8Ux8", argLength: 2}, // arg0 >> arg1, unsigned
   138  	{name: "Rsh8Ux16", argLength: 2},
   139  	{name: "Rsh8Ux32", argLength: 2},
   140  	{name: "Rsh8Ux64", argLength: 2},
   141  	{name: "Rsh16Ux8", argLength: 2},
   142  	{name: "Rsh16Ux16", argLength: 2},
   143  	{name: "Rsh16Ux32", argLength: 2},
   144  	{name: "Rsh16Ux64", argLength: 2},
   145  	{name: "Rsh32Ux8", argLength: 2},
   146  	{name: "Rsh32Ux16", argLength: 2},
   147  	{name: "Rsh32Ux32", argLength: 2},
   148  	{name: "Rsh32Ux64", argLength: 2},
   149  	{name: "Rsh64Ux8", argLength: 2},
   150  	{name: "Rsh64Ux16", argLength: 2},
   151  	{name: "Rsh64Ux32", argLength: 2},
   152  	{name: "Rsh64Ux64", argLength: 2},
   153  
   154  	// 2-input comparisons
   155  	{name: "Eq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 == arg1
   156  	{name: "Eq16", argLength: 2, commutative: true, typ: "Bool"},
   157  	{name: "Eq32", argLength: 2, commutative: true, typ: "Bool"},
   158  	{name: "Eq64", argLength: 2, commutative: true, typ: "Bool"},
   159  	{name: "EqPtr", argLength: 2, commutative: true, typ: "Bool"},
   160  	{name: "EqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   161  	{name: "EqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   162  	{name: "Eq32F", argLength: 2, typ: "Bool"},
   163  	{name: "Eq64F", argLength: 2, typ: "Bool"},
   164  
   165  	{name: "Neq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1
   166  	{name: "Neq16", argLength: 2, commutative: true, typ: "Bool"},
   167  	{name: "Neq32", argLength: 2, commutative: true, typ: "Bool"},
   168  	{name: "Neq64", argLength: 2, commutative: true, typ: "Bool"},
   169  	{name: "NeqPtr", argLength: 2, commutative: true, typ: "Bool"},
   170  	{name: "NeqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   171  	{name: "NeqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   172  	{name: "Neq32F", argLength: 2, typ: "Bool"},
   173  	{name: "Neq64F", argLength: 2},
   174  
   175  	{name: "Less8", argLength: 2, typ: "Bool"},  // arg0 < arg1, signed
   176  	{name: "Less8U", argLength: 2, typ: "Bool"}, // arg0 < arg1, unsigned
   177  	{name: "Less16", argLength: 2, typ: "Bool"},
   178  	{name: "Less16U", argLength: 2, typ: "Bool"},
   179  	{name: "Less32", argLength: 2, typ: "Bool"},
   180  	{name: "Less32U", argLength: 2, typ: "Bool"},
   181  	{name: "Less64", argLength: 2, typ: "Bool"},
   182  	{name: "Less64U", argLength: 2, typ: "Bool"},
   183  	{name: "Less32F", argLength: 2, typ: "Bool"},
   184  	{name: "Less64F", argLength: 2, typ: "Bool"},
   185  
   186  	{name: "Leq8", argLength: 2, typ: "Bool"},  // arg0 <= arg1, signed
   187  	{name: "Leq8U", argLength: 2, typ: "Bool"}, // arg0 <= arg1, unsigned
   188  	{name: "Leq16", argLength: 2, typ: "Bool"},
   189  	{name: "Leq16U", argLength: 2, typ: "Bool"},
   190  	{name: "Leq32", argLength: 2, typ: "Bool"},
   191  	{name: "Leq32U", argLength: 2, typ: "Bool"},
   192  	{name: "Leq64", argLength: 2, typ: "Bool"},
   193  	{name: "Leq64U", argLength: 2, typ: "Bool"},
   194  	{name: "Leq32F", argLength: 2, typ: "Bool"},
   195  	{name: "Leq64F", argLength: 2, typ: "Bool"},
   196  
   197  	{name: "Greater8", argLength: 2, typ: "Bool"},  // arg0 > arg1, signed
   198  	{name: "Greater8U", argLength: 2, typ: "Bool"}, // arg0 > arg1, unsigned
   199  	{name: "Greater16", argLength: 2, typ: "Bool"},
   200  	{name: "Greater16U", argLength: 2, typ: "Bool"},
   201  	{name: "Greater32", argLength: 2, typ: "Bool"},
   202  	{name: "Greater32U", argLength: 2, typ: "Bool"},
   203  	{name: "Greater64", argLength: 2, typ: "Bool"},
   204  	{name: "Greater64U", argLength: 2, typ: "Bool"},
   205  	{name: "Greater32F", argLength: 2, typ: "Bool"},
   206  	{name: "Greater64F", argLength: 2, typ: "Bool"},
   207  
   208  	{name: "Geq8", argLength: 2, typ: "Bool"},  // arg0 <= arg1, signed
   209  	{name: "Geq8U", argLength: 2, typ: "Bool"}, // arg0 <= arg1, unsigned
   210  	{name: "Geq16", argLength: 2, typ: "Bool"},
   211  	{name: "Geq16U", argLength: 2, typ: "Bool"},
   212  	{name: "Geq32", argLength: 2, typ: "Bool"},
   213  	{name: "Geq32U", argLength: 2, typ: "Bool"},
   214  	{name: "Geq64", argLength: 2, typ: "Bool"},
   215  	{name: "Geq64U", argLength: 2, typ: "Bool"},
   216  	{name: "Geq32F", argLength: 2, typ: "Bool"},
   217  	{name: "Geq64F", argLength: 2, typ: "Bool"},
   218  
   219  	// boolean ops
   220  	{name: "AndB", argLength: 2, typ: "Bool"}, // arg0 && arg1 (not shortcircuited)
   221  	{name: "OrB", argLength: 2, typ: "Bool"},  // arg0 || arg1 (not shortcircuited)
   222  	{name: "EqB", argLength: 2, typ: "Bool"},  // arg0 == arg1
   223  	{name: "NeqB", argLength: 2, typ: "Bool"}, // arg0 != arg1
   224  	{name: "Not", argLength: 1, typ: "Bool"},  // !arg0, boolean
   225  
   226  	// 1-input ops
   227  	{name: "Neg8", argLength: 1}, // -arg0
   228  	{name: "Neg16", argLength: 1},
   229  	{name: "Neg32", argLength: 1},
   230  	{name: "Neg64", argLength: 1},
   231  	{name: "Neg32F", argLength: 1},
   232  	{name: "Neg64F", argLength: 1},
   233  
   234  	{name: "Com8", argLength: 1}, // ^arg0
   235  	{name: "Com16", argLength: 1},
   236  	{name: "Com32", argLength: 1},
   237  	{name: "Com64", argLength: 1},
   238  
   239  	{name: "Ctz32", argLength: 1}, // Count trailing (low  order) zeroes (returns 0-32)
   240  	{name: "Ctz64", argLength: 1}, // Count trailing zeroes (returns 0-64)
   241  
   242  	{name: "Bswap32", argLength: 1}, // Swap bytes
   243  	{name: "Bswap64", argLength: 1}, // Swap bytes
   244  
   245  	{name: "Sqrt", argLength: 1}, // sqrt(arg0), float64 only
   246  
   247  	// Data movement, max argument length for Phi is indefinite so just pick
   248  	// a really large number
   249  	{name: "Phi", argLength: -1}, // select an argument based on which predecessor block we came from
   250  	{name: "Copy", argLength: 1}, // output = arg0
   251  	// Convert converts between pointers and integers.
   252  	// We have a special op for this so as to not confuse GC
   253  	// (particularly stack maps).  It takes a memory arg so it
   254  	// gets correctly ordered with respect to GC safepoints.
   255  	// arg0=ptr/int arg1=mem, output=int/ptr
   256  	{name: "Convert", argLength: 2},
   257  
   258  	// constants. Constant values are stored in the aux or
   259  	// auxint fields.
   260  	{name: "ConstBool", aux: "Bool"},     // auxint is 0 for false and 1 for true
   261  	{name: "ConstString", aux: "String"}, // value is aux.(string)
   262  	{name: "ConstNil", typ: "BytePtr"},   // nil pointer
   263  	{name: "Const8", aux: "Int8"},        // auxint is sign-extended 8 bits
   264  	{name: "Const16", aux: "Int16"},      // auxint is sign-extended 16 bits
   265  	{name: "Const32", aux: "Int32"},      // auxint is sign-extended 32 bits
   266  	{name: "Const64", aux: "Int64"},      // value is auxint
   267  	{name: "Const32F", aux: "Float32"},   // value is math.Float64frombits(uint64(auxint)) and is exactly prepresentable as float 32
   268  	{name: "Const64F", aux: "Float64"},   // value is math.Float64frombits(uint64(auxint))
   269  	{name: "ConstInterface"},             // nil interface
   270  	{name: "ConstSlice"},                 // nil slice
   271  
   272  	// Constant-like things
   273  	{name: "InitMem"},            // memory input to the function.
   274  	{name: "Arg", aux: "SymOff"}, // argument to the function.  aux=GCNode of arg, off = offset in that arg.
   275  
   276  	// The address of a variable.  arg0 is the base pointer (SB or SP, depending
   277  	// on whether it is a global or stack variable).  The Aux field identifies the
   278  	// variable. It will be either an *ExternSymbol (with arg0=SB), *ArgSymbol (arg0=SP),
   279  	// or *AutoSymbol (arg0=SP).
   280  	{name: "Addr", argLength: 1, aux: "Sym"}, // Address of a variable.  Arg0=SP or SB.  Aux identifies the variable.
   281  
   282  	{name: "SP"},                 // stack pointer
   283  	{name: "SB", typ: "Uintptr"}, // static base pointer (a.k.a. globals pointer)
   284  	{name: "Func", aux: "Sym"},   // entry address of a function
   285  	{name: "Invalid"},            // unused value
   286  
   287  	// Memory operations
   288  	{name: "Load", argLength: 2},                                  // Load from arg0.  arg1=memory
   289  	{name: "Store", argLength: 3, typ: "Mem", aux: "Int64"},       // Store arg1 to arg0.  arg2=memory, auxint=size.  Returns memory.
   290  	{name: "Move", argLength: 3, typ: "Mem", aux: "SizeAndAlign"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size+alignment.  Returns memory.
   291  	{name: "Zero", argLength: 2, typ: "Mem", aux: "SizeAndAlign"}, // arg0=destptr, arg1=mem, auxint=size+alignment. Returns memory.
   292  
   293  	// Memory operations with write barriers.
   294  	// Expand to runtime calls. Write barrier will be removed if write on stack.
   295  	{name: "StoreWB", argLength: 3, typ: "Mem", aux: "Int64"},                  // Store arg1 to arg0. arg2=memory, auxint=size.  Returns memory.
   296  	{name: "MoveWB", argLength: 3, typ: "Mem", aux: "SymSizeAndAlign"},         // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size+alignment, aux=symbol-of-type (for typedmemmove).  Returns memory.
   297  	{name: "MoveWBVolatile", argLength: 3, typ: "Mem", aux: "SymSizeAndAlign"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size+alignment, aux=symbol-of-type (for typedmemmove).  Returns memory. Src is volatile, i.e. needs to move to a temp space before calling typedmemmove.
   298  	{name: "ZeroWB", argLength: 2, typ: "Mem", aux: "SymSizeAndAlign"},         // arg0=destptr, arg1=mem, auxint=size+alignment, aux=symbol-of-type. Returns memory.
   299  
   300  	// Function calls. Arguments to the call have already been written to the stack.
   301  	// Return values appear on the stack. The method receiver, if any, is treated
   302  	// as a phantom first argument.
   303  	{name: "ClosureCall", argLength: 3, aux: "Int64", call: true}, // arg0=code pointer, arg1=context ptr, arg2=memory.  auxint=arg size.  Returns memory.
   304  	{name: "StaticCall", argLength: 1, aux: "SymOff", call: true}, // call function aux.(*gc.Sym), arg0=memory.  auxint=arg size.  Returns memory.
   305  	{name: "DeferCall", argLength: 1, aux: "Int64", call: true},   // defer call.  arg0=memory, auxint=arg size.  Returns memory.
   306  	{name: "GoCall", argLength: 1, aux: "Int64", call: true},      // go call.  arg0=memory, auxint=arg size.  Returns memory.
   307  	{name: "InterCall", argLength: 2, aux: "Int64", call: true},   // interface call.  arg0=code pointer, arg1=memory, auxint=arg size.  Returns memory.
   308  
   309  	// Conversions: signed extensions, zero (unsigned) extensions, truncations
   310  	{name: "SignExt8to16", argLength: 1, typ: "Int16"},
   311  	{name: "SignExt8to32", argLength: 1, typ: "Int32"},
   312  	{name: "SignExt8to64", argLength: 1, typ: "Int64"},
   313  	{name: "SignExt16to32", argLength: 1, typ: "Int32"},
   314  	{name: "SignExt16to64", argLength: 1, typ: "Int64"},
   315  	{name: "SignExt32to64", argLength: 1, typ: "Int64"},
   316  	{name: "ZeroExt8to16", argLength: 1, typ: "UInt16"},
   317  	{name: "ZeroExt8to32", argLength: 1, typ: "UInt32"},
   318  	{name: "ZeroExt8to64", argLength: 1, typ: "UInt64"},
   319  	{name: "ZeroExt16to32", argLength: 1, typ: "UInt32"},
   320  	{name: "ZeroExt16to64", argLength: 1, typ: "UInt64"},
   321  	{name: "ZeroExt32to64", argLength: 1, typ: "UInt64"},
   322  	{name: "Trunc16to8", argLength: 1},
   323  	{name: "Trunc32to8", argLength: 1},
   324  	{name: "Trunc32to16", argLength: 1},
   325  	{name: "Trunc64to8", argLength: 1},
   326  	{name: "Trunc64to16", argLength: 1},
   327  	{name: "Trunc64to32", argLength: 1},
   328  
   329  	{name: "Cvt32to32F", argLength: 1},
   330  	{name: "Cvt32to64F", argLength: 1},
   331  	{name: "Cvt64to32F", argLength: 1},
   332  	{name: "Cvt64to64F", argLength: 1},
   333  	{name: "Cvt32Fto32", argLength: 1},
   334  	{name: "Cvt32Fto64", argLength: 1},
   335  	{name: "Cvt64Fto32", argLength: 1},
   336  	{name: "Cvt64Fto64", argLength: 1},
   337  	{name: "Cvt32Fto64F", argLength: 1},
   338  	{name: "Cvt64Fto32F", argLength: 1},
   339  
   340  	// Automatically inserted safety checks
   341  	{name: "IsNonNil", argLength: 1, typ: "Bool"},        // arg0 != nil
   342  	{name: "IsInBounds", argLength: 2, typ: "Bool"},      // 0 <= arg0 < arg1. arg1 is guaranteed >= 0.
   343  	{name: "IsSliceInBounds", argLength: 2, typ: "Bool"}, // 0 <= arg0 <= arg1. arg1 is guaranteed >= 0.
   344  	{name: "NilCheck", argLength: 2, typ: "Void"},        // arg0=ptr, arg1=mem. Panics if arg0 is nil. Returns void.
   345  
   346  	// Pseudo-ops
   347  	{name: "GetG", argLength: 1}, // runtime.getg() (read g pointer). arg0=mem
   348  	{name: "GetClosurePtr"},      // get closure pointer from dedicated register
   349  
   350  	// Indexing operations
   351  	{name: "PtrIndex", argLength: 2},             // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type
   352  	{name: "OffPtr", argLength: 1, aux: "Int64"}, // arg0 + auxint (arg0 and result are pointers)
   353  
   354  	// Slices
   355  	{name: "SliceMake", argLength: 3},                // arg0=ptr, arg1=len, arg2=cap
   356  	{name: "SlicePtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0)
   357  	{name: "SliceLen", argLength: 1},                 // len(arg0)
   358  	{name: "SliceCap", argLength: 1},                 // cap(arg0)
   359  
   360  	// Complex (part/whole)
   361  	{name: "ComplexMake", argLength: 2}, // arg0=real, arg1=imag
   362  	{name: "ComplexReal", argLength: 1}, // real(arg0)
   363  	{name: "ComplexImag", argLength: 1}, // imag(arg0)
   364  
   365  	// Strings
   366  	{name: "StringMake", argLength: 2},                // arg0=ptr, arg1=len
   367  	{name: "StringPtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0)
   368  	{name: "StringLen", argLength: 1, typ: "Int"},     // len(arg0)
   369  
   370  	// Interfaces
   371  	{name: "IMake", argLength: 2},                // arg0=itab, arg1=data
   372  	{name: "ITab", argLength: 1, typ: "BytePtr"}, // arg0=interface, returns itable field
   373  	{name: "IData", argLength: 1},                // arg0=interface, returns data field
   374  
   375  	// Structs
   376  	{name: "StructMake0"},                              // Returns struct with 0 fields.
   377  	{name: "StructMake1", argLength: 1},                // arg0=field0.  Returns struct.
   378  	{name: "StructMake2", argLength: 2},                // arg0,arg1=field0,field1.  Returns struct.
   379  	{name: "StructMake3", argLength: 3},                // arg0..2=field0..2.  Returns struct.
   380  	{name: "StructMake4", argLength: 4},                // arg0..3=field0..3.  Returns struct.
   381  	{name: "StructSelect", argLength: 1, aux: "Int64"}, // arg0=struct, auxint=field index.  Returns the auxint'th field.
   382  
   383  	// Arrays
   384  	{name: "ArrayMake0"},                              // Returns array with 0 elements
   385  	{name: "ArrayMake1", argLength: 1},                // Returns array with 1 element
   386  	{name: "ArraySelect", argLength: 1, aux: "Int64"}, // arg0=array, auxint=index. Returns a[i].
   387  
   388  	// Spill&restore ops for the register allocator. These are
   389  	// semantically identical to OpCopy; they do not take/return
   390  	// stores like regular memory ops do. We can get away without memory
   391  	// args because we know there is no aliasing of spill slots on the stack.
   392  	{name: "StoreReg", argLength: 1},
   393  	{name: "LoadReg", argLength: 1},
   394  
   395  	// Used during ssa construction. Like Copy, but the arg has not been specified yet.
   396  	{name: "FwdRef", aux: "Sym"},
   397  
   398  	// Unknown value. Used for Values whose values don't matter because they are dead code.
   399  	{name: "Unknown"},
   400  
   401  	{name: "VarDef", argLength: 1, aux: "Sym", typ: "Mem"}, // aux is a *gc.Node of a variable that is about to be initialized.  arg0=mem, returns mem
   402  	{name: "VarKill", argLength: 1, aux: "Sym"},            // aux is a *gc.Node of a variable that is known to be dead.  arg0=mem, returns mem
   403  	{name: "VarLive", argLength: 1, aux: "Sym"},            // aux is a *gc.Node of a variable that must be kept live.  arg0=mem, returns mem
   404  	{name: "KeepAlive", argLength: 2, typ: "Mem"},          // arg[0] is a value that must be kept alive until this mark.  arg[1]=mem, returns mem
   405  
   406  	// Ops for breaking 64-bit operations on 32-bit architectures
   407  	{name: "Int64Make", argLength: 2, typ: "UInt64"}, // arg0=hi, arg1=lo
   408  	{name: "Int64Hi", argLength: 1, typ: "UInt32"},   // high 32-bit of arg0
   409  	{name: "Int64Lo", argLength: 1, typ: "UInt32"},   // low 32-bit of arg0
   410  
   411  	{name: "Add32carry", argLength: 2, commutative: true, typ: "(UInt32,Flags)"}, // arg0 + arg1, returns (value, carry)
   412  	{name: "Add32withcarry", argLength: 3, commutative: true},                    // arg0 + arg1 + arg2, arg2=carry (0 or 1)
   413  
   414  	{name: "Sub32carry", argLength: 2, typ: "(UInt32,Flags)"}, // arg0 - arg1, returns (value, carry)
   415  	{name: "Sub32withcarry", argLength: 3},                    // arg0 - arg1 - arg2, arg2=carry (0 or 1)
   416  
   417  	{name: "Signmask", argLength: 1, typ: "Int32"},  // 0 if arg0 >= 0, -1 if arg0 < 0
   418  	{name: "Zeromask", argLength: 1, typ: "UInt32"}, // 0 if arg0 == 0, 0xffffffff if arg0 != 0
   419  	{name: "Slicemask", argLength: 1},               // 0 if arg0 == 0, -1 if arg0 > 0, undef if arg0<0. Type is native int size.
   420  
   421  	{name: "Cvt32Uto32F", argLength: 1}, // uint32 -> float32, only used on 32-bit arch
   422  	{name: "Cvt32Uto64F", argLength: 1}, // uint32 -> float64, only used on 32-bit arch
   423  	{name: "Cvt32Fto32U", argLength: 1}, // float32 -> uint32, only used on 32-bit arch
   424  	{name: "Cvt64Fto32U", argLength: 1}, // float64 -> uint32, only used on 32-bit arch
   425  	{name: "Cvt64Uto32F", argLength: 1}, // uint64 -> float32, only used on archs that has the instruction
   426  	{name: "Cvt64Uto64F", argLength: 1}, // uint64 -> float64, only used on archs that has the instruction
   427  	{name: "Cvt32Fto64U", argLength: 1}, // float32 -> uint64, only used on archs that has the instruction
   428  	{name: "Cvt64Fto64U", argLength: 1}, // float64 -> uint64, only used on archs that has the instruction
   429  
   430  	// pseudo-ops for breaking Tuple
   431  	{name: "Select0", argLength: 1}, // the first component of a tuple
   432  	{name: "Select1", argLength: 1}, // the second component of a tuple
   433  
   434  	// Atomic operations used for semantically inlining runtime/internal/atomic.
   435  	// Atomic loads return a new memory so that the loads are properly ordered
   436  	// with respect to other loads and stores.
   437  	// TODO: use for sync/atomic at some point.
   438  	{name: "AtomicLoad32", argLength: 2, typ: "(UInt32,Mem)"},         // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   439  	{name: "AtomicLoad64", argLength: 2, typ: "(UInt64,Mem)"},         // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   440  	{name: "AtomicLoadPtr", argLength: 2, typ: "(BytePtr,Mem)"},       // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   441  	{name: "AtomicStore32", argLength: 3, typ: "Mem"},                 // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   442  	{name: "AtomicStore64", argLength: 3, typ: "Mem"},                 // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   443  	{name: "AtomicStorePtrNoWB", argLength: 3, typ: "Mem"},            // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   444  	{name: "AtomicExchange32", argLength: 3, typ: "(UInt32,Mem)"},     // Store arg1 to *arg0.  arg2=memory.  Returns old contents of *arg0 and new memory.
   445  	{name: "AtomicExchange64", argLength: 3, typ: "(UInt64,Mem)"},     // Store arg1 to *arg0.  arg2=memory.  Returns old contents of *arg0 and new memory.
   446  	{name: "AtomicAdd32", argLength: 3, typ: "(UInt32,Mem)"},          // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   447  	{name: "AtomicAdd64", argLength: 3, typ: "(UInt64,Mem)"},          // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   448  	{name: "AtomicCompareAndSwap32", argLength: 4, typ: "(Bool,Mem)"}, // if *arg0==arg1, then set *arg0=arg2.  Returns true iff store happens and new memory.
   449  	{name: "AtomicCompareAndSwap64", argLength: 4, typ: "(Bool,Mem)"}, // if *arg0==arg1, then set *arg0=arg2.  Returns true iff store happens and new memory.
   450  	{name: "AtomicAnd8", argLength: 3, typ: "Mem"},                    // *arg0 &= arg1.  arg2=memory.  Returns memory.
   451  	{name: "AtomicOr8", argLength: 3, typ: "Mem"},                     // *arg0 |= arg1.  arg2=memory.  Returns memory.
   452  }
   453  
   454  //     kind           control    successors       implicit exit
   455  //   ----------------------------------------------------------
   456  //     Exit        return mem                []             yes
   457  //      Ret        return mem                []             yes
   458  //   RetJmp        return mem                []             yes
   459  //    Plain               nil            [next]
   460  //       If   a boolean Value      [then, else]
   461  //     Call               mem            [next]             yes  (control opcode should be OpCall or OpStaticCall)
   462  //    Check              void            [next]             yes  (control opcode should be Op{Lowered}NilCheck)
   463  //    First               nil    [always,never]
   464  
   465  var genericBlocks = []blockData{
   466  	{name: "Plain"},  // a single successor
   467  	{name: "If"},     // 2 successors, if control goto Succs[0] else goto Succs[1]
   468  	{name: "Defer"},  // 2 successors, Succs[0]=defer queued, Succs[1]=defer recovered. control is call op (of memory type)
   469  	{name: "Ret"},    // no successors, control value is memory result
   470  	{name: "RetJmp"}, // no successors, jumps to b.Aux.(*gc.Sym)
   471  	{name: "Exit"},   // no successors, control value generates a panic
   472  
   473  	// transient block state used for dead code removal
   474  	{name: "First"}, // 2 successors, always takes the first one (second is dead)
   475  }
   476  
   477  func init() {
   478  	archs = append(archs, arch{
   479  		name:    "generic",
   480  		ops:     genericOps,
   481  		blocks:  genericBlocks,
   482  		generic: true,
   483  	})
   484  }