github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/cmd/compile/internal/arm/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 arm 6 7 import ( 8 "cmd/compile/internal/gc" 9 "cmd/internal/obj" 10 "cmd/internal/obj/arm" 11 ) 12 13 func defframe(ptxt *obj.Prog) { 14 // fill in argument size, stack size 15 ptxt.To.Type = obj.TYPE_TEXTSIZE 16 17 ptxt.To.Val = int32(gc.Rnd(gc.Curfn.Type.ArgWidth(), int64(gc.Widthptr))) 18 frame := uint32(gc.Rnd(gc.Stksize+gc.Maxarg, int64(gc.Widthreg))) 19 ptxt.To.Offset = int64(frame) 20 21 // insert code to contain ambiguously live variables 22 // so that garbage collector only sees initialized values 23 // when it looks for pointers. 24 p := ptxt 25 26 hi := int64(0) 27 lo := hi 28 r0 := uint32(0) 29 for _, n := range gc.Curfn.Func.Dcl { 30 if !n.Name.Needzero { 31 continue 32 } 33 if n.Class != gc.PAUTO { 34 gc.Fatalf("needzero class %d", n.Class) 35 } 36 if n.Type.Width%int64(gc.Widthptr) != 0 || n.Xoffset%int64(gc.Widthptr) != 0 || n.Type.Width == 0 { 37 gc.Fatalf("var %L has size %d offset %d", n, int(n.Type.Width), int(n.Xoffset)) 38 } 39 if lo != hi && n.Xoffset+n.Type.Width >= lo-int64(2*gc.Widthptr) { 40 // merge with range we already have 41 lo = gc.Rnd(n.Xoffset, int64(gc.Widthptr)) 42 43 continue 44 } 45 46 // zero old range 47 p = zerorange(p, int64(frame), lo, hi, &r0) 48 49 // set new range 50 hi = n.Xoffset + n.Type.Width 51 52 lo = n.Xoffset 53 } 54 55 // zero final range 56 zerorange(p, int64(frame), lo, hi, &r0) 57 } 58 59 func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, r0 *uint32) *obj.Prog { 60 cnt := hi - lo 61 if cnt == 0 { 62 return p 63 } 64 if *r0 == 0 { 65 p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, arm.REG_R0, 0) 66 *r0 = 1 67 } 68 69 if cnt < int64(4*gc.Widthptr) { 70 for i := int64(0); i < cnt; i += int64(gc.Widthptr) { 71 p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_REG, arm.REG_R0, 0, obj.TYPE_MEM, arm.REGSP, 4+frame+lo+i) 72 } 73 } else if !gc.Nacl && (cnt <= int64(128*gc.Widthptr)) { 74 p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, 4+frame+lo, obj.TYPE_REG, arm.REG_R1, 0) 75 p.Reg = arm.REGSP 76 p = gc.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0) 77 p.To.Name = obj.NAME_EXTERN 78 p.To.Sym = gc.Duffzero 79 p.To.Offset = 4 * (128 - cnt/int64(gc.Widthptr)) 80 } else { 81 p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, 4+frame+lo, obj.TYPE_REG, arm.REG_R1, 0) 82 p.Reg = arm.REGSP 83 p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, arm.REG_R2, 0) 84 p.Reg = arm.REG_R1 85 p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_REG, arm.REG_R0, 0, obj.TYPE_MEM, arm.REG_R1, 4) 86 p1 := p 87 p.Scond |= arm.C_PBIT 88 p = gc.Appendpp(p, arm.ACMP, obj.TYPE_REG, arm.REG_R1, 0, obj.TYPE_NONE, 0, 0) 89 p.Reg = arm.REG_R2 90 p = gc.Appendpp(p, arm.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0) 91 gc.Patch(p, p1) 92 } 93 94 return p 95 } 96 97 func ginsnop() { 98 p := gc.Prog(arm.AAND) 99 p.From.Type = obj.TYPE_REG 100 p.From.Reg = arm.REG_R0 101 p.To.Type = obj.TYPE_REG 102 p.To.Reg = arm.REG_R0 103 p.Scond = arm.C_SCOND_EQ 104 }