1 extern "C" {
2 extern void vector_test();
3 }
4
5 #include "allocator.h"
6
7
8 #include <dsppp/arch.hpp>
9 #include <dsppp/fixed_point.hpp>
10 #include <dsppp/matrix.hpp>
11
12 #include <iostream>
13
14 #include <cmsis_tests.h>
15
16 template<typename T,int NB>
test()17 static void test()
18 {
19 std::cout << "----\r\n" << "N = " << NB << "\r\n";
20 #if defined(STATIC_TEST)
21 PVector<T,NB> a;
22 PVector<T,NB> b;
23 #else
24 PVector<T> a(NB);
25 PVector<T> b(NB);
26 #endif
27
28 init_array(a,NB);
29 init_array(b,NB);
30
31
32 INIT_SYSTICK;
33 START_CYCLE_MEASUREMENT;
34 startSectionNB(1);
35 #if defined(STATIC_TEST)
36 PVector<T,NB> res = a + b;
37 #else
38 PVector<T> res = copy(a + b);
39 #endif
40 stopSectionNB(1);
41 STOP_CYCLE_MEASUREMENT;
42
43
44
45 INIT_SYSTICK
46 START_CYCLE_MEASUREMENT;
47 #if defined(STATIC_TEST)
48 PVector<T,NB> ref;
49 #else
50 PVector<T> ref(NB);
51 #endif
52 cmsisdsp_add(a.const_ptr(),b.const_ptr(),ref.ptr(),NB);
53 STOP_CYCLE_MEASUREMENT;
54
55 if (!validate(res.const_ptr(),ref.const_ptr(),NB))
56 {
57 printf("add failed \r\n");
58 }
59
60 std::cout << "=====\r\n";
61 }
62
63
64 template<typename T,int NB>
test_view()65 void test_view()
66 {
67 std::cout << "----\r\n" << "N = " << NB << "\r\n";
68 #if defined(STATIC_TEST)
69 PVector<T,NB> a;
70 PVector<T,NB> b;
71 #else
72 PVector<T> a(NB);
73 PVector<T> b(NB);
74 #endif
75
76 init_array(a,NB);
77 init_array(b,NB);
78
79 //std::cout << a;
80 //std::cout << "\r\n";
81
82 //std::cout << PVector<T,NB/2>(a.template sub<2>());
83
84 INIT_SYSTICK;
85 START_CYCLE_MEASUREMENT;
86 startSectionNB(1);
87 #if defined(STATIC_TEST)
88 PVector<T,NB/2> res = a.template sub<2>() + b.template sub<2>();
89 #else
90 PVector<T> res = a.template sub<2>() + b.template sub<2>();
91 #endif
92 stopSectionNB(1);
93 STOP_CYCLE_MEASUREMENT;
94
95
96 PVector<T,NB/2> ref;
97
98
99
100 INIT_SYSTICK;
101 START_CYCLE_MEASUREMENT;
102 PVector<T,NB/2> da(a.template sub<2>());
103 PVector<T,NB/2> db(b.template sub<2>());
104 cmsisdsp_add(da.const_ptr(),db.const_ptr(),ref.ptr(),NB/2);
105 STOP_CYCLE_MEASUREMENT;
106
107 if (!validate(res.const_ptr(),ref.const_ptr(),NB/2))
108 {
109 printf("add failed \r\n");
110 }
111 std::cout << "=====\r\n";
112 }
113
114 template<typename T,int NB>
test_fill()115 void test_fill()
116 {
117 std::cout << "----\r\n" << "N = " << NB << "\r\n";
118
119 INIT_SYSTICK;
120 START_CYCLE_MEASUREMENT;
121 startSectionNB(1);
122 #if defined(STATIC_TEST)
123 PVector<T,NB> res(T(1));
124 #else
125 PVector<T> res(NB,T(1));
126 #endif
127 stopSectionNB(1);
128 STOP_CYCLE_MEASUREMENT;
129
130 }
131
132
133 template<typename T>
all_vector_test()134 void all_vector_test()
135 {
136
137
138 const int nb_tails = TailForTests<T>::tail;
139 const int nb_loops = TailForTests<T>::loop;
140
141 title<T>("Vector");
142
143 // For benchmarks
144 test<T,NBVEC_4>();
145 test<T,NBVEC_8>();
146 test<T,NBVEC_9>();
147 test<T,NBVEC_16>();
148 test<T,NBVEC_32>();
149 test<T,NBVEC_64>();
150 test<T,NBVEC_128>();
151 test<T,NBVEC_256>();
152 test<T,NBVEC_258>();
153 test<T,NBVEC_512>();
154 test<T,NBVEC_1024>();
155 test<T,NBVEC_2048>();
156
157 // For tests
158 test<T,1>();
159 test<T,nb_tails>();
160 test<T,nb_loops>();
161 test<T,nb_loops+1>();
162 test<T,nb_loops+nb_tails>();
163
164
165 title<T>("Vector View");
166
167 test_view<T,NBVEC_4>();
168 test_view<T,NBVEC_8>();
169 test_view<T,NBVEC_16>();
170 test_view<T,NBVEC_32>();
171 test_view<T,NBVEC_64>();
172
173 if constexpr (nb_tails>1)
174 {
175 test_view<T,nb_tails>();
176 }
177 test_view<T,nb_loops>();
178 test_view<T,nb_loops+1>();
179 test_view<T,nb_loops+nb_tails>();
180
181
182 title<T>("Vector fill");
183 test_fill<T,NBVEC_4>();
184 test_fill<T,NBVEC_8>();
185 test_fill<T,NBVEC_16>();
186 test_fill<T,NBVEC_32>();
187 test_fill<T,NBVEC_64>();
188
189 test_fill<T,1>();
190 test_fill<T,nb_tails>();
191 test_fill<T,nb_loops>();
192 test_fill<T,nb_loops+1>();
193 test_fill<T,nb_loops+nb_tails>();
194
195 }
196
vector_test()197 void vector_test()
198 {
199 #if defined(VECTOR_TEST)
200 #if defined(F64_DT)
201 all_vector_test<double>();
202 #endif
203 #if defined(F32_DT)
204 all_vector_test<float>();
205 #endif
206 #if defined(F16_DT) && !defined(DISABLEFLOAT16)
207 all_vector_test<float16_t>();
208 #endif
209 #if defined(Q31_DT)
210 all_vector_test<Q31>();
211 #endif
212 #if defined(Q15_DT)
213 all_vector_test<Q15>();
214 #endif
215 #if defined(Q7_DT)
216 all_vector_test<Q7>();
217 #endif
218 #endif
219 }
220