github.com/yukk001/go1.10.8@v0.0.0-20190813125351-6df2d3982e20/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  		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.REGRT1, 0)
    40  		p = pp.Appendpp(p, arm64.AADD, obj.TYPE_CONST, 0, 8+off, obj.TYPE_REG, arm64.REGRT1, 0)
    41  		p.Reg = arm64.REGRT1
    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  		p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, 8+off-8, obj.TYPE_REG, arm64.REGTMP, 0)
    48  		p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGSP, 0, obj.TYPE_REG, arm64.REGRT1, 0)
    49  		p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, arm64.REGTMP, 0, obj.TYPE_REG, arm64.REGRT1, 0)
    50  		p.Reg = arm64.REGRT1
    51  		p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, arm64.REGTMP, 0)
    52  		p = pp.Appendpp(p, arm64.AADD, obj.TYPE_REG, arm64.REGTMP, 0, obj.TYPE_REG, arm64.REGRT2, 0)
    53  		p.Reg = arm64.REGRT1
    54  		p = pp.Appendpp(p, arm64.AMOVD, obj.TYPE_REG, arm64.REGZERO, 0, obj.TYPE_MEM, arm64.REGRT1, int64(gc.Widthptr))
    55  		p.Scond = arm64.C_XPRE
    56  		p1 := p
    57  		p = pp.Appendpp(p, arm64.ACMP, obj.TYPE_REG, arm64.REGRT1, 0, obj.TYPE_NONE, 0, 0)
    58  		p.Reg = arm64.REGRT2
    59  		p = pp.Appendpp(p, arm64.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0)
    60  		gc.Patch(p, p1)
    61  	}
    62  
    63  	return p
    64  }
    65  
    66  func zeroAuto(pp *gc.Progs, n *gc.Node) {
    67  	// Note: this code must not clobber any registers.
    68  	sym := n.Sym.Linksym()
    69  	size := n.Type.Size()
    70  	for i := int64(0); i < size; i += 8 {
    71  		p := pp.Prog(arm64.AMOVD)
    72  		p.From.Type = obj.TYPE_REG
    73  		p.From.Reg = arm64.REGZERO
    74  		p.To.Type = obj.TYPE_MEM
    75  		p.To.Name = obj.NAME_AUTO
    76  		p.To.Reg = arm64.REGSP
    77  		p.To.Offset = n.Xoffset + i
    78  		p.To.Sym = sym
    79  	}
    80  }
    81  
    82  func ginsnop(pp *gc.Progs) {
    83  	p := pp.Prog(arm64.AHINT)
    84  	p.From.Type = obj.TYPE_CONST
    85  }