github.com/bir3/gocompiler@v0.9.2202/src/cmd/compile/internal/loong64/ggen.go (about)

     1  // Copyright 2022 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 loong64
     6  
     7  import (
     8  	"github.com/bir3/gocompiler/src/cmd/compile/internal/base"
     9  	"github.com/bir3/gocompiler/src/cmd/compile/internal/ir"
    10  	"github.com/bir3/gocompiler/src/cmd/compile/internal/objw"
    11  	"github.com/bir3/gocompiler/src/cmd/compile/internal/types"
    12  	"github.com/bir3/gocompiler/src/cmd/internal/obj"
    13  	"github.com/bir3/gocompiler/src/cmd/internal/obj/loong64"
    14  )
    15  
    16  func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog {
    17  	if cnt == 0 {
    18  		return p
    19  	}
    20  
    21  	// Adjust the frame to account for LR.
    22  	off += base.Ctxt.Arch.FixedFrameSize
    23  
    24  	if cnt < int64(4*types.PtrSize) {
    25  		for i := int64(0); i < cnt; i += int64(types.PtrSize) {
    26  			p = pp.Append(p, loong64.AMOVV, obj.TYPE_REG, loong64.REGZERO, 0, obj.TYPE_MEM, loong64.REGSP, off+i)
    27  		}
    28  	} else if cnt <= int64(128*types.PtrSize) {
    29  		p = pp.Append(p, loong64.AADDV, obj.TYPE_CONST, 0, off, obj.TYPE_REG, loong64.REGRT1, 0)
    30  		p.Reg = loong64.REGSP
    31  		p = pp.Append(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0)
    32  		p.To.Name = obj.NAME_EXTERN
    33  		p.To.Sym = ir.Syms.Duffzero
    34  		p.To.Offset = 8 * (128 - cnt/int64(types.PtrSize))
    35  	} else {
    36  		//	ADDV	$(off), SP, r1
    37  		//	ADDV	$cnt, r1, r2
    38  		// loop:
    39  		//	MOVV	R0, (r1)
    40  		//	ADDV	$Widthptr, r1
    41  		//	BNE	r1, r2, loop
    42  		p = pp.Append(p, loong64.AADDV, obj.TYPE_CONST, 0, off, obj.TYPE_REG, loong64.REGRT1, 0)
    43  		p.Reg = loong64.REGSP
    44  		p = pp.Append(p, loong64.AADDV, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, loong64.REGRT2, 0)
    45  		p.Reg = loong64.REGRT1
    46  		p = pp.Append(p, loong64.AMOVV, obj.TYPE_REG, loong64.REGZERO, 0, obj.TYPE_MEM, loong64.REGRT1, 0)
    47  		loop := p
    48  		p = pp.Append(p, loong64.AADDV, obj.TYPE_CONST, 0, int64(types.PtrSize), obj.TYPE_REG, loong64.REGRT1, 0)
    49  		p = pp.Append(p, loong64.ABNE, obj.TYPE_REG, loong64.REGRT1, 0, obj.TYPE_BRANCH, 0, 0)
    50  		p.Reg = loong64.REGRT2
    51  		p.To.SetTarget(loop)
    52  	}
    53  
    54  	return p
    55  }
    56  
    57  func ginsnop(pp *objw.Progs) *obj.Prog {
    58  	p := pp.Prog(loong64.ANOOP)
    59  	return p
    60  }