github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/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 "github.com/gagliardetto/golang-go/cmd/compile/internal/gc" 9 "github.com/gagliardetto/golang-go/cmd/internal/obj" 10 "github.com/gagliardetto/golang-go/cmd/internal/obj/arm64" 11 "github.com/gagliardetto/golang-go/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 FP&LR) 18 // be 16 bytes aligned. If not, pad it. 19 if frame%16 != 0 { 20 frame += 16 - (frame % 16) 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 if cnt%(2*int64(gc.Widthptr)) != 0 { 35 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGSP, 8+off) 36 off += int64(gc.Widthptr) 37 cnt -= int64(gc.Widthptr) 38 } 39 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REG_R20, 0) 40 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_CONST, 0, 8+off, obj.TYPE_REG, arm64.REG_R20, 0) 41 p.Reg = arm64.REG_R20 42 p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0) 43 p.To.Name = obj.NAME_EXTERN 44 p.To.Sym = gc.Duffzero 45 p.To.Offset = 4 * (64 - cnt/(2*int64(gc.Widthptr))) 46 } else { 47 // Not using REGTMP, so this is async preemptible (async preemption clobbers REGTMP). 48 // We are at the function entry, where no register is live, so it is okay to clobber 49 // other registers 50 const rtmp = arm64.REG_R20 51 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, 8+off-8, obj.TYPE_REG, rtmp, 0) 52 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REGRT1, 0) 53 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, rtmp, 0, obj.TYPE_REG, arm64.REGRT1, 0) 54 p.Reg = arm64.REGRT1 55 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, rtmp, 0) 56 p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, rtmp, 0, obj.TYPE_REG, arm64.REGRT2, 0) 57 p.Reg = arm64.REGRT1 58 p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGRT1, int64(gc.Widthptr)) 59 p.Scond = arm64.C_XPRE 60 p1 := p 61 p = pp.Appendpp(p, arm64.ACMP, obj.TYPE_REG, arm64.REGRT1, 0, obj.TYPE_NONE, 0, 0) 62 p.Reg = arm64.REGRT2 63 p = pp.Appendpp(p, arm64.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0) 64 gc.Patch(p, p1) 65 } 66 67 return p 68 } 69 70 func ginsnop(pp *gc.Progs) *obj.Prog { 71 p := pp.Prog(arm64.AHINT) 72 p.From.Type = obj.TYPE_CONST 73 return p 74 }