1
2
3
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
22 off += base.Ctxt.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_A0, 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
42
43
44
45
46
47
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