Subversion Repositories canSerial

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
#ifndef _BASIC_MATH_TEMPLATES_H_
2
#define _BASIC_MATH_TEMPLATES_H_
3
 
4
/*--------------------------------------------------------------------------------*/
5
/* Includes */
6
/*--------------------------------------------------------------------------------*/
7
#include "test_templates.h"
8
 
9
/*--------------------------------------------------------------------------------*/
10
/* Group Specific Templates */
11
/*--------------------------------------------------------------------------------*/
12
 
13
/**
14
 *  Compare the outputs used by basic math tests for the function under test and
15
 *  the reference function.
16
 */
17
#define BASIC_MATH_COMPARE_INTERFACE(block_size, output_type)   \
18
    TEST_ASSERT_BUFFERS_EQUAL(                                  \
19
        basic_math_output_ref.data_ptr,                         \
20
        basic_math_output_fut.data_ptr,                         \
21
        block_size * sizeof(output_type))
22
 
23
/*
24
 * Comparison SNR thresholds for the data types used in basic_math_tests.
25
 */
26
#define BASIC_MATH_SNR_THRESHOLD_float32_t 120
27
#define BASIC_MATH_SNR_THRESHOLD_q31_t 100
28
#define BASIC_MATH_SNR_THRESHOLD_q15_t 75
29
#define BASIC_MATH_SNR_THRESHOLD_q7_t 25
30
 
31
/**
32
 *  Compare reference and fut outputs using SNR.
33
 *
34
 *  @note The outputs are converted to float32_t before comparison.
35
 */
36
#define BASIC_MATH_SNR_COMPARE_INTERFACE(block_size, output_type)   \
37
    do                                                              \
38
    {                                                               \
39
        TEST_CONVERT_AND_ASSERT_SNR(                                \
40
            basic_math_output_f32_ref,                              \
41
            basic_math_output_ref.data_ptr,                         \
42
            basic_math_output_f32_fut,                              \
43
            basic_math_output_fut.data_ptr,                         \
44
            block_size,                                             \
45
            output_type,                                            \
46
            BASIC_MATH_SNR_THRESHOLD_##output_type                  \
47
            );                                                      \
48
    } while (0)
49
 
50
 
51
/**
52
 *  Compare reference and fut outputs using SNR.
53
 *
54
 *  @note The outputs are converted to float32_t before comparison.
55
 */
56
#define BASIC_MATH_SNR_ELT1_COMPARE_INTERFACE(block_size, output_type)  \
57
    do                                                                  \
58
    {                                                                   \
59
        TEST_CONVERT_AND_ASSERT_SNR(                                    \
60
            basic_math_output_f32_ref,                                  \
61
            basic_math_output_ref.data_ptr,                             \
62
            basic_math_output_f32_fut,                                  \
63
            basic_math_output_fut.data_ptr,                             \
64
            1,                                                          \
65
            output_type,                                                \
66
            BASIC_MATH_SNR_THRESHOLD_##output_type                      \
67
            );                                                          \
68
    } while (0)
69
 
70
 
71
 
72
/*--------------------------------------------------------------------------------*/
73
/* Input Interfaces */
74
/*--------------------------------------------------------------------------------*/
75
/*
76
 *  General:
77
 *  Input interfaces provide inputs to functions inside test templates.  They
78
 *  ONLY provide the inputs.  The output variables should be hard coded.
79
 *
80
 *  The input interfaces must have the following format:
81
 *
82
 *  ARM_xxx_INPUT_INTERFACE() or
83
 *  REF_xxx_INPUT_INTERFACE()
84
 *
85
 *  The xxx must be lowercase, and is intended to be the indentifying substring
86
 *  in the function's name.  Acceptable values are 'sub' or 'add' from the
87
 *  functions arm_add_q31.
88
 */
89
 
90
#define ARM_abs_INPUT_INTERFACE(input, block_size)              \
91
    PAREN(input, basic_math_output_fut.data_ptr, block_size)
92
 
