github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/riscv64/ggen.go (about)

     1  // Copyright 2016 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 riscv64
     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/riscv"
    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  
    18  	// Adjust the frame to account for LR.
    19  	off += gc.Ctxt.FixedFrameSize()
    20  
    21  	if cnt < int64(4*gc.Widthptr) {
    22  		for i := int64(0); i < cnt; i += int64(gc.Widthptr) {
    23  			p = pp.Appendpp(p, riscv.AMOV, obj.TYPE_REG, riscv.REG_ZERO, 0, obj.TYPE_MEM, riscv.REG_SP, off+i)
    24  		}
    25  		return p
    26  	}
    27  
    28  	// TODO(jsing): Add a duff zero implementation for medium sized ranges.
    29  
    30  	// Loop, zeroing pointer width bytes at a time.
    31  	// ADD	$(off), SP, T0
    32  	// ADD	$(cnt), T0, T1
    33  	// loop:
    34  	// 	MOV	ZERO, (T0)
    35  	// 	ADD	$Widthptr, T0
    36  	//	BNE	T0, T1, loop
    37  	p = pp.Appendpp(p, riscv.AADD, obj.TYPE_CONST, 0, off, obj.TYPE_REG, riscv.REG_T0, 0)
    38  	p.Reg = riscv.REG_SP
    39  	p = pp.Appendpp(p, riscv.AADD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, riscv.REG_T1, 0)
    40  	p.Reg = riscv.REG_T0
    41  	p = pp.Appendpp(p, riscv.AMOV, obj.TYPE_REG, riscv.REG_ZERO, 0, obj.TYPE_MEM, riscv.REG_T0, 0)
    42  	loop := p
    43  	p = pp.Appendpp(p, riscv.AADD, obj.TYPE_CONST, 0, int64(gc.Widthptr), obj.TYPE_REG, riscv.REG_T0, 0)
    44  	p = pp.Appendpp(p, riscv.ABNE, obj.TYPE_REG, riscv.REG_T0, 0, obj.TYPE_BRANCH, 0, 0)
    45  	p.Reg = riscv.REG_T1
    46  	gc.Patch(p, loop)
    47  	return p
    48  }