github.com/aloncn/graphics-go@v0.0.1/src/cmd/compile/internal/arm64/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 arm64 6 7 import ( 8 "cmd/compile/internal/gc" 9 "cmd/internal/obj" 10 "cmd/internal/obj/arm64" 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 = [arm64.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 arm64.AHINT: {Flags: gc.OK}, 43 44 // Integer 45 arm64.AADD: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 46 arm64.ASUB: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 47 arm64.ANEG: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 48 arm64.AAND: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 49 arm64.AORR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 50 arm64.AEOR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 51 arm64.AMUL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 52 arm64.ASMULL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 53 arm64.AUMULL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 54 arm64.ASMULH: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, 55 arm64.AUMULH: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, 56 arm64.ASDIV: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 57 arm64.AUDIV: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 58 arm64.ALSL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 59 arm64.ALSR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 60 arm64.AASR: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite}, 61 arm64.ACMP: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead}, 62 63 // Floating point. 64 arm64.AFADDD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 65 arm64.AFADDS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 66 arm64.AFSUBD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 67 arm64.AFSUBS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 68 arm64.AFNEGD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, 69 arm64.AFNEGS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite}, 70 arm64.AFSQRTD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, 71 arm64.AFMULD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 72 arm64.AFMULS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 73 arm64.AFDIVD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, 74 arm64.AFDIVS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, 75 arm64.AFCMPD: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead}, 76 arm64.AFCMPS: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead}, 77 78 // float -> integer 79 arm64.AFCVTZSD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 80 arm64.AFCVTZSS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 81 arm64.AFCVTZSDW: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 82 arm64.AFCVTZSSW: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 83 arm64.AFCVTZUD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 84 arm64.AFCVTZUS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 85 arm64.AFCVTZUDW: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 86 arm64.AFCVTZUSW: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, 87 88 // float -> float 89 arm64.AFCVTSD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 90 arm64.AFCVTDS: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, 91 92 // integer -> float 93 arm64.ASCVTFD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 94 arm64.ASCVTFS: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 95 arm64.ASCVTFWD: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 96 arm64.ASCVTFWS: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 97 arm64.AUCVTFD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 98 arm64.AUCVTFS: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv}, 99 arm64.AUCVTFWD: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 100 arm64.AUCVTFWS: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, 101 102 // Moves 103 arm64.AMOVB: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 104 arm64.AMOVBU: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 105 arm64.AMOVH: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 106 arm64.AMOVHU: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 107 arm64.AMOVW: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 108 arm64.AMOVWU: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 109 arm64.AMOVD: {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Move}, 110 arm64.AFMOVS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, 111 arm64.AFMOVD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Move}, 112 113 // Jumps 114 arm64.AB: {Flags: gc.Jump | gc.Break}, 115 arm64.ABL: {Flags: gc.Call}, 116 arm64.ABEQ: {Flags: gc.Cjmp}, 117 arm64.ABNE: {Flags: gc.Cjmp}, 118 arm64.ABGE: {Flags: gc.Cjmp}, 119 arm64.ABLT: {Flags: gc.Cjmp}, 120 arm64.ABGT: {Flags: gc.Cjmp}, 121 arm64.ABLE: {Flags: gc.Cjmp}, 122 arm64.ABLO: {Flags: gc.Cjmp}, 123 arm64.ABLS: {Flags: gc.Cjmp}, 124 arm64.ABHI: {Flags: gc.Cjmp}, 125 arm64.ABHS: {Flags: gc.Cjmp}, 126 arm64.ACBZ: {Flags: gc.Cjmp}, 127 arm64.ACBNZ: {Flags: gc.Cjmp}, 128 obj.ARET: {Flags: gc.Break}, 129 obj.ADUFFZERO: {Flags: gc.Call}, 130 obj.ADUFFCOPY: {Flags: gc.Call}, 131 } 132 133 func proginfo(p *obj.Prog) { 134 info := &p.Info 135 *info = progtable[p.As] 136 if info.Flags == 0 { 137 gc.Fatalf("proginfo: unknown instruction %v", p) 138 } 139 140 if (info.Flags&gc.RegRead != 0) && p.Reg == 0 { 141 info.Flags &^= gc.RegRead 142 info.Flags |= gc.RightRead /*CanRegRead |*/ 143 } 144 145 if (p.From.Type == obj.TYPE_MEM || p.From.Type == obj.TYPE_ADDR) && p.From.Reg != 0 { 146 info.Regindex |= RtoB(int(p.From.Reg)) 147 if p.Scond != 0 { 148 info.Regset |= RtoB(int(p.From.Reg)) 149 } 150 } 151 152 if (p.To.Type == obj.TYPE_MEM || p.To.Type == obj.TYPE_ADDR) && p.To.Reg != 0 { 153 info.Regindex |= RtoB(int(p.To.Reg)) 154 if p.Scond != 0 { 155 info.Regset |= RtoB(int(p.To.Reg)) 156 } 157 } 158 159 if p.From.Type == obj.TYPE_ADDR && p.From.Sym != nil && (info.Flags&gc.LeftRead != 0) { 160 info.Flags &^= gc.LeftRead 161 info.Flags |= gc.LeftAddr 162 } 163 164 if p.As == obj.ADUFFZERO { 165 info.Reguse |= RtoB(arm64.REGRT1) 166 info.Regset |= RtoB(arm64.REGRT1) 167 } 168 169 if p.As == obj.ADUFFCOPY { 170 // TODO(austin) Revisit when duffcopy is implemented 171 info.Reguse |= RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) | RtoB(arm64.REG_R5) 172 173 info.Regset |= RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) 174 } 175 }