93
#define REF_abs_INPUT_INTERFACE(input, block_size)              \
94
    PAREN(input, basic_math_output_ref.data_ptr, block_size)
95
 
96
#define ARM_add_INPUT_INTERFACE(input_a, input_b, block_size)           \
97
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \
98
 
99
#define REF_add_INPUT_INTERFACE(input_a, input_b, block_size)           \
100
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \
101
 
102
#define ARM_dot_prod_INPUT_INTERFACE(input_a, input_b, block_size)      \
103
    PAREN(input_a, input_b, block_size, basic_math_output_fut.data_ptr) \
104
 
105
#define REF_dot_prod_INPUT_INTERFACE(input_a, input_b, block_size)      \
106
    PAREN(input_a, input_b, block_size, basic_math_output_ref.data_ptr) \
107
 
108
#define ARM_mult_INPUT_INTERFACE(input_a, input_b, block_size)          \
109
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \
110
 
111
#define REF_mult_INPUT_INTERFACE(input_a, input_b, block_size)          \
112
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \
113
 
114
#define ARM_negate_INPUT_INTERFACE(input, block_size)           \
115
    PAREN(input, basic_math_output_fut.data_ptr, block_size)
116
 
117
#define REF_negate_INPUT_INTERFACE(input, block_size)           \
118
    PAREN(input, basic_math_output_ref.data_ptr, block_size)
119
 
120
#define ARM_offset_INPUT_INTERFACE(input, elt, block_size)          \
121
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \
122
 
123
#define REF_offset_INPUT_INTERFACE(input, elt, block_size)          \
124
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \
125
 
126
#define ARM_shift_INPUT_INTERFACE(input, elt, block_size)           \
127
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \
128
 
129
#define REF_shift_INPUT_INTERFACE(input, elt, block_size)           \
130
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \
131
 
132
#define ARM_scale_float_INPUT_INTERFACE(input, elt, block_size)     \
133
    PAREN(input, elt, basic_math_output_fut.data_ptr, block_size)   \
134
 
135
#define REF_scale_float_INPUT_INTERFACE(input, elt, block_size)     \
136
    PAREN(input, elt, basic_math_output_ref.data_ptr, block_size)   \
137
 
138
/* These two are for the fixed point functions */
139
#define ARM_scale_INPUT_INTERFACE(input, elt1, elt2, block_size)        \
140
    PAREN(input, elt1, elt2, basic_math_output_fut.data_ptr, block_size) \
141
 
142
#define REF_scale_INPUT_INTERFACE(input, elt1, elt2, block_size)        \
143
    PAREN(input, elt1, elt2, basic_math_output_ref.data_ptr, block_size) \
144
 
145
#define ARM_sub_INPUT_INTERFACE(input_a, input_b, block_size)           \
146
    PAREN(input_a, input_b, basic_math_output_fut.data_ptr, block_size) \
147
 
148
#define REF_sub_INPUT_INTERFACE(input_a, input_b, block_size)           \
149
    PAREN(input_a, input_b, basic_math_output_ref.data_ptr, block_size) \
150
 
151
 
152
/*--------------------------------------------------------------------------------*/
153
/* Test Templates */
154
/*--------------------------------------------------------------------------------*/
155
 
156
/**
157
 *  Specialization of #TEST_TEMPLATE_BUF1_BLK() for basic math tests.
158
 *
159
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
160
 *  REF_xxx_INPUT_INTERFACEs.
161
 */
162
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_BLK(fn_name,       \
163
                                                 suffix,        \
164
                                                 input_type,    \
165
                                                 output_type)   \
166
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,          \
167
                      arm_##fn_name##_##suffix)                 \
168
    {                                                           \
169
        TEST_TEMPLATE_BUF1_BLK(                                 \
170
            basic_math_f_all,                                   \
171
            basic_math_block_sizes,                             \
172
            input_type,                                         \
173
            output_type,                                        \
174
            arm_##fn_name##_##suffix,                           \
175
            ARM_##fn_name##_INPUT_INTERFACE,                    \
176
            ref_##fn_name##_##suffix,                           \
177
            REF_##fn_name##_INPUT_INTERFACE,                    \
178
            BASIC_MATH_COMPARE_INTERFACE);                      \
179
    }
