STREAMS 2
TYPE DOUBLE
FLOPS 2
BYTES 16

li r10, 12           # sixteen (4x4) elements per loop iteration
divd r10, r3, r10   # r3 holds loop limit, divide by elements per loop iteration
mtctr r10           # move to count register
li r6, 0            # load immediate value of 0 into r7 (used as offset in addressing)
li r7, 16           # load immediate value of 16 into r8 (used as offset in addressing)
li r8, 32           # load immediate value of 32 into r9 (used as offset in addressing)
li r9, 48           # load immediate value of 48 into r10 (used as offset in addressing)
li r10, 64          # load immediate value of 48 into r10 (used as offset in addressing)
li 11, 80          # load immediate value of 48 into r10 (used as offset in addressing)

# set accumulation registers to zero
xvsubdp     0, 0, 0
xvsubdp     1, 1, 1
xvsubdp     2, 2, 2
xvsubdp     3, 3, 3
xvsubdp     4, 4, 4
xvsubdp     5, 5, 5

# set c registers to zero
xvsubdp     6, 6, 6
xvsubdp     7, 7, 7
xvsubdp     8, 8, 8
xvsubdp     9, 9, 9
xvsubdp     10, 10, 10
xvsubdp     11, 11, 11

LOOP 12
# load A[i]
lxvd2x      12, STR0, r6
lxvd2x      13, STR0, r7
lxvd2x      14, STR0, r8
lxvd2x      15, STR0, r9
lxvd2x      16, STR0, r10
lxvd2x      17, STR0, 11

# load B[i]
lxvd2x      18, STR1, r6
lxvd2x      19, STR1, r7
lxvd2x      20, STR1, r8
lxvd2x      21, STR1, r9
lxvd2x      22, STR1, r10
lxvd2x      23, STR1, 11

# y = A[i]*B[i]-c
# xvmsubadp xt, xa, xb --> xt = xa*xb-xt
xvmsubadp   6, 12, 18
xvmsubadp   7, 13, 19
xvmsubadp   8, 14, 20
xvmsubadp   9, 15, 21
xvmsubadp   10, 16, 22
xvmsubadp   11, 17, 23

# t = sum + y
xvadddp     24, 0, 6
xvadddp     25, 1, 7
xvadddp     26, 2, 8
xvadddp     27, 3, 9
xvadddp     28, 4, 10 
xvadddp     29, 5, 11

# tmp = t - sum; we can writewrite registers holding 'sum'
xvsubdp     0, 24, 0
xvsubdp     1, 25, 1
xvsubdp     2, 26, 2
xvsubdp     3, 27, 3
xvsubdp     4, 28, 4
xvsubdp     5, 29, 5

# c = tmp - y = (t - sum) - y; we can overwrite register holding 'y'
xvsubdp     6, 0, 6
xvsubdp     7, 1, 7
xvsubdp     8, 2, 8
xvsubdp     9, 3, 9
xvsubdp     10, 4, 10
xvsubdp     11, 5, 11 

# sum = t
xvmovdp     0, 24
xvmovdp     1, 25
xvmovdp     2, 26
xvmovdp     3, 27
xvmovdp     4, 28
xvmovdp     5, 29

addi STR0, STR0, 96
addi STR1, STR1, 96
