1 // Copyright 2018 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 "strings" 9 10 "golang.org/x/arch/x86/xeddata" 11 ) 12 13 // argument is a describes single instruction operand properties. 14 type argument struct { 15 // ytype is argument class as returned by asm6 "oclass" function. 16 ytype string 17 18 // zkind is a partial Z-case matcher. 19 // Determines which Z-case handles the encoding of instruction. 20 zkind string 21 } 22 23 // instruction is decoded XED instruction. 24 // Used to produce ytabs and optabs in later phases. 25 type instruction struct { 26 // opcode is instruction symbolic name. 27 opcode string 28 29 pset xeddata.PatternSet 30 enc *encoding 31 32 // mask is EVEX K-register argument; points to args element. 33 // Used to emit Yk0+Yknot0 table entries. 34 // Nil for VEX-encoded insts. 35 mask *argument 36 args []*argument 37 38 // zform is a pattern that determines which encoder Z-case is used. 39 // We store zform instead of zcase directly because it's further 40 // expanded during optabs generation. 41 zform string 42 } 43 44 // String returns short inst printed representation. 45 func (inst *instruction) String() string { return inst.opcode } 46 47 // YtypeListString joins each argument Y-type and returns the result. 48 func (inst *instruction) YtypeListString() string { 49 var parts []string 50 for _, arg := range inst.args { 51 parts = append(parts, arg.ytype) 52 } 53 return strings.Join(parts, " ") 54 } 55 56 // ArgIndexByZkind returns first argument matching given zkind or -1. 57 func (inst *instruction) ArgIndexByZkind(zkind string) int { 58 for i, arg := range inst.args { 59 if arg.zkind == zkind { 60 return i 61 } 62 } 63 return -1 64 } 65