summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_cmplx_mult.c
blob: 93646192ebe4669f3f56428c10b4d68b78037133 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "ref.h"

arm_status ref_mat_cmplx_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 sumR,sumI;
	float32_t a0,b0,c0,d0;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sumR = 0;
			sumI = 0;
			
			for(i=0;i<innerSize;i++)
			{
				a0 = pSrcA->pData[2*(r*innerSize + i) + 0];
				b0 = pSrcA->pData[2*(r*innerSize + i) + 1];
				c0 = pSrcB->pData[2*(i*outC + c) + 0]; 
				d0 = pSrcB->pData[2*(i*outC + c) + 1];	
				
				sumR += a0 * c0 - b0 * d0;
				sumI += b0 * c0 + a0 * d0;
			}
			
			pDst->pData[2*(r*outC + c) + 0] = sumR;
			pDst->pData[2*(r*outC + c) + 1] = sumI;
		}
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_cmplx_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 sumR,sumI;
	q31_t a0,b0,c0,d0;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sumR = 0;
			sumI = 0;
			
			for(i=0;i<innerSize;i++)
			{
				a0 = pSrcA->pData[2*(r*innerSize + i) + 0];
				b0 = pSrcA->pData[2*(r*innerSize + i) + 1];
				c0 = pSrcB->pData[2*(i*outC + c) + 0]; 
				d0 = pSrcB->pData[2*(i*outC + c) + 1];	
				
				sumR += (q63_t)a0 * c0 - (q63_t)b0 * d0;
				sumI += (q63_t)b0 * c0 + (q63_t)a0 * d0;
			}
			
			pDst->pData[2*(r*outC + c) + 0] = ref_sat_q31(sumR >> 31);
			pDst->pData[2*(r*outC + c) + 1] = ref_sat_q31(sumI >> 31);
		}
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_cmplx_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 sumR,sumI;
	q15_t a0,b0,c0,d0;
	
	outR = pSrcA->numRows;
	outC = pSrcB->numCols;
	innerSize = pSrcA->numCols;
	
	for(r=0;r<outR;r++)
	{
		for(c=0;c<outC;c++)
		{
			sumR = 0;
			sumI = 0;
			
			for(i=0;i<innerSize;i++)
			{
				a0 = pSrcA->pData[2*(r*innerSize + i) + 0];
				b0 = pSrcA->pData[2*(r*innerSize + i) + 1];
				c0 = pSrcB->pData[2*(i*outC + c) + 0]; 
				d0 = pSrcB->pData[2*(i*outC + c) + 1];	
				
				sumR += (q31_t)a0 * c0 - (q31_t)b0 * d0;
				sumI += (q31_t)b0 * c0 + (q31_t)a0 * d0;
			}
			
			pDst->pData[2*(r*outC + c) + 0] = ref_sat_q15(sumR >> 15);
			pDst->pData[2*(r*outC + c) + 1] = ref_sat_q15(sumI >> 15);
		}
	}
	
	return ARM_MATH_SUCCESS;
}