180
 
181
/**
182
 *  Specialization of #TEST_TEMPLATE_BUF2_BLK() for basic math tests.
183
 *
184
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
185
 *  REF_xxx_INPUT_INTERFACEs.
186
 */
187
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF2_BLK(fn_name,               \
188
                                                 suffix,                \
189
                                                 input_type,            \
190
                                                 output_type,           \
191
                                                 comparison_interface)  \
192
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,                  \
193
                      arm_##fn_name##_##suffix)                         \
194
    {                                                                   \
195
        TEST_TEMPLATE_BUF2_BLK(                                         \
196
            basic_math_f_all,                                           \
197
            basic_math_f_all,                                           \
198
            basic_math_block_sizes,                                     \
199
            input_type,                                                 \
200
            output_type,                                                \
201
            arm_##fn_name##_##suffix,                                   \
202
            ARM_##fn_name##_INPUT_INTERFACE,                            \
203
            ref_##fn_name##_##suffix,                                   \
204
            REF_##fn_name##_INPUT_INTERFACE,                            \
205
            comparison_interface);                                      \
206
    }
207
 
208
/**
209
 *  Specialization of #TEST_TEMPLATE_BUF1_ELT1_BLK() for basic math tests.
210
 *
211
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
212
 *  REF_xxx_INPUT_INTERFACEs.
213
 */
214
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_ELT1_BLK(fn_name,      \
215
                                                      suffix,       \
216
                                                      input_type,   \
217
                                                      elt_type,     \
218
                                                      output_type)  \
219
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,              \
220
                      arm_##fn_name##_##suffix)                     \
221
    {                                                               \
222
        TEST_TEMPLATE_BUF1_ELT1_BLK(                                \
223
            basic_math_f_all,                                       \
224
            basic_math_elts,                                        \
225
            basic_math_block_sizes,                                 \
226
            input_type,                                             \
227
            elt_type,                                               \
228
            output_type,                                            \
229
            arm_##fn_name##_##suffix,                               \
230
            ARM_##fn_name##_INPUT_INTERFACE,                        \
231
            ref_##fn_name##_##suffix,                               \
232
            REF_##fn_name##_INPUT_INTERFACE,                        \
233
            BASIC_MATH_COMPARE_INTERFACE);                          \
234
    }
235
 
236
/**
237
 *  Specialization of #TEST_TEMPLATE_BUF1_ELT2_BLK() for basic math tests.
238
 *
239
 *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
240
 *  REF_xxx_INPUT_INTERFACEs.
241
 */
242
#define BASIC_MATH_DEFINE_TEST_TEMPLATE_BUF1_ELT2_BLK(fn_name,      \
243
                                                      suffix,       \
244
                                                      input_type,   \
245
                                                      elt1_type,    \
246
                                                      elt2_type,    \
247
                                                      output_type)  \
248
    JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,              \
249
                      arm_##fn_name##_##suffix)                     \
250
    {                                                               \
251
        TEST_TEMPLATE_BUF1_ELT2_BLK(                                \
252
            basic_math_f_all,                                       \
253
            basic_math_elts,                                        \
254
            basic_math_elts2,                                       \
255
            basic_math_block_sizes,                                 \
256
            input_type,                                             \
257
            elt1_type,                                              \
258
            elt2_type,                                              \
259
            output_type,                                            \
260
            arm_##fn_name##_##suffix,                               \
261
            ARM_##fn_name##_INPUT_INTERFACE,                        \
262
            ref_##fn_name##_##suffix,                               \
263
            REF_##fn_name##_INPUT_INTERFACE,                        \
264
            BASIC_MATH_COMPARE_INTERFACE);                          \
265
    }
266
 
267
#endif /* _BASIC_MATH_TEMPLATES_H_ */