github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/ppc64/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 ppc64 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/ppc64" 11 ) 12 13 func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog { 14 if cnt == 0 { 15 return p 16 } 17 if cnt < int64(4*gc.Widthptr) { 18 for i := int64(0); i < cnt; i += int64(gc.Widthptr) { 19 p = pp.Appendpp(p, ppc64.AMOVD, obj.TYPE_REG, ppc64.REGZERO, 0, obj.TYPE_MEM, ppc64.REGSP, gc.Ctxt.FixedFrameSize()+off+i) 20 } 21 } else if cnt <= int64(128*gc.Widthptr) { 22 p = pp.Appendpp(p, ppc64.AADD, obj.TYPE_CONST, 0, gc.Ctxt.FixedFrameSize()+off-8, obj.TYPE_REG, ppc64.REGRT1, 0) 23 p.Reg = ppc64.REGSP 24 p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0) 25 p.To.Name = obj.NAME_EXTERN 26 p.To.Sym = gc.Duffzero 27 p.To.Offset = 4 * (128 - cnt/int64(gc.Widthptr)) 28 } else { 29 p = pp.Appendpp(p, ppc64.AMOVD, obj.TYPE_CONST, 0, gc.Ctxt.FixedFrameSize()+off-8, obj.TYPE_REG, ppc64.REGTMP, 0) 30 p = pp.Appendpp(p, ppc64.AADD, obj.TYPE_REG, ppc64.REGTMP, 0, obj.TYPE_REG, ppc64.REGRT1, 0) 31 p.Reg = ppc64.REGSP 32 p = pp.Appendpp(p, ppc64.AMOVD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, ppc64.REGTMP, 0) 33 p = pp.Appendpp(p, ppc64.AADD, obj.TYPE_REG, ppc64.REGTMP, 0, obj.TYPE_REG, ppc64.REGRT2, 0) 34 p.Reg = ppc64.REGRT1 35 p = pp.Appendpp(p, ppc64.AMOVDU, obj.TYPE_REG, ppc64.REGZERO, 0, obj.TYPE_MEM, ppc64.REGRT1, int64(gc.Widthptr)) 36 p1 := p 37 p = pp.Appendpp(p, ppc64.ACMP, obj.TYPE_REG, ppc64.REGRT1, 0, obj.TYPE_REG, ppc64.REGRT2, 0) 38 p = pp.Appendpp(p, ppc64.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0) 39 gc.Patch(p, p1) 40 } 41 42 return p 43 } 44 45 func ginsnop(pp *gc.Progs) *obj.Prog { 46 p := pp.Prog(ppc64.AOR) 47 p.From.Type = obj.TYPE_REG 48 p.From.Reg = ppc64.REG_R0 49 p.To.Type = obj.TYPE_REG 50 p.To.Reg = ppc64.REG_R0 51 return p 52 } 53 54 func ginsnopdefer(pp *gc.Progs) *obj.Prog { 55 // On PPC64 two nops are required in the defer case. 56 // 57 // (see gc/cgen.go, gc/plive.go -- copy of comment below) 58 // 59 // On ppc64, when compiling Go into position 60 // independent code on ppc64le we insert an 61 // instruction to reload the TOC pointer from the 62 // stack as well. See the long comment near 63 // jmpdefer in runtime/asm_ppc64.s for why. 64 // If the MOVD is not needed, insert a hardware NOP 65 // so that the same number of instructions are used 66 // on ppc64 in both shared and non-shared modes. 67 68 ginsnop(pp) 69 if gc.Ctxt.Flag_shared { 70 p := pp.Prog(ppc64.AMOVD) 71 p.From.Type = obj.TYPE_MEM 72 p.From.Offset = 24 73 p.From.Reg = ppc64.REGSP 74 p.To.Type = obj.TYPE_REG 75 p.To.Reg = ppc64.REG_R2 76 return p 77 } 78 return ginsnop(pp) 79 }