...

Source file src/pkg/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	// +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	var genericOps = []opData{
    21		// 2-input arithmetic
    22		// Types must be consistent with Go typing. Add, for example, must take two values
    23		// of the same type and produces that same type.
    24		{name: "Add8", argLength: 2, commutative: true}, // arg0 + arg1
    25		{name: "Add16", argLength: 2, commutative: true},
    26		{name: "Add32", argLength: 2, commutative: true},
    27		{name: "Add64", argLength: 2, commutative: true},
    28		{name: "AddPtr", argLength: 2}, // For address calculations.  arg0 is a pointer and arg1 is an int.
    29		{name: "Add32F", argLength: 2, commutative: true},
    30		{name: "Add64F", argLength: 2, commutative: true},
    31	
    32		{name: "Sub8", argLength: 2}, // arg0 - arg1
    33		{name: "Sub16", argLength: 2},
    34		{name: "Sub32", argLength: 2},
    35		{name: "Sub64", argLength: 2},
    36		{name: "SubPtr", argLength: 2},
    37		{name: "Sub32F", argLength: 2},
    38		{name: "Sub64F", argLength: 2},
    39	
    40		{name: "Mul8", argLength: 2, commutative: true}, // arg0 * arg1
    41		{name: "Mul16", argLength: 2, commutative: true},
    42		{name: "Mul32", argLength: 2, commutative: true},
    43		{name: "Mul64", argLength: 2, commutative: true},
    44		{name: "Mul32F", argLength: 2, commutative: true},
    45		{name: "Mul64F", argLength: 2, commutative: true},
    46	
    47		{name: "Div32F", argLength: 2}, // arg0 / arg1
    48		{name: "Div64F", argLength: 2},
    49	
    50		{name: "Hmul32", argLength: 2, commutative: true},
    51		{name: "Hmul32u", argLength: 2, commutative: true},
    52		{name: "Hmul64", argLength: 2, commutative: true},
    53		{name: "Hmul64u", argLength: 2, commutative: true},
    54	
    55		{name: "Mul32uhilo", argLength: 2, typ: "(UInt32,UInt32)", commutative: true}, // arg0 * arg1, returns (hi, lo)
    56		{name: "Mul64uhilo", argLength: 2, typ: "(UInt64,UInt64)", commutative: true}, // arg0 * arg1, returns (hi, lo)
    57	
    58		{name: "Mul32uover", argLength: 2, typ: "(UInt32,Bool)", commutative: true}, // Let x = arg0*arg1 (full 32x32-> 64 unsigned multiply), returns (uint32(x), (uint32(x) != x))
    59		{name: "Mul64uover", argLength: 2, typ: "(UInt64,Bool)", commutative: true}, // Let x = arg0*arg1 (full 64x64->128 unsigned multiply), returns (uint64(x), (uint64(x) != x))
    60	
    61		// Weird special instructions for use in the strength reduction of divides.
    62		// These ops compute unsigned (arg0 + arg1) / 2, correct to all
    63		// 32/64 bits, even when the intermediate result of the add has 33/65 bits.
    64		// These ops can assume arg0 >= arg1.
    65		// Note: these ops aren't commutative!
    66		{name: "Avg32u", argLength: 2, typ: "UInt32"}, // 32-bit platforms only
    67		{name: "Avg64u", argLength: 2, typ: "UInt64"}, // 64-bit platforms only
    68	
    69		// For Div16, Div32 and Div64, AuxInt non-zero means that the divisor has been proved to be not -1
    70		// or that the dividend is not the most negative value.
    71		{name: "Div8", argLength: 2},  // arg0 / arg1, signed
    72		{name: "Div8u", argLength: 2}, // arg0 / arg1, unsigned
    73		{name: "Div16", argLength: 2, aux: "Bool"},
    74		{name: "Div16u", argLength: 2},
    75		{name: "Div32", argLength: 2, aux: "Bool"},
    76		{name: "Div32u", argLength: 2},
    77		{name: "Div64", argLength: 2, aux: "Bool"},
    78		{name: "Div64u", argLength: 2},
    79		{name: "Div128u", argLength: 3}, // arg0:arg1 / arg2 (128-bit divided by 64-bit), returns (q, r)
    80	
    81		// For Mod16, Mod32 and Mod64, AuxInt non-zero means that the divisor has been proved to be not -1.
    82		{name: "Mod8", argLength: 2},  // arg0 % arg1, signed
    83		{name: "Mod8u", argLength: 2}, // arg0 % arg1, unsigned
    84		{name: "Mod16", argLength: 2, aux: "Bool"},
    85		{name: "Mod16u", argLength: 2},
    86		{name: "Mod32", argLength: 2, aux: "Bool"},
    87		{name: "Mod32u", argLength: 2},
    88		{name: "Mod64", argLength: 2, aux: "Bool"},
    89		{name: "Mod64u", argLength: 2},
    90	
    91		{name: "And8", argLength: 2, commutative: true}, // arg0 & arg1
    92		{name: "And16", argLength: 2, commutative: true},
    93		{name: "And32", argLength: 2, commutative: true},
    94		{name: "And64", argLength: 2, commutative: true},
    95	
    96		{name: "Or8", argLength: 2, commutative: true}, // arg0 | arg1
    97		{name: "Or16", argLength: 2, commutative: true},
    98		{name: "Or32", argLength: 2, commutative: true},
    99		{name: "Or64", argLength: 2, commutative: true},
   100	
   101		{name: "Xor8", argLength: 2, commutative: true}, // arg0 ^ arg1
   102		{name: "Xor16", argLength: 2, commutative: true},
   103		{name: "Xor32", argLength: 2, commutative: true},
   104		{name: "Xor64", argLength: 2, commutative: true},
   105	
   106		// For shifts, AxB means the shifted value has A bits and the shift amount has B bits.
   107		// Shift amounts are considered unsigned.
   108		// If arg1 is known to be less than the number of bits in arg0,
   109		// then auxInt may be set to 1.
   110		// This enables better code generation on some platforms.
   111		{name: "Lsh8x8", argLength: 2, aux: "Bool"}, // arg0 << arg1
   112		{name: "Lsh8x16", argLength: 2, aux: "Bool"},
   113		{name: "Lsh8x32", argLength: 2, aux: "Bool"},
   114		{name: "Lsh8x64", argLength: 2, aux: "Bool"},
   115		{name: "Lsh16x8", argLength: 2, aux: "Bool"},
   116		{name: "Lsh16x16", argLength: 2, aux: "Bool"},
   117		{name: "Lsh16x32", argLength: 2, aux: "Bool"},
   118		{name: "Lsh16x64", argLength: 2, aux: "Bool"},
   119		{name: "Lsh32x8", argLength: 2, aux: "Bool"},
   120		{name: "Lsh32x16", argLength: 2, aux: "Bool"},
   121		{name: "Lsh32x32", argLength: 2, aux: "Bool"},
   122		{name: "Lsh32x64", argLength: 2, aux: "Bool"},
   123		{name: "Lsh64x8", argLength: 2, aux: "Bool"},
   124		{name: "Lsh64x16", argLength: 2, aux: "Bool"},
   125		{name: "Lsh64x32", argLength: 2, aux: "Bool"},
   126		{name: "Lsh64x64", argLength: 2, aux: "Bool"},
   127	
   128		{name: "Rsh8x8", argLength: 2, aux: "Bool"}, // arg0 >> arg1, signed
   129		{name: "Rsh8x16", argLength: 2, aux: "Bool"},
   130		{name: "Rsh8x32", argLength: 2, aux: "Bool"},
   131		{name: "Rsh8x64", argLength: 2, aux: "Bool"},
   132		{name: "Rsh16x8", argLength: 2, aux: "Bool"},
   133		{name: "Rsh16x16", argLength: 2, aux: "Bool"},
   134		{name: "Rsh16x32", argLength: 2, aux: "Bool"},
   135		{name: "Rsh16x64", argLength: 2, aux: "Bool"},
   136		{name: "Rsh32x8", argLength: 2, aux: "Bool"},
   137		{name: "Rsh32x16", argLength: 2, aux: "Bool"},
   138		{name: "Rsh32x32", argLength: 2, aux: "Bool"},
   139		{name: "Rsh32x64", argLength: 2, aux: "Bool"},
   140		{name: "Rsh64x8", argLength: 2, aux: "Bool"},
   141		{name: "Rsh64x16", argLength: 2, aux: "Bool"},
   142		{name: "Rsh64x32", argLength: 2, aux: "Bool"},
   143		{name: "Rsh64x64", argLength: 2, aux: "Bool"},
   144	
   145		{name: "Rsh8Ux8", argLength: 2, aux: "Bool"}, // arg0 >> arg1, unsigned
   146		{name: "Rsh8Ux16", argLength: 2, aux: "Bool"},
   147		{name: "Rsh8Ux32", argLength: 2, aux: "Bool"},
   148		{name: "Rsh8Ux64", argLength: 2, aux: "Bool"},
   149		{name: "Rsh16Ux8", argLength: 2, aux: "Bool"},
   150		{name: "Rsh16Ux16", argLength: 2, aux: "Bool"},
   151		{name: "Rsh16Ux32", argLength: 2, aux: "Bool"},
   152		{name: "Rsh16Ux64", argLength: 2, aux: "Bool"},
   153		{name: "Rsh32Ux8", argLength: 2, aux: "Bool"},
   154		{name: "Rsh32Ux16", argLength: 2, aux: "Bool"},
   155		{name: "Rsh32Ux32", argLength: 2, aux: "Bool"},
   156		{name: "Rsh32Ux64", argLength: 2, aux: "Bool"},
   157		{name: "Rsh64Ux8", argLength: 2, aux: "Bool"},
   158		{name: "Rsh64Ux16", argLength: 2, aux: "Bool"},
   159		{name: "Rsh64Ux32", argLength: 2, aux: "Bool"},
   160		{name: "Rsh64Ux64", argLength: 2, aux: "Bool"},
   161	
   162		// 2-input comparisons
   163		{name: "Eq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 == arg1
   164		{name: "Eq16", argLength: 2, commutative: true, typ: "Bool"},
   165		{name: "Eq32", argLength: 2, commutative: true, typ: "Bool"},
   166		{name: "Eq64", argLength: 2, commutative: true, typ: "Bool"},
   167		{name: "EqPtr", argLength: 2, commutative: true, typ: "Bool"},
   168		{name: "EqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   169		{name: "EqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   170		{name: "Eq32F", argLength: 2, commutative: true, typ: "Bool"},
   171		{name: "Eq64F", argLength: 2, commutative: true, typ: "Bool"},
   172	
   173		{name: "Neq8", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1
   174		{name: "Neq16", argLength: 2, commutative: true, typ: "Bool"},
   175		{name: "Neq32", argLength: 2, commutative: true, typ: "Bool"},
   176		{name: "Neq64", argLength: 2, commutative: true, typ: "Bool"},
   177		{name: "NeqPtr", argLength: 2, commutative: true, typ: "Bool"},
   178		{name: "NeqInter", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   179		{name: "NeqSlice", argLength: 2, typ: "Bool"}, // arg0 or arg1 is nil; other cases handled by frontend
   180		{name: "Neq32F", argLength: 2, commutative: true, typ: "Bool"},
   181		{name: "Neq64F", argLength: 2, commutative: true, typ: "Bool"},
   182	
   183		{name: "Less8", argLength: 2, typ: "Bool"},  // arg0 < arg1, signed
   184		{name: "Less8U", argLength: 2, typ: "Bool"}, // arg0 < arg1, unsigned
   185		{name: "Less16", argLength: 2, typ: "Bool"},
   186		{name: "Less16U", argLength: 2, typ: "Bool"},
   187		{name: "Less32", argLength: 2, typ: "Bool"},
   188		{name: "Less32U", argLength: 2, typ: "Bool"},
   189		{name: "Less64", argLength: 2, typ: "Bool"},
   190		{name: "Less64U", argLength: 2, typ: "Bool"},
   191		{name: "Less32F", argLength: 2, typ: "Bool"},
   192		{name: "Less64F", argLength: 2, typ: "Bool"},
   193	
   194		{name: "Leq8", argLength: 2, typ: "Bool"},  // arg0 <= arg1, signed
   195		{name: "Leq8U", argLength: 2, typ: "Bool"}, // arg0 <= arg1, unsigned
   196		{name: "Leq16", argLength: 2, typ: "Bool"},
   197		{name: "Leq16U", argLength: 2, typ: "Bool"},
   198		{name: "Leq32", argLength: 2, typ: "Bool"},
   199		{name: "Leq32U", argLength: 2, typ: "Bool"},
   200		{name: "Leq64", argLength: 2, typ: "Bool"},
   201		{name: "Leq64U", argLength: 2, typ: "Bool"},
   202		{name: "Leq32F", argLength: 2, typ: "Bool"},
   203		{name: "Leq64F", argLength: 2, typ: "Bool"},
   204	
   205		{name: "Greater8", argLength: 2, typ: "Bool"},  // arg0 > arg1, signed
   206		{name: "Greater8U", argLength: 2, typ: "Bool"}, // arg0 > arg1, unsigned
   207		{name: "Greater16", argLength: 2, typ: "Bool"},
   208		{name: "Greater16U", argLength: 2, typ: "Bool"},
   209		{name: "Greater32", argLength: 2, typ: "Bool"},
   210		{name: "Greater32U", argLength: 2, typ: "Bool"},
   211		{name: "Greater64", argLength: 2, typ: "Bool"},
   212		{name: "Greater64U", argLength: 2, typ: "Bool"},
   213		{name: "Greater32F", argLength: 2, typ: "Bool"},
   214		{name: "Greater64F", argLength: 2, typ: "Bool"},
   215	
   216		{name: "Geq8", argLength: 2, typ: "Bool"},  // arg0 <= arg1, signed
   217		{name: "Geq8U", argLength: 2, typ: "Bool"}, // arg0 <= arg1, unsigned
   218		{name: "Geq16", argLength: 2, typ: "Bool"},
   219		{name: "Geq16U", argLength: 2, typ: "Bool"},
   220		{name: "Geq32", argLength: 2, typ: "Bool"},
   221		{name: "Geq32U", argLength: 2, typ: "Bool"},
   222		{name: "Geq64", argLength: 2, typ: "Bool"},
   223		{name: "Geq64U", argLength: 2, typ: "Bool"},
   224		{name: "Geq32F", argLength: 2, typ: "Bool"},
   225		{name: "Geq64F", argLength: 2, typ: "Bool"},
   226	
   227		// the type of a CondSelect is the same as the type of its first
   228		// two arguments, which should be register-width scalars; the third
   229		// argument should be a boolean
   230		{name: "CondSelect", argLength: 3}, // arg2 ? arg0 : arg1
   231	
   232		// boolean ops
   233		{name: "AndB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 && arg1 (not shortcircuited)
   234		{name: "OrB", argLength: 2, commutative: true, typ: "Bool"},  // arg0 || arg1 (not shortcircuited)
   235		{name: "EqB", argLength: 2, commutative: true, typ: "Bool"},  // arg0 == arg1
   236		{name: "NeqB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1
   237		{name: "Not", argLength: 1, typ: "Bool"},                     // !arg0, boolean
   238	
   239		// 1-input ops
   240		{name: "Neg8", argLength: 1}, // -arg0
   241		{name: "Neg16", argLength: 1},
   242		{name: "Neg32", argLength: 1},
   243		{name: "Neg64", argLength: 1},
   244		{name: "Neg32F", argLength: 1},
   245		{name: "Neg64F", argLength: 1},
   246	
   247		{name: "Com8", argLength: 1}, // ^arg0
   248		{name: "Com16", argLength: 1},
   249		{name: "Com32", argLength: 1},
   250		{name: "Com64", argLength: 1},
   251	
   252		{name: "Ctz8", argLength: 1},         // Count trailing (low order) zeroes (returns 0-8)
   253		{name: "Ctz16", argLength: 1},        // Count trailing (low order) zeroes (returns 0-16)
   254		{name: "Ctz32", argLength: 1},        // Count trailing (low order) zeroes (returns 0-32)
   255		{name: "Ctz64", argLength: 1},        // Count trailing (low order) zeroes (returns 0-64)
   256		{name: "Ctz8NonZero", argLength: 1},  // same as above, but arg[0] known to be non-zero, returns 0-7
   257		{name: "Ctz16NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-15
   258		{name: "Ctz32NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-31
   259		{name: "Ctz64NonZero", argLength: 1}, // same as above, but arg[0] known to be non-zero, returns 0-63
   260		{name: "BitLen8", argLength: 1},      // Number of bits in arg[0] (returns 0-8)
   261		{name: "BitLen16", argLength: 1},     // Number of bits in arg[0] (returns 0-16)
   262		{name: "BitLen32", argLength: 1},     // Number of bits in arg[0] (returns 0-32)
   263		{name: "BitLen64", argLength: 1},     // Number of bits in arg[0] (returns 0-64)
   264	
   265		{name: "Bswap32", argLength: 1}, // Swap bytes
   266		{name: "Bswap64", argLength: 1}, // Swap bytes
   267	
   268		{name: "BitRev8", argLength: 1},  // Reverse the bits in arg[0]
   269		{name: "BitRev16", argLength: 1}, // Reverse the bits in arg[0]
   270		{name: "BitRev32", argLength: 1}, // Reverse the bits in arg[0]
   271		{name: "BitRev64", argLength: 1}, // Reverse the bits in arg[0]
   272	
   273		{name: "PopCount8", argLength: 1},    // Count bits in arg[0]
   274		{name: "PopCount16", argLength: 1},   // Count bits in arg[0]
   275		{name: "PopCount32", argLength: 1},   // Count bits in arg[0]
   276		{name: "PopCount64", argLength: 1},   // Count bits in arg[0]
   277		{name: "RotateLeft8", argLength: 2},  // Rotate bits in arg[0] left by arg[1]
   278		{name: "RotateLeft16", argLength: 2}, // Rotate bits in arg[0] left by arg[1]
   279		{name: "RotateLeft32", argLength: 2}, // Rotate bits in arg[0] left by arg[1]
   280		{name: "RotateLeft64", argLength: 2}, // Rotate bits in arg[0] left by arg[1]
   281	
   282		// Square root, float64 only.
   283		// Special cases:
   284		//   +∞  → +∞
   285		//   ±0  → ±0 (sign preserved)
   286		//   x<0 → NaN
   287		//   NaN → NaN
   288		{name: "Sqrt", argLength: 1}, // √arg0
   289	
   290		// Round to integer, float64 only.
   291		// Special cases:
   292		//   ±∞  → ±∞ (sign preserved)
   293		//   ±0  → ±0 (sign preserved)
   294		//   NaN → NaN
   295		{name: "Floor", argLength: 1},       // round arg0 toward -∞
   296		{name: "Ceil", argLength: 1},        // round arg0 toward +∞
   297		{name: "Trunc", argLength: 1},       // round arg0 toward 0
   298		{name: "Round", argLength: 1},       // round arg0 to nearest, ties away from 0
   299		{name: "RoundToEven", argLength: 1}, // round arg0 to nearest, ties to even
   300	
   301		// Modify the sign bit
   302		{name: "Abs", argLength: 1},      // absolute value arg0
   303		{name: "Copysign", argLength: 2}, // copy sign from arg0 to arg1
   304	
   305		// Data movement, max argument length for Phi is indefinite so just pick
   306		// a really large number
   307		{name: "Phi", argLength: -1, zeroWidth: true}, // select an argument based on which predecessor block we came from
   308		{name: "Copy", argLength: 1},                  // output = arg0
   309		// Convert converts between pointers and integers.
   310		// We have a special op for this so as to not confuse GC
   311		// (particularly stack maps).  It takes a memory arg so it
   312		// gets correctly ordered with respect to GC safepoints.
   313		// It gets compiled to nothing, so its result must in the same
   314		// register as its argument. regalloc knows it can use any
   315		// allocatable integer register for OpConvert.
   316		// arg0=ptr/int arg1=mem, output=int/ptr
   317		{name: "Convert", argLength: 2, zeroWidth: true, resultInArg0: true},
   318	
   319		// constants. Constant values are stored in the aux or
   320		// auxint fields.
   321		{name: "ConstBool", aux: "Bool"},     // auxint is 0 for false and 1 for true
   322		{name: "ConstString", aux: "String"}, // value is aux.(string)
   323		{name: "ConstNil", typ: "BytePtr"},   // nil pointer
   324		{name: "Const8", aux: "Int8"},        // auxint is sign-extended 8 bits
   325		{name: "Const16", aux: "Int16"},      // auxint is sign-extended 16 bits
   326		{name: "Const32", aux: "Int32"},      // auxint is sign-extended 32 bits
   327		// Note: ConstX are sign-extended even when the type of the value is unsigned.
   328		// For instance, uint8(0xaa) is stored as auxint=0xffffffffffffffaa.
   329		{name: "Const64", aux: "Int64"},    // value is auxint
   330		{name: "Const32F", aux: "Float32"}, // value is math.Float64frombits(uint64(auxint)) and is exactly prepresentable as float 32
   331		{name: "Const64F", aux: "Float64"}, // value is math.Float64frombits(uint64(auxint))
   332		{name: "ConstInterface"},           // nil interface
   333		{name: "ConstSlice"},               // nil slice
   334	
   335		// Constant-like things
   336		{name: "InitMem", zeroWidth: true},                               // memory input to the function.
   337		{name: "Arg", aux: "SymOff", symEffect: "Read", zeroWidth: true}, // argument to the function.  aux=GCNode of arg, off = offset in that arg.
   338	
   339		// The address of a variable.  arg0 is the base pointer.
   340		// If the variable is a global, the base pointer will be SB and
   341		// the Aux field will be a *obj.LSym.
   342		// If the variable is a local, the base pointer will be SP and
   343		// the Aux field will be a *gc.Node.
   344		{name: "Addr", argLength: 1, aux: "Sym", symEffect: "Addr"},      // Address of a variable.  Arg0=SB.  Aux identifies the variable.
   345		{name: "LocalAddr", argLength: 2, aux: "Sym", symEffect: "Addr"}, // Address of a variable.  Arg0=SP. Arg1=mem. Aux identifies the variable.
   346	
   347		{name: "SP", zeroWidth: true},                 // stack pointer
   348		{name: "SB", typ: "Uintptr", zeroWidth: true}, // static base pointer (a.k.a. globals pointer)
   349		{name: "Invalid"},                             // unused value
   350	
   351		// Memory operations
   352		{name: "Load", argLength: 2},                          // Load from arg0.  arg1=memory
   353		{name: "Store", argLength: 3, typ: "Mem", aux: "Typ"}, // Store arg1 to arg0.  arg2=memory, aux=type.  Returns memory.
   354		// The source and destination of Move may overlap in some cases. See e.g.
   355		// memmove inlining in generic.rules. When inlineablememmovesize (in ../rewrite.go)
   356		// returns true, we must do all loads before all stores, when lowering Move.
   357		{name: "Move", argLength: 3, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size, aux=type.  Returns memory.
   358		{name: "Zero", argLength: 2, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=mem, auxint=size, aux=type. Returns memory.
   359	
   360		// Memory operations with write barriers.
   361		// Expand to runtime calls. Write barrier will be removed if write on stack.
   362		{name: "StoreWB", argLength: 3, typ: "Mem", aux: "Typ"},    // Store arg1 to arg0. arg2=memory, aux=type.  Returns memory.
   363		{name: "MoveWB", argLength: 3, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size, aux=type.  Returns memory.
   364		{name: "ZeroWB", argLength: 2, typ: "Mem", aux: "TypSize"}, // arg0=destptr, arg1=mem, auxint=size, aux=type. Returns memory.
   365	
   366		// WB invokes runtime.gcWriteBarrier. This is not a normal
   367		// call: it takes arguments in registers, doesn't clobber
   368		// general-purpose registers (the exact clobber set is
   369		// arch-dependent), and is not a safe-point.
   370		{name: "WB", argLength: 3, typ: "Mem", aux: "Sym", symEffect: "None"}, // arg0=destptr, arg1=srcptr, arg2=mem, aux=runtime.gcWriteBarrier
   371	
   372		// PanicBounds and PanicExtend generate a runtime panic.
   373		// Their arguments provide index values to use in panic messages.
   374		// Both PanicBounds and PanicExtend have an AuxInt value from the BoundsKind type (in ../op.go).
   375		// PanicBounds' index is int sized.
   376		// PanicExtend's index is int64 sized. (PanicExtend is only used on 32-bit archs.)
   377		{name: "PanicBounds", argLength: 3, aux: "Int64", typ: "Mem"}, // arg0=idx, arg1=len, arg2=mem, returns memory.
   378		{name: "PanicExtend", argLength: 4, aux: "Int64", typ: "Mem"}, // arg0=idxHi, arg1=idxLo, arg2=len, arg3=mem, returns memory.
   379	
   380		// Function calls. Arguments to the call have already been written to the stack.
   381		// Return values appear on the stack. The method receiver, if any, is treated
   382		// as a phantom first argument.
   383		{name: "ClosureCall", argLength: 3, aux: "Int64", call: true},                    // arg0=code pointer, arg1=context ptr, arg2=memory.  auxint=arg size.  Returns memory.
   384		{name: "StaticCall", argLength: 1, aux: "SymOff", call: true, symEffect: "None"}, // call function aux.(*obj.LSym), arg0=memory.  auxint=arg size.  Returns memory.
   385		{name: "InterCall", argLength: 2, aux: "Int64", call: true},                      // interface call.  arg0=code pointer, arg1=memory, auxint=arg size.  Returns memory.
   386	
   387		// Conversions: signed extensions, zero (unsigned) extensions, truncations
   388		{name: "SignExt8to16", argLength: 1, typ: "Int16"},
   389		{name: "SignExt8to32", argLength: 1, typ: "Int32"},
   390		{name: "SignExt8to64", argLength: 1, typ: "Int64"},
   391		{name: "SignExt16to32", argLength: 1, typ: "Int32"},
   392		{name: "SignExt16to64", argLength: 1, typ: "Int64"},
   393		{name: "SignExt32to64", argLength: 1, typ: "Int64"},
   394		{name: "ZeroExt8to16", argLength: 1, typ: "UInt16"},
   395		{name: "ZeroExt8to32", argLength: 1, typ: "UInt32"},
   396		{name: "ZeroExt8to64", argLength: 1, typ: "UInt64"},
   397		{name: "ZeroExt16to32", argLength: 1, typ: "UInt32"},
   398		{name: "ZeroExt16to64", argLength: 1, typ: "UInt64"},
   399		{name: "ZeroExt32to64", argLength: 1, typ: "UInt64"},
   400		{name: "Trunc16to8", argLength: 1},
   401		{name: "Trunc32to8", argLength: 1},
   402		{name: "Trunc32to16", argLength: 1},
   403		{name: "Trunc64to8", argLength: 1},
   404		{name: "Trunc64to16", argLength: 1},
   405		{name: "Trunc64to32", argLength: 1},
   406	
   407		{name: "Cvt32to32F", argLength: 1},
   408		{name: "Cvt32to64F", argLength: 1},
   409		{name: "Cvt64to32F", argLength: 1},
   410		{name: "Cvt64to64F", argLength: 1},
   411		{name: "Cvt32Fto32", argLength: 1},
   412		{name: "Cvt32Fto64", argLength: 1},
   413		{name: "Cvt64Fto32", argLength: 1},
   414		{name: "Cvt64Fto64", argLength: 1},
   415		{name: "Cvt32Fto64F", argLength: 1},
   416		{name: "Cvt64Fto32F", argLength: 1},
   417	
   418		// Force rounding to precision of type.
   419		{name: "Round32F", argLength: 1},
   420		{name: "Round64F", argLength: 1},
   421	
   422		// Automatically inserted safety checks
   423		{name: "IsNonNil", argLength: 1, typ: "Bool"},        // arg0 != nil
   424		{name: "IsInBounds", argLength: 2, typ: "Bool"},      // 0 <= arg0 < arg1. arg1 is guaranteed >= 0.
   425		{name: "IsSliceInBounds", argLength: 2, typ: "Bool"}, // 0 <= arg0 <= arg1. arg1 is guaranteed >= 0.
   426		{name: "NilCheck", argLength: 2, typ: "Void"},        // arg0=ptr, arg1=mem. Panics if arg0 is nil. Returns void.
   427	
   428		// Pseudo-ops
   429		{name: "GetG", argLength: 1, zeroWidth: true}, // runtime.getg() (read g pointer). arg0=mem
   430		{name: "GetClosurePtr"},                       // get closure pointer from dedicated register
   431		{name: "GetCallerPC"},                         // for getcallerpc intrinsic
   432		{name: "GetCallerSP"},                         // for getcallersp intrinsic
   433	
   434		// Indexing operations
   435		{name: "PtrIndex", argLength: 2},             // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type
   436		{name: "OffPtr", argLength: 1, aux: "Int64"}, // arg0 + auxint (arg0 and result are pointers)
   437	
   438		// Slices
   439		{name: "SliceMake", argLength: 3},                // arg0=ptr, arg1=len, arg2=cap
   440		{name: "SlicePtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0)
   441		{name: "SliceLen", argLength: 1},                 // len(arg0)
   442		{name: "SliceCap", argLength: 1},                 // cap(arg0)
   443	
   444		// Complex (part/whole)
   445		{name: "ComplexMake", argLength: 2}, // arg0=real, arg1=imag
   446		{name: "ComplexReal", argLength: 1}, // real(arg0)
   447		{name: "ComplexImag", argLength: 1}, // imag(arg0)
   448	
   449		// Strings
   450		{name: "StringMake", argLength: 2},                // arg0=ptr, arg1=len
   451		{name: "StringPtr", argLength: 1, typ: "BytePtr"}, // ptr(arg0)
   452		{name: "StringLen", argLength: 1, typ: "Int"},     // len(arg0)
   453	
   454		// Interfaces
   455		{name: "IMake", argLength: 2},                // arg0=itab, arg1=data
   456		{name: "ITab", argLength: 1, typ: "Uintptr"}, // arg0=interface, returns itable field
   457		{name: "IData", argLength: 1},                // arg0=interface, returns data field
   458	
   459		// Structs
   460		{name: "StructMake0"},                              // Returns struct with 0 fields.
   461		{name: "StructMake1", argLength: 1},                // arg0=field0.  Returns struct.
   462		{name: "StructMake2", argLength: 2},                // arg0,arg1=field0,field1.  Returns struct.
   463		{name: "StructMake3", argLength: 3},                // arg0..2=field0..2.  Returns struct.
   464		{name: "StructMake4", argLength: 4},                // arg0..3=field0..3.  Returns struct.
   465		{name: "StructSelect", argLength: 1, aux: "Int64"}, // arg0=struct, auxint=field index.  Returns the auxint'th field.
   466	
   467		// Arrays
   468		{name: "ArrayMake0"},                              // Returns array with 0 elements
   469		{name: "ArrayMake1", argLength: 1},                // Returns array with 1 element
   470		{name: "ArraySelect", argLength: 1, aux: "Int64"}, // arg0=array, auxint=index. Returns a[i].
   471	
   472		// Spill&restore ops for the register allocator. These are
   473		// semantically identical to OpCopy; they do not take/return
   474		// stores like regular memory ops do. We can get away without memory
   475		// args because we know there is no aliasing of spill slots on the stack.
   476		{name: "StoreReg", argLength: 1},
   477		{name: "LoadReg", argLength: 1},
   478	
   479		// Used during ssa construction. Like Copy, but the arg has not been specified yet.
   480		{name: "FwdRef", aux: "Sym", symEffect: "None"},
   481	
   482		// Unknown value. Used for Values whose values don't matter because they are dead code.
   483		{name: "Unknown"},
   484	
   485		{name: "VarDef", argLength: 1, aux: "Sym", typ: "Mem", symEffect: "None", zeroWidth: true}, // aux is a *gc.Node of a variable that is about to be initialized.  arg0=mem, returns mem
   486		{name: "VarKill", argLength: 1, aux: "Sym", symEffect: "None"},                             // aux is a *gc.Node of a variable that is known to be dead.  arg0=mem, returns mem
   487		// TODO: what's the difference betweeen VarLive and KeepAlive?
   488		{name: "VarLive", argLength: 1, aux: "Sym", symEffect: "Read", zeroWidth: true}, // aux is a *gc.Node of a variable that must be kept live.  arg0=mem, returns mem
   489		{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
   490	
   491		// InlMark marks the start of an inlined function body. Its AuxInt field
   492		// distinguishes which entry in the local inline tree it is marking.
   493		{name: "InlMark", argLength: 1, aux: "Int32", typ: "Void"}, // arg[0]=mem, returns void.
   494	
   495		// Ops for breaking 64-bit operations on 32-bit architectures
   496		{name: "Int64Make", argLength: 2, typ: "UInt64"}, // arg0=hi, arg1=lo
   497		{name: "Int64Hi", argLength: 1, typ: "UInt32"},   // high 32-bit of arg0
   498		{name: "Int64Lo", argLength: 1, typ: "UInt32"},   // low 32-bit of arg0
   499	
   500		{name: "Add32carry", argLength: 2, commutative: true, typ: "(UInt32,Flags)"}, // arg0 + arg1, returns (value, carry)
   501		{name: "Add32withcarry", argLength: 3, commutative: true},                    // arg0 + arg1 + arg2, arg2=carry (0 or 1)
   502	
   503		{name: "Sub32carry", argLength: 2, typ: "(UInt32,Flags)"}, // arg0 - arg1, returns (value, carry)
   504		{name: "Sub32withcarry", argLength: 3},                    // arg0 - arg1 - arg2, arg2=carry (0 or 1)
   505	
   506		{name: "Add64carry", argLength: 3, commutative: true, typ: "(UInt64,UInt64)"}, // arg0 + arg1 + arg2, arg2 must be 0 or 1. returns (value, value>>64)
   507		{name: "Sub64borrow", argLength: 3, typ: "(UInt64,UInt64)"},                   // arg0 - (arg1 + arg2), arg2 must be 0 or 1. returns (value, value>>64&1)
   508	
   509		{name: "Signmask", argLength: 1, typ: "Int32"},  // 0 if arg0 >= 0, -1 if arg0 < 0
   510		{name: "Zeromask", argLength: 1, typ: "UInt32"}, // 0 if arg0 == 0, 0xffffffff if arg0 != 0
   511		{name: "Slicemask", argLength: 1},               // 0 if arg0 == 0, -1 if arg0 > 0, undef if arg0<0. Type is native int size.
   512	
   513		{name: "Cvt32Uto32F", argLength: 1}, // uint32 -> float32, only used on 32-bit arch
   514		{name: "Cvt32Uto64F", argLength: 1}, // uint32 -> float64, only used on 32-bit arch
   515		{name: "Cvt32Fto32U", argLength: 1}, // float32 -> uint32, only used on 32-bit arch
   516		{name: "Cvt64Fto32U", argLength: 1}, // float64 -> uint32, only used on 32-bit arch
   517		{name: "Cvt64Uto32F", argLength: 1}, // uint64 -> float32, only used on archs that has the instruction
   518		{name: "Cvt64Uto64F", argLength: 1}, // uint64 -> float64, only used on archs that has the instruction
   519		{name: "Cvt32Fto64U", argLength: 1}, // float32 -> uint64, only used on archs that has the instruction
   520		{name: "Cvt64Fto64U", argLength: 1}, // float64 -> uint64, only used on archs that has the instruction
   521	
   522		// pseudo-ops for breaking Tuple
   523		{name: "Select0", argLength: 1, zeroWidth: true}, // the first component of a tuple
   524		{name: "Select1", argLength: 1, zeroWidth: true}, // the second component of a tuple
   525	
   526		// Atomic operations used for semantically inlining runtime/internal/atomic.
   527		// Atomic loads return a new memory so that the loads are properly ordered
   528		// with respect to other loads and stores.
   529		// TODO: use for sync/atomic at some point.
   530		{name: "AtomicLoad8", argLength: 2, typ: "(UInt8,Mem)"},                                    // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   531		{name: "AtomicLoad32", argLength: 2, typ: "(UInt32,Mem)"},                                  // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   532		{name: "AtomicLoad64", argLength: 2, typ: "(UInt64,Mem)"},                                  // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   533		{name: "AtomicLoadPtr", argLength: 2, typ: "(BytePtr,Mem)"},                                // Load from arg0.  arg1=memory.  Returns loaded value and new memory.
   534		{name: "AtomicLoadAcq32", argLength: 2, typ: "(UInt32,Mem)"},                               // Load from arg0.  arg1=memory.  Lock acquisition, returns loaded value and new memory.
   535		{name: "AtomicStore32", argLength: 3, typ: "Mem", hasSideEffects: true},                    // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   536		{name: "AtomicStore64", argLength: 3, typ: "Mem", hasSideEffects: true},                    // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   537		{name: "AtomicStorePtrNoWB", argLength: 3, typ: "Mem", hasSideEffects: true},               // Store arg1 to *arg0.  arg2=memory.  Returns memory.
   538		{name: "AtomicStoreRel32", argLength: 3, typ: "Mem", hasSideEffects: true},                 // Store arg1 to *arg0.  arg2=memory.  Lock release, returns memory.
   539		{name: "AtomicExchange32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true},        // Store arg1 to *arg0.  arg2=memory.  Returns old contents of *arg0 and new memory.
   540		{name: "AtomicExchange64", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true},        // Store arg1 to *arg0.  arg2=memory.  Returns old contents of *arg0 and new memory.
   541		{name: "AtomicAdd32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true},             // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   542		{name: "AtomicAdd64", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true},             // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   543		{name: "AtomicCompareAndSwap32", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true},    // if *arg0==arg1, then set *arg0=arg2.  Returns true if store happens and new memory.
   544		{name: "AtomicCompareAndSwap64", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true},    // if *arg0==arg1, then set *arg0=arg2.  Returns true if store happens and new memory.
   545		{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.
   546		{name: "AtomicAnd8", argLength: 3, typ: "Mem", hasSideEffects: true},                       // *arg0 &= arg1.  arg2=memory.  Returns memory.
   547		{name: "AtomicOr8", argLength: 3, typ: "Mem", hasSideEffects: true},                        // *arg0 |= arg1.  arg2=memory.  Returns memory.
   548	
   549		// Atomic operation variants
   550		// These variants have the same semantics as above atomic operations.
   551		// But they are used for generating more efficient code on certain modern machines, with run-time CPU feature detection.
   552		// Currently, they are used on ARM64 only.
   553		{name: "AtomicAdd32Variant", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   554		{name: "AtomicAdd64Variant", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Do *arg0 += arg1.  arg2=memory.  Returns sum and new memory.
   555	
   556		// Clobber experiment op
   557		{name: "Clobber", argLength: 0, typ: "Void", aux: "SymOff", symEffect: "None"}, // write an invalid pointer value to the given pointer slot of a stack variable
   558	}
   559	
   560	//     kind           control    successors       implicit exit
   561	//   ----------------------------------------------------------
   562	//     Exit        return mem                []             yes
   563	//      Ret        return mem                []             yes
   564	//   RetJmp        return mem                []             yes
   565	//    Plain               nil            [next]
   566	//       If   a boolean Value      [then, else]
   567	//     Call               mem            [next]             yes  (control opcode should be OpCall or OpStaticCall)
   568	//    Check              void            [next]             yes  (control opcode should be Op{Lowered}NilCheck)
   569	//    First               nil    [always,never]
   570	
   571	var genericBlocks = []blockData{
   572		{name: "Plain"},  // a single successor
   573		{name: "If"},     // 2 successors, if control goto Succs[0] else goto Succs[1]
   574		{name: "Defer"},  // 2 successors, Succs[0]=defer queued, Succs[1]=defer recovered. control is call op (of memory type)
   575		{name: "Ret"},    // no successors, control value is memory result
   576		{name: "RetJmp"}, // no successors, jumps to b.Aux.(*gc.Sym)
   577		{name: "Exit"},   // no successors, control value generates a panic
   578	
   579		// transient block state used for dead code removal
   580		{name: "First"}, // 2 successors, always takes the first one (second is dead)
   581	}
   582	
   583	func init() {
   584		archs = append(archs, arch{
   585			name:    "generic",
   586			ops:     genericOps,
   587			blocks:  genericBlocks,
   588			generic: true,
   589		})
   590	}
   591	

View as plain text