summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_mult.c
blob: e9ef432c1dca47fd1ceaf28798ae4ac7d071cad2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "ref.h"

arm_status ref_mat_mult_f32(
  const arm_matrix_instance_f32 * pSrcA,
  const arm_matrix_instance_f32 * pSrcB,
  arm_matrix_instance_f32 * pDst)
{
	uint32_t r,c,i,outR,outC,innerSize;
	float32_t sum;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sum = 0;
			
			for(i=0;i<innerSize;i++)
			{
				sum += pSrcA->pData[r*innerSize + i] * pSrcB->pData[i*outC + c];
			}
			
			pDst->pData[r*outC + c] = sum;
		}
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_mult_q31(
  const arm_matrix_instance_q31 * pSrcA,
  const arm_matrix_instance_q31 * pSrcB,
  arm_matrix_instance_q31 * pDst)
{
	uint32_t r,c,i,outR,outC,innerSize;
	q63_t sum;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sum = 0;
			
			for(i=0;i<innerSize;i++)
			{
				sum += (q63_t)(pSrcA->pData[r*innerSize + i]) * pSrcB->pData[i*outC + c];
			}
			
			pDst->pData[r*outC + c] = ref_sat_q31(sum >> 31);
		}
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_mult_q15(
  const arm_matrix_instance_q15 * pSrcA,
  const arm_matrix_instance_q15 * pSrcB,
  arm_matrix_instance_q15 * pDst)
{
	uint32_t r,c,i,outR,outC,innerSize;
	q63_t sum;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sum = 0;
			
			for(i=0;i<innerSize;i++)
			{
				sum += (q31_t)(pSrcA->pData[r*innerSize + i]) * pSrcB->pData[i*outC + c];
			}
			
			pDst->pData[r*outC + c] = ref_sat_q15(sum >> 15);
		}
	}
	
	return ARM_MATH_SUCCESS;
}