1 /*
2 * Copyright (c) 2020 Stephanos Ioannidis <root@stephanos.io>
3 * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <zephyr/ztest.h>
9 #include <zephyr/kernel.h>
10 #include <stdlib.h>
11 #include <arm_math.h>
12 #include "../../common/benchmark_common.h"
13
14 #define PATTERN_LENGTH (256)
15
16 static const q7_t input1[PATTERN_LENGTH] = {
17 0x17, 0xCC, 0x33, 0xF2, 0x14, 0x01, 0x2A, 0xF2,
18 0xEC, 0x22, 0x01, 0xF7, 0x2A, 0xB5, 0xCF, 0xED,
19 0x2F, 0xE8, 0xCB, 0xE8, 0xF2, 0x08, 0xC6, 0xF2,
20 0x34, 0x2F, 0xE1, 0xEF, 0xE8, 0xF1, 0xC1, 0xEF,
21 0x3B, 0x23, 0x07, 0x01, 0xFE, 0x07, 0x03, 0xF7,
22 0x45, 0xF5, 0xE9, 0xF5, 0x0F, 0x13, 0xF5, 0xF2,
23 0x06, 0x1C, 0xF4, 0xFB, 0x12, 0xAF, 0x09, 0x0C,
24 0xE8, 0x03, 0xF2, 0x10, 0x2D, 0xD3, 0x16, 0xF5,
25 0x32, 0x0C, 0x59, 0xDA, 0x0C, 0x1C, 0xB5, 0x49,
26 0x23, 0x05, 0xA1, 0x21, 0x1B, 0x1E, 0xCE, 0xC1,
27 0xE0, 0x58, 0x22, 0x01, 0xDB, 0x05, 0x06, 0x30,
28 0xCF, 0xCC, 0x0D, 0xA1, 0x38, 0x35, 0xFE, 0x19,
29 0xD5, 0x01, 0x15, 0x37, 0x10, 0xDC, 0xF4, 0xD0,
30 0x09, 0x0F, 0x1C, 0xA3, 0xCA, 0xF7, 0x29, 0x19,
31 0x10, 0xF5, 0xFB, 0xD8, 0x0A, 0xA4, 0xD3, 0x08,
32 0x44, 0xDF, 0x2F, 0x5E, 0xFA, 0xFC, 0x48, 0x0B,
33 0xFA, 0xB9, 0x43, 0xF3, 0xCC, 0x6A, 0x51, 0x0B,
34 0xF8, 0xC6, 0xD2, 0xE0, 0xD6, 0xFA, 0xE0, 0x1B,
35 0xCC, 0x31, 0x03, 0xE1, 0x18, 0x11, 0x04, 0xCC,
36 0xFA, 0xF6, 0xFE, 0x25, 0x0E, 0x34, 0x15, 0xE7,
37 0xDD, 0xE3, 0xFE, 0xDE, 0x12, 0xCD, 0xE0, 0xF6,
38 0xD6, 0xF5, 0xDE, 0x0D, 0x28, 0x09, 0xF2, 0xC2,
39 0x1A, 0x54, 0xBB, 0xEB, 0xB7, 0xDB, 0x12, 0x05,
40 0x0F, 0xEE, 0x48, 0x00, 0x02, 0x11, 0xCA, 0xA9,
41 0x0C, 0x7F, 0x1D, 0x34, 0x13, 0xC8, 0x15, 0xFA,
42 0xDE, 0x39, 0xFE, 0x02, 0x09, 0x07, 0x2C, 0xF4,
43 0xEE, 0xE9, 0x11, 0x22, 0xE2, 0xAB, 0x37, 0xC1,
44 0xEA, 0x00, 0x3E, 0xEC, 0x23, 0x03, 0xEE, 0xBB,
45 0xE2, 0x6D, 0x17, 0x00, 0xEF, 0x2F, 0x19, 0x31,
46 0x05, 0xCB, 0xFF, 0x0A, 0x29, 0xA6, 0xD9, 0x42,
47 0x1A, 0xDE, 0x21, 0x31, 0x3E, 0x34, 0xFB, 0x11,
48 0xE3, 0x8F, 0xF1, 0xC6, 0xEF, 0x51, 0x01, 0xE0
49 };
50
51 static const q7_t input2[PATTERN_LENGTH] = {
52 0x0F, 0x06, 0xDE, 0x12, 0xE8, 0x03, 0xF2, 0xEC,
53 0x2C, 0xC7, 0x0C, 0xF3, 0xF6, 0xE2, 0xFB, 0x14,
54 0xC0, 0xDD, 0xE5, 0xDB, 0xD6, 0xCE, 0x19, 0xEB,
55 0xF7, 0x0D, 0x20, 0x0C, 0x1B, 0xB9, 0xF4, 0xF2,
56 0x02, 0xE9, 0x21, 0x3F, 0xE4, 0x02, 0x75, 0x0D,
57 0x31, 0x0F, 0x38, 0x16, 0xEA, 0x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E6, 0x6B, 0xF5, 0xCC, 0xCA, 0xDA,
80 0xD5, 0xEA, 0x1D, 0x35, 0x06, 0x0B, 0x1E, 0x17,
81 0xC5, 0xD4, 0x04, 0xF0, 0x03, 0xFE, 0x04, 0xD3,
82 0x1E, 0xD2, 0x0B, 0x08, 0xCD, 0xC1, 0xDF, 0xFE,
83 0xF7, 0xDB, 0xD0, 0x03, 0x4F, 0xE7, 0x0D, 0x1A
84 };
85
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_add_q7)86 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_add_q7)
87 {
88 uint32_t irq_key, timestamp, timespan;
89 q7_t *output;
90
91 /* Allocate output buffer */
92 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
93 zassert_not_null(output, "output buffer allocation failed");
94
95 /* Begin benchmark */
96 benchmark_begin(&irq_key, ×tamp);
97
98 /* Execute function */
99 arm_add_q7(input1, input2, output, PATTERN_LENGTH);
100
101 /* End benchmark */
102 timespan = benchmark_end(irq_key, timestamp);
103
104 /* Free output buffer */
105 free(output);
106
107 /* Print result */
108 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
109 }
110
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_sub_q7)111 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_sub_q7)
112 {
113 uint32_t irq_key, timestamp, timespan;
114 q7_t *output;
115
116 /* Allocate output buffer */
117 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
118 zassert_not_null(output, "output buffer allocation failed");
119
120 /* Begin benchmark */
121 benchmark_begin(&irq_key, ×tamp);
122
123 /* Execute function */
124 arm_sub_q7(input1, input2, output, PATTERN_LENGTH);
125
126 /* End benchmark */
127 timespan = benchmark_end(irq_key, timestamp);
128
129 /* Free output buffer */
130 free(output);
131
132 /* Print result */
133 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
134 }
135
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_mult_q7)136 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_mult_q7)
137 {
138 uint32_t irq_key, timestamp, timespan;
139 q7_t *output;
140
141 /* Allocate output buffer */
142 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
143 zassert_not_null(output, "output buffer allocation failed");
144
145 /* Begin benchmark */
146 benchmark_begin(&irq_key, ×tamp);
147
148 /* Execute function */
149 arm_mult_q7(input1, input2, output, PATTERN_LENGTH);
150
151 /* End benchmark */
152 timespan = benchmark_end(irq_key, timestamp);
153
154 /* Free output buffer */
155 free(output);
156
157 /* Print result */
158 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
159 }
160
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_abs_q7)161 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_abs_q7)
162 {
163 uint32_t irq_key, timestamp, timespan;
164 q7_t *output;
165
166 /* Allocate output buffer */
167 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
168 zassert_not_null(output, "output buffer allocation failed");
169
170 /* Begin benchmark */
171 benchmark_begin(&irq_key, ×tamp);
172
173 /* Execute function */
174 arm_abs_q7(input1, output, PATTERN_LENGTH);
175
176 /* End benchmark */
177 timespan = benchmark_end(irq_key, timestamp);
178
179 /* Free output buffer */
180 free(output);
181
182 /* Print result */
183 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
184 }
185
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_negate_q7)186 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_negate_q7)
187 {
188 uint32_t irq_key, timestamp, timespan;
189 q7_t *output;
190
191 /* Allocate output buffer */
192 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
193 zassert_not_null(output, "output buffer allocation failed");
194
195 /* Begin benchmark */
196 benchmark_begin(&irq_key, ×tamp);
197
198 /* Execute function */
199 arm_negate_q7(input1, output, PATTERN_LENGTH);
200
201 /* End benchmark */
202 timespan = benchmark_end(irq_key, timestamp);
203
204 /* Free output buffer */
205 free(output);
206
207 /* Print result */
208 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
209 }
210
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_offset_q7)211 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_offset_q7)
212 {
213 uint32_t irq_key, timestamp, timespan;
214 q7_t *output;
215
216 /* Allocate output buffer */
217 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
218 zassert_not_null(output, "output buffer allocation failed");
219
220 /* Begin benchmark */
221 benchmark_begin(&irq_key, ×tamp);
222
223 /* Execute function */
224 arm_offset_q7(input1, 1.0, output, PATTERN_LENGTH);
225
226 /* End benchmark */
227 timespan = benchmark_end(irq_key, timestamp);
228
229 /* Free output buffer */
230 free(output);
231
232 /* Print result */
233 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
234 }
235
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_scale_q7)236 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_scale_q7)
237 {
238 uint32_t irq_key, timestamp, timespan;
239 q7_t *output;
240
241 /* Allocate output buffer */
242 output = malloc(PATTERN_LENGTH * sizeof(q7_t));
243 zassert_not_null(output, "output buffer allocation failed");
244
245 /* Begin benchmark */
246 benchmark_begin(&irq_key, ×tamp);
247
248 /* Execute function */
249 arm_scale_q7(input1, 0x45, 1, output, PATTERN_LENGTH);
250
251 /* End benchmark */
252 timespan = benchmark_end(irq_key, timestamp);
253
254 /* Free output buffer */
255 free(output);
256
257 /* Print result */
258 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
259 }
260
ZTEST(basicmath_q7_benchmark,test_benchmark_vec_dot_prod_q7)261 ZTEST(basicmath_q7_benchmark, test_benchmark_vec_dot_prod_q7)
262 {
263 uint32_t irq_key, timestamp, timespan;
264 q31_t output;
265
266 /* Begin benchmark */
267 benchmark_begin(&irq_key, ×tamp);
268
269 /* Execute function */
270 arm_dot_prod_q7(input1, input2, PATTERN_LENGTH, &output);
271
272 /* End benchmark */
273 timespan = benchmark_end(irq_key, timestamp);
274
275 /* Print result */
276 TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan);
277 }
278
279 ZTEST_SUITE(basicmath_q7_benchmark, NULL, NULL, NULL, NULL, NULL);
280