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