github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/cmd/compile/internal/sparc64/prog.go (about) 1 // Copyright 2014 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 sparc64 6 7 import ( 8 "cmd/compile/internal/gc" 9 "cmd/internal/obj" 10 "cmd/internal/obj/sparc64" 11 ) 12 13 const ( 14 LeftRdwr uint32 = gc.LeftRead | gc.LeftWrite 15 RightRdwr uint32 = gc.RightRead | gc.RightWrite 16 ) 17 18 // This table gives the basic information about instruction 19 // generated by the compiler and processed in the optimizer. 20 // See opt.h for bit definitions. 21 // 22 // Instructions not generated need not be listed. 23 // As an exception to that rule, we typically write down all the 24 // size variants of an operation even if we just use a subset. 25 // 26 // The table is formatted for 8-space tabs. 27 var progtable = [sparc64.ALAST]obj.ProgInfo{ 28 obj.ATYPE: {Flags: gc.Pseudo | gc.Skip}, 29 obj.ATEXT: {Flags: gc.Pseudo}, 30 obj.AFUNCDATA: {Flags: gc.Pseudo}, 31 obj.APCDATA: {Flags: gc.Pseudo}, 32 obj.AUNDEF: {Flags: gc.Break}, 33 obj.AUSEFIELD: {Flags: gc.OK}, 34 obj.ACHECKNIL: {Flags: gc.LeftRead}, 35 obj.AVARDEF: {Flags: gc.Pseudo | gc.RightWrite}, 36 obj.AVARKILL: {Flags: gc.Pseudo | gc.RightWrite}, 37 obj.AVARLIVE: {Flags: gc.Pseudo | gc.LeftRead}, 38 39 // NOP is an internal no-op that also stands 40 // for USED and SET annotations, not the Power opcode. 41 obj.ANOP: {Flags: gc.LeftRead | gc.RightWrite}, 42 sparc64.ARNOP: {Flags: gc.OK}, 43 44 // Integer 45 sparc64.AADD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 46 sparc64.ASUB: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 47 sparc64.ANEG: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 48 sparc64.AAND: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 49 sparc64.AOR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 50 sparc64.AXOR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 51 sparc64.AMULD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 52 sparc64.ASDIVD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 53 sparc64.AUDIVD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 54 sparc64.ASLLD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 55 sparc64.ASRLD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 56 sparc64.ASRAD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 57 sparc64.ASLLW: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, 58 sparc64.ASRLW: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, 59 sparc64.ASRAW: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, 60 sparc64.ACMP: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead}, 61 62 // Floating point. 63 sparc64.AFADDD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 64 sparc64.AFADDS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 65 sparc64.AFSUBD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 66 sparc64.AFSUBS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 67 sparc64.AFNEGD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, 68 sparc64.AFNEGS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite}, 69 sparc64.AFSQRTD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, 70 sparc64.AFMULD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 71 sparc64.AFMULS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 72 sparc64.AFDIVD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 73 sparc64.AFDIVS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 74 sparc64.AFCMPD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead}, 75 sparc64.AFCMPS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead}, 76 77 // float -> integer 78 sparc64.AFDTOX: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 79 sparc64.AFSTOX: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 80 sparc64.AFDTOI: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 81 sparc64.AFSTOI: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 82 83 // float -> float 84 sparc64.AFSTOD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 85 sparc64.AFDTOS: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 86 87 // integer -> float 88 sparc64.AFXTOD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 89 sparc64.AFXTOS: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 90 sparc64.AFITOD: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 91 sparc64.AFITOS: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 92 93 // Moves 94 sparc64.AMOVB: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 95 sparc64.AMOVUB: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 96 sparc64.AMOVH: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 97 sparc64.AMOVUH: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 98 sparc64.AMOVW: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 99 sparc64.AMOVUW: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 100 sparc64.ASTW: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 101 sparc64.AMOVD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Move}, 102 sparc64.ASTD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Move}, 103 sparc64.AFMOVS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 104 sparc64.AFMOVD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Move}, 105 106 // Jumps 107 obj.AJMP: {Flags: gc.Jump | gc.Break}, 108 obj.ACALL: {Flags: gc.Call}, 109 sparc64.ABRNZ: {Flags: gc.Cjmp}, 110 sparc64.ABCCD: {Flags: gc.Cjmp}, 111 sparc64.ABCCW: {Flags: gc.Cjmp}, 112 sparc64.ABCSD: {Flags: gc.Cjmp}, 113 sparc64.ABCSW: {Flags: gc.Cjmp}, 114 sparc64.ABED: {Flags: gc.Cjmp}, 115 sparc64.ABEW: {Flags: gc.Cjmp}, 116 sparc64.ABGD: {Flags: gc.Cjmp}, 117 sparc64.ABGED: {Flags: gc.Cjmp}, 118 sparc64.ABGEW: {Flags: gc.Cjmp}, 119 sparc64.ABGUD: {Flags: gc.Cjmp}, 120 sparc64.ABGUW: {Flags: gc.Cjmp}, 121 sparc64.ABGW: {Flags: gc.Cjmp}, 122 sparc64.ABLD: {Flags: gc.Cjmp}, 123 sparc64.ABLED: {Flags: gc.Cjmp}, 124 sparc64.ABLEUD: {Flags: gc.Cjmp}, 125 sparc64.ABLEUW: {Flags: gc.Cjmp}, 126 sparc64.ABLEW: {Flags: gc.Cjmp}, 127 sparc64.ABLW: {Flags: gc.Cjmp}, 128 sparc64.ABNED: {Flags: gc.Cjmp}, 129 sparc64.ABNEW: {Flags: gc.Cjmp}, 130 sparc64.AFBE: {Flags: gc.Cjmp}, 131 sparc64.AFBG: {Flags: gc.Cjmp}, 132 sparc64.AFBGE: {Flags: gc.Cjmp}, 133 sparc64.AFBL: {Flags: gc.Cjmp}, 134 sparc64.AFBLE: {Flags: gc.Cjmp}, 135 sparc64.AFBNE: {Flags: gc.Cjmp}, 136 obj.ARET: {Flags: gc.Break}, 137 obj.ADUFFZERO: {Flags: gc.Call}, 138 obj.ADUFFCOPY: {Flags: gc.Call}, 139 } 140 141 func proginfo(p *obj.Prog) { 142 info := &p.Info 143 *info = progtable[p.As] 144 if info.Flags == 0 { 145 gc.Fatalf("proginfo: unknown instruction %v", p) 146 } 147 148 if (info.Flags&gc.RegRead != 0) && p.Reg == 0 { 149 info.Flags &^= gc.RegRead 150 info.Flags |= gc.RightRead /*CanRegRead |*/ 151 } 152 153 if (p.From.Type == obj.TYPE_MEM || p.From.Type == obj.TYPE_ADDR) && p.From.Reg != 0 { 154 info.Regindex |= RtoB(int(p.From.Reg)) 155 if p.Scond != 0 { 156 info.Regset |= RtoB(int(p.From.Reg)) 157 } 158 } 159 160 if (p.To.Type == obj.TYPE_MEM || p.To.Type == obj.TYPE_ADDR) && p.To.Reg != 0 { 161 info.Regindex |= RtoB(int(p.To.Reg)) 162 if p.Scond != 0 { 163 info.Regset |= RtoB(int(p.To.Reg)) 164 } 165 } 166 167 if p.From.Type == obj.TYPE_ADDR && p.From.Sym != nil && (info.Flags&gc.LeftRead != 0) { 168 info.Flags &^= gc.LeftRead 169 info.Flags |= gc.LeftAddr 170 } 171 172 if p.As == obj.ADUFFZERO { 173 info.Reguse |= RtoB(sparc64.REG_RT1) 174 info.Regset |= RtoB(sparc64.REG_RT1) 175 } 176 177 if p.As == obj.ADUFFCOPY { 178 // TODO(austin) Revisit when duffcopy is implemented 179 info.Reguse |= RtoB(sparc64.REG_RT1) | RtoB(sparc64.REG_RT2) | RtoB(sparc64.REG_G5) 180 181 info.Regset |= RtoB(sparc64.REG_RT1) | RtoB(sparc64.REG_RT2) 182 } 183 }