summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c
blob: 57ecf1baf2977ba1881212b8f08fd4c9fda32ce7 (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
#include "ref.h"

float32_t scratchArray[8192*2]; 

arm_cfft_instance_f32 ref_cfft_sR_f32_len8192 = { 8192, 0, 0, 0 };
	
q31_t ref_sat_n(q31_t num, uint32_t bits)
{
	int32_t posMax, negMin;
	uint32_t i;

	posMax = 1;
	for (i = 0; i < (bits - 1); i++)
	{
		posMax = posMax * 2;
	}

	if (num > 0)
	{
		posMax = (posMax - 1);

		if (num > posMax)
		{
			num = posMax;
		}
	}
	else
	{
		negMin = -posMax;

		if (num < negMin)
		{
			num = negMin;
		}
	}
	return (num);
}

q31_t ref_sat_q31(q63_t num)
{
	if (num > (q63_t)INT_MAX)
	{
		return INT_MAX;
	}
	else if (num < (q63_t)0xffffffff80000000ll)
	{
		return INT_MIN;
	}
	else
	{
		return (q31_t)num;
	}
}

q15_t ref_sat_q15(q31_t num)
{
	if (num > (q31_t)SHRT_MAX)
	{
		return SHRT_MAX;
	}
	else if (num < (q31_t)0xffff8000)
	{
		return SHRT_MIN;
	}
	else
	{
		return (q15_t)num;
	}
}

q7_t ref_sat_q7(q15_t num)
{
	if (num > (q15_t)SCHAR_MAX)
	{
		return SCHAR_MAX;
	}
	else if (num < (q15_t)0xff80)
	{
		return SCHAR_MIN;
	}
	else
	{
		return (q7_t)num;
	}
}

float32_t ref_pow(float32_t a, uint32_t b)
{
	uint32_t i;
	float32_t r = a;
	
	for(i=1;i<b;i++) 
	{
		r *= a;
	}
	
	if ( b == 0)
	{
		return 1;
	}
	
	return r;
}