1 #*****************************************************************************
2 # vvadd function (assembly version)
3 #-----------------------------------------------------------------------------
6 #--------------------------------------------------------------------------
8 #--------------------------------------------------------------------------
10 # Here are some defines that make writing assembly code easier.
12 # I'm using the knowledge that rN will be placed in register a0, rA will be
13 # placed into register a1, etc., based on the calling convention for functions.
22 # WARNING: do not write to the s0,...,s9 registers without first saving them to
25 #--------------------------------------------------------------------------
26 # void scalar_vvadd_asm( int n, float a[], float b[], float c[] )
27 #--------------------------------------------------------------------------
31 .globl scalar_vvadd_asm
32 .type scalar_vvadd_asm,@function
36 # ***** Scalar Example *****
38 beq rN, zero, done # exit early if n == 0
54 #--------------------------------------------------------------------------
55 # void vt_vvadd_asm( int n, float a[], float b[], float c[] )
56 #--------------------------------------------------------------------------
59 # ***** Vector-Thread Example *****
62 .type vt_vvadd_asm,@function
69 # First, configure the vector unit.
70 # rd (given vlen), desired vlen, num of x-regs, num of f-regs
71 # For vvadd, we do not need to use any x-registers, and only two
72 # floating point registers. By using fewer registers, hwacha can give us a longer vector length!
73 # But make sure to use registers starting from x0, f0!
74 # WARNING: there is a BUG if you tell it you want 0 registers of any type!
75 # So here I'm asking for 1 x-register, even though I don't use any of them.
76 vvcfgivl rVLen, rN, 1, 2
80 vsetvl rVLen, rN # set the vector length
81 # rN is the desired (application) vector length
82 # rVLen is what vector length we were given
84 vflw vf0, rA # vector loads
86 vf 0(a5) # jump to vector-fetch code
87 vfsw vf0, rC # vector store
89 sub rN, rN, rVLen # book keeping
90 slli a6, rVLen, 2 # turn num_elements into num_bytes
94 bne rN, zero, stripmineloop
97 fence.v.l # make stores visible to the control processor
104 # The C code uses a jalr instruction to call this function
105 # so we can use a jr to return back to where the function
106 # was called. Also known as "ret", for "return".