summaryrefslogtreecommitdiff
path: root/fw/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/inc/basic_math_tests/basic_math_templates.h
blob: 958ef78446b8e93c40542c61ad1694d2d8dbff7d (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifndef _BASIC_MATH_TEMPLATES_H_
#define _BASIC_MATH_TEMPLATES_H_

/*--------------------------------------------------------------------------------*/
/* Includes */
/*--------------------------------------------------------------------------------*/
#include "test_templates.h"

/*--------------------------------------------------------------------------------*/
/* Group Specific Templates */
/*--------------------------------------------------------------------------------*/

/**
 *  Compare the outputs used by basic math tests for the function under test and
 *  the reference function.
 */
#define BASIC_MATH_COMPARE_INTERFACE(block_size, output_type)   \
    TEST_ASSERT_BUFFERS_EQUAL(                                  \
        basic_math_output_ref.data_ptr,                         \
        basic_math_output_fut.data_ptr,                         \
        block_size * sizeof(output_type))

/*
 * Comparison SNR thresholds for the data types used in basic_math_tests.
 */
#define BASIC_MATH_SNR_THRESHOLD_float32_t 120
#define BASIC_MATH_SNR_THRESHOLD_q31_t 100
#define BASIC_MATH_SNR_THRESHOLD_q15_t 75
#define BASIC_MATH_SNR_THRESHOLD_q7_t 25

/**
 *  Compare reference and fut outputs using SNR.
 *
 *  @note The outputs are converted to float32_t before comparison.
 */
#define BASIC_MATH_SNR_COMPARE_INTERFACE(block_size, output_type)   \
    do                                                              \
    {                                                               \
        TEST_CONVERT_AND_ASSERT_SNR(                                \
            basic_math_output_f32_ref,                              \
            basic_math_output_ref.data_ptr,                         \
            basic_math_output_f32_fut,                              \
            basic_math_output_fut.data_ptr,                         \
            block_size,                                             \
            output_type,                                            \
            BASIC_MATH_SNR_THRESHOLD_##output_type                  \
            );                                                      \
    } while (0)


/**
 *  Compare reference and fut outputs using SNR.
 *
 *  @note The outputs are converted to float32_t before comparison.
 */
#define BASIC_MATH_SNR_ELT1_COMPARE_INTERFACE(block_size, output_type)  \
    do                                                                  \
    {                                                                   \
        TEST_CONVERT_AND_ASSERT_SNR(                                    \
            basic_math_output_f32_ref,                                  \
            basic_math_output_ref.data_ptr,                             \
            basic_math_output_f32_fut,                                  \
            basic_math_output_fut.data_ptr,                             \
            1,                                                          \
            output_type,                                                \
            BASIC_MATH_SNR_THRESHOLD_##output_type                      \
            );                                                          \
    } while (0)



/*--------------------------------------------------------------------------------*/
/* Input Interfaces */
/*--------------------------------------------------------------------------------*/
/*
 *  General:
 *  Input interfaces provide inputs to functions inside test templates.  They
 *  ONLY provide the inputs.  The output variables should be hard coded.
 *
 *  The input interfaces must have the following format:
 *
 *  ARM_xxx_INPUT_INTERFACE() or
 *  REF_xxx_INPUT_INTERFACE()
 *
 *  The xxx must be lowercase, and is intended to be the indentifying substring
 *  in the function's name.  Acceptable values are 'sub' or 'add' from the
 *  functions arm_add_q31.
 */

#define ARM_abs_INPUT_INTERFACE(input, block_size)              \
    PAREN(input, basic_math_output_fut.data_ptr, block_size)

#define REF_abs_INPUT_INTERFACE(input, block_size)              \
    PAREN(input, basic_math_output_ref.data_ptr, block_size)

#define ARM_add_INPUT_INTERFACE(input_a, input_b, block_size)           \
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \

#define REF_add_INPUT_INTERFACE(input_a, input_b, block_size)           \
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \

#define ARM_dot_prod_INPUT_INTERFACE(input_a, input_b, block_size)      \
    PAREN(input_a, input_b, block_size, basic_math_output_fut.data_ptr) \

#define REF_dot_prod_INPUT_INTERFACE(input_a, input_b, block_size)      \
    PAREN(input_a, input_b, block_size, basic_math_output_ref.data_ptr) \

#define ARM_mult_INPUT_INTERFACE(input_a, input_b, block_size)          \
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \

#define REF_mult_INPUT_INTERFACE(input_a, input_b, block_size)          \
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \

#define ARM_negate_INPUT_INTERFACE(input, block_size)           \
    PAREN(input, basic_math_output_fut.data_ptr, block_size)

#define REF_negate_INPUT_INTERFACE(input, block_size)           \
    PAREN(input, basic_math_output_ref.data_ptr, block_size)

#define ARM_offset_INPUT_INTERFACE(input, elt, block_size)          \
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \

#define REF_offset_INPUT_INTERFACE(input, elt, block_size)          \
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \

#define ARM_shift_INPUT_INTERFACE(input, elt, block_size)           \
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \

#define REF_shift_INPUT_INTERFACE(input, elt, block_size)           \
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \

#define ARM_scale_float_INPUT_INTERFACE(input, elt, block_size)     \
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \

#define REF_scale_float_INPUT_INTERFACE(input, elt, block_size)     \
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \

/* These two are for the fixed point functions */
#define ARM_scale_INPUT_INTERFACE(input, elt1, elt2, block_size)        \
    PAREN(input, elt1, elt2, basic_math_output_fut.data_ptr, block_size) \

#define REF_scale_INPUT_INTERFACE(input, elt1, elt2, block_size)        \
    PAREN(input, elt1, elt2, basic_math_output_ref.data_ptr, block_size) \

#define ARM_sub_INPUT_INTERFACE(input_a, input_b, block_size)           \
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \

#define REF_sub_INPUT_INTERFACE(input_a, input_b, block_size)           \
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \


/*--------------------------------------------------------------------------------*/
/* Test Templates */
/*--------------------------------------------------------------------------------*/

/**
 *  Specialization of #TEST_TEMPLATE_BUF1_BLK() for basic math tests.
 *
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
 *  REF_xxx_INPUT_INTERFACEs.
 */
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_BLK(fn_name,       \
                                                 suffix,        \
                                                 input_type,    \
                                                 output_type)   \
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,          \
                      arm_##fn_name##_##suffix)                 \
    {                                                           \
        TEST_TEMPLATE_BUF1_BLK(                                 \
            basic_math_f_all,                                   \
            basic_math_block_sizes,                             \
            input_type,                                         \
            output_type,                                        \
            arm_##fn_name##_##suffix,                           \
            ARM_##fn_name##_INPUT_INTERFACE,                    \
            ref_##fn_name##_##suffix,                           \
            REF_##fn_name##_INPUT_INTERFACE,                    \
            BASIC_MATH_COMPARE_INTERFACE);                      \
    }

/**
 *  Specialization of #TEST_TEMPLATE_BUF2_BLK() for basic math tests.
 *
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
 *  REF_xxx_INPUT_INTERFACEs.
 */
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF2_BLK(fn_name,               \
                                                 suffix,                \
                                                 input_type,            \
                                                 output_type,           \
                                                 comparison_interface)  \
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,                  \
                      arm_##fn_name##_##suffix)                         \
    {                                                                   \
        TEST_TEMPLATE_BUF2_BLK(                                         \
            basic_math_f_all,                                           \
            basic_math_f_all,                                           \
            basic_math_block_sizes,                                     \
            input_type,                                                 \
            output_type,                                                \
            arm_##fn_name##_##suffix,                                   \
            ARM_##fn_name##_INPUT_INTERFACE,                            \
            ref_##fn_name##_##suffix,                                   \
            REF_##fn_name##_INPUT_INTERFACE,                            \
            comparison_interface);                                      \
    }

/**
 *  Specialization of #TEST_TEMPLATE_BUF1_ELT1_BLK() for basic math tests.
 *
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
 *  REF_xxx_INPUT_INTERFACEs.
 */
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_ELT1_BLK(fn_name,      \
                                                      suffix,       \
                                                      input_type,   \
                                                      elt_type,     \
                                                      output_type)  \
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,              \
                      arm_##fn_name##_##suffix)                     \
    {                                                               \
        TEST_TEMPLATE_BUF1_ELT1_BLK(                                \
            basic_math_f_all,                                       \
            basic_math_elts,                                        \
            basic_math_block_sizes,                                 \
            input_type,                                             \
            elt_type,                                               \
            output_type,                                            \
            arm_##fn_name##_##suffix,                               \
            ARM_##fn_name##_INPUT_INTERFACE,                        \
            ref_##fn_name##_##suffix,                               \
            REF_##fn_name##_INPUT_INTERFACE,                        \
            BASIC_MATH_COMPARE_INTERFACE);                          \
    }

/**
 *  Specialization of #TEST_TEMPLATE_BUF1_ELT2_BLK() for basic math tests.
 *
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
 *  REF_xxx_INPUT_INTERFACEs.
 */
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_ELT2_BLK(fn_name,      \
                                                      suffix,       \
                                                      input_type,   \
                                                      elt1_type,    \
                                                      elt2_type,    \
                                                      output_type)  \
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,              \
                      arm_##fn_name##_##suffix)                     \
    {                                                               \
        TEST_TEMPLATE_BUF1_ELT2_BLK(                                \
            basic_math_f_all,                                       \
            basic_math_elts,                                        \
            basic_math_elts2,                                       \
            basic_math_block_sizes,                                 \
            input_type,                                             \
            elt1_type,                                              \
            elt2_type,                                              \
            output_type,                                            \
            arm_##fn_name##_##suffix,                               \
            ARM_##fn_name##_INPUT_INTERFACE,                        \
            ref_##fn_name##_##suffix,                               \
            REF_##fn_name##_INPUT_INTERFACE,                        \
            BASIC_MATH_COMPARE_INTERFACE);                          \
    }

#endif /* _BASIC_MATH_TEMPLATES_H_ */