github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/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/go-asm/go/cmd/compile/ir" 9 "github.com/go-asm/go/cmd/compile/objw" 10 "github.com/go-asm/go/cmd/compile/types" 11 "github.com/go-asm/go/cmd/obj" 12 "github.com/go-asm/go/cmd/obj/arm64" 13 ) 14 15 func padframe(frame int64) int64 { 16 // arm64 requires that the frame size (not counting saved FP&LR) 17 // be 16 bytes aligned. If not, pad it. 18 if frame%16 != 0 { 19 frame += 16 - (frame % 16) 20 } 21 return frame 22 } 23 24 func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog { 25 if cnt == 0 { 26 return p 27 } 28 if cnt < int64(4*types.PtrSize) { 29 for i := int64(0); i < cnt; i += int64(types.PtrSize) { 30 p = pp.Append(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGSP, 8+off+i) 31 } 32 } else if cnt <= int64(128*types.PtrSize) { 33 if cnt%(2*int64(types.PtrSize)) != 0 { 34 p = pp.Append(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGSP, 8+off) 35 off += int64(types.PtrSize) 36 cnt -= int64(types.PtrSize) 37 } 38 p = pp.Append(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REG_R20, 0) 39 p = pp.Append(p, arm64.AADD, obj.TYPE_CONST, 0, 8+off, obj.TYPE_REG, arm64.REG_R20, 0) 40 p.Reg = arm64.REG_R20 41 p = pp.Append(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0) 42 p.To.Name = obj.NAME_EXTERN 43 p.To.Sym = ir.Syms.Duffzero 44 p.To.Offset = 4 * (64 - cnt/(2*int64(types.PtrSize))) 45 } else { 46 // Not using REGTMP, so this is async preemptible (async preemption clobbers REGTMP). 47 // We are at the function entry, where no register is live, so it is okay to clobber 48 // other registers 49 const rtmp = arm64.REG_R20 50 p = pp.Append(p, arm64.AMOVD, obj.TYPE_CONST, 0, 8+off-8, obj.TYPE_REG, rtmp, 0) 51 p = pp.Append(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REGRT1, 0) 52 p = pp.Append(p, arm64.AADD, obj.TYPE_REG, rtmp, 0, obj.TYPE_REG, arm64.REGRT1, 0) 53 p.Reg = arm64.REGRT1 54 p = pp.Append(p, arm64.AMOVD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, rtmp, 0) 55 p = pp.Append(p, arm64.AADD, obj.TYPE_REG, rtmp, 0, obj.TYPE_REG, arm64.REGRT2, 0) 56 p.Reg = arm64.REGRT1 57 p = pp.Append(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGRT1, int64(types.PtrSize)) 58 p.Scond = arm64.C_XPRE 59 p1 := p 60 p = pp.Append(p, arm64.ACMP, obj.TYPE_REG, arm64.REGRT1, 0, obj.TYPE_NONE, 0, 0) 61 p.Reg = arm64.REGRT2 62 p = pp.Append(p, arm64.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0) 63 p.To.SetTarget(p1) 64 } 65 66 return p 67 } 68 69 func ginsnop(pp *objw.Progs) *obj.Prog { 70 p := pp.Prog(arm64.AHINT) 71 p.From.Type = obj.TYPE_CONST 72 return p 73 }