...

Source file src/cmd/compile/internal/riscv64/ggen.go

Documentation: cmd/compile/internal/riscv64

     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  	"cmd/compile/internal/base"
     9  	"cmd/compile/internal/ir"
    10  	"cmd/compile/internal/objw"
    11  	"cmd/compile/internal/types"
    12  	"cmd/internal/obj"
    13  	"cmd/internal/obj/riscv"
    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, riscv.AMOV, obj.TYPE_REG, riscv.REG_ZERO, 0, obj.TYPE_MEM, riscv.REG_SP, off+i)
    27  		}
    28  		return p
    29  	}
    30  
    31  	if cnt <= int64(128*types.PtrSize) {
    32  		p = pp.Append(p, riscv.AADDI, obj.TYPE_CONST, 0, off, obj.TYPE_REG, riscv.REG_X25, 0)
    33  		p.Reg = riscv.REG_SP
    34  		p = pp.Append(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0)
    35  		p.To.Name = obj.NAME_EXTERN
    36  		p.To.Sym = ir.Syms.Duffzero
    37  		p.To.Offset = 8 * (128 - cnt/int64(types.PtrSize))
    38  		return p
    39  	}
    40  
    41  	// Loop, zeroing pointer width bytes at a time.
    42  	// ADD	$(off), SP, T0
    43  	// ADD	$(cnt), T0, T1
    44  	// loop:
    45  	// 	MOV	ZERO, (T0)
    46  	// 	ADD	$Widthptr, T0
    47  	//	BNE	T0, T1, loop
    48  	p = pp.Append(p, riscv.AADD, obj.TYPE_CONST, 0, off, obj.TYPE_REG, riscv.REG_T0, 0)
    49  	p.Reg = riscv.REG_SP
    50  	p = pp.Append(p, riscv.AADD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, riscv.REG_T1, 0)
    51  	p.Reg = riscv.REG_T0
    52  	p = pp.Append(p, riscv.AMOV, obj.TYPE_REG, riscv.REG_ZERO, 0, obj.TYPE_MEM, riscv.REG_T0, 0)
    53  	loop := p
    54  	p = pp.Append(p, riscv.AADD, obj.TYPE_CONST, 0, int64(types.PtrSize), obj.TYPE_REG, riscv.REG_T0, 0)
    55  	p = pp.Append(p, riscv.ABNE, obj.TYPE_REG, riscv.REG_T0, 0, obj.TYPE_BRANCH, 0, 0)
    56  	p.Reg = riscv.REG_T1
    57  	p.To.SetTarget(loop)
    58  	return p
    59  }
    60  

View as plain text