github.com/slayercat/go@v0.0.0-20170428012452-c51559813f61/src/cmd/compile/internal/arm64/ggen.go (about) 1 // Copyright 2009 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 "cmd/internal/objabi" 12 ) 13 14 var darwin = objabi.GOOS == "darwin" 15 16 func padframe(frame int64) int64 { 17 // arm64 requires that the frame size (not counting saved LR) 18 // be empty or be 8 mod 16. If not, pad it. 19 if frame != 0 && frame%16 != 8 { 20 frame += 8 21 } 22 return frame 23 } 24 25 func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog { 26 if cnt == 0 { 27 return p 28 } 29 if cnt < int64(4*gc.Widthptr) { 30 for i := int64(0); i < cnt; i += int64(gc.Widthptr) { 31 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGSP, 8+off+i) 32 } 33 } else if cnt <= int64(128*gc.Widthptr) && !darwin { // darwin ld64 cannot handle BR26 reloc with non-zero addend 34 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REGRT1, 0) 35 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_CONST, 0, 8+off-8, obj.TYPE_REG, arm64.REGRT1, 0) 36 p.Reg = arm64.REGRT1 37 p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0) 38 p.To.Name = obj.NAME_EXTERN 39 p.To.Sym = gc.Duffzero 40 p.To.Offset = 4 * (128 - cnt/int64(gc.Widthptr)) 41 } else { 42 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, 8+off-8, obj.TYPE_REG, arm64.REGTMP, 0) 43 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REGRT1, 0) 44 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, arm64.REGTMP, 0, obj.TYPE_REG, arm64.REGRT1, 0) 45 p.Reg = arm64.REGRT1 46 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, arm64.REGTMP, 0) 47 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, arm64.REGTMP, 0, obj.TYPE_REG, arm64.REGRT2, 0) 48 p.Reg = arm64.REGRT1 49 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGRT1, int64(gc.Widthptr)) 50 p.Scond = arm64.C_XPRE 51 p1 := p 52 p = pp.Appendpp(p, arm64.ACMP, obj.TYPE_REG, arm64.REGRT1, 0, obj.TYPE_NONE, 0, 0) 53 p.Reg = arm64.REGRT2 54 p = pp.Appendpp(p, arm64.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0) 55 gc.Patch(p, p1) 56 } 57 58 return p 59 } 60 61 func zeroAuto(pp *gc.Progs, n *gc.Node) { 62 // Note: this code must not clobber any registers. 63 sym := n.Sym.Linksym() 64 size := n.Type.Size() 65 for i := int64(0); i < size; i += 8 { 66 p := pp.Prog(arm64.AMOVD) 67 p.From.Type = obj.TYPE_REG 68 p.From.Reg = arm64.REGZERO 69 p.To.Type = obj.TYPE_MEM 70 p.To.Name = obj.NAME_AUTO 71 p.To.Reg = arm64.REGSP 72 p.To.Offset = n.Xoffset + i 73 p.To.Sym = sym 74 } 75 } 76 77 func ginsnop(pp *gc.Progs) { 78 p := pp.Prog(arm64.AHINT) 79 p.From.Type = obj.TYPE_CONST 80 }