1 /*
2 * Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
3 * Copyright (C) 2010-2021 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_f16.h>
12 #include <arm_const_structs.h>
13 #include "../../common/test_common.h"
14
15 #include "rf16.pat"
16
17 #define SNR_ERROR_THRESH ((float32_t)58)
18
test_arm_rfft_f16_real_backend(bool inverse,const uint16_t * input,const uint16_t * ref,size_t length)19 static void test_arm_rfft_f16_real_backend(
20 bool inverse, const uint16_t *input, const uint16_t *ref,
21 size_t length)
22 {
23 arm_rfft_fast_instance_f16 inst;
24 float16_t *output, *scratch;
25
26 /* Initialise instance */
27 arm_rfft_fast_init_f16(&inst, length);
28
29 /* Allocate output buffer */
30 output = malloc(length * sizeof(float16_t));
31 zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
32
33 scratch = calloc(length + 2, sizeof(float16_t)); /* see #24701 */
34 zassert_not_null(scratch, ASSERT_MSG_BUFFER_ALLOC_FAILED);
35
36 /* Load data in place */
37 memcpy(scratch, input, length * sizeof(float16_t));
38
39 /* Run test function */
40 arm_rfft_fast_f16(&inst, scratch, output, inverse);
41
42 /* Validate output */
43 zassert_true(
44 test_snr_error_f16(length, output, (float16_t *)ref,
45 SNR_ERROR_THRESH),
46 ASSERT_MSG_SNR_LIMIT_EXCEED);
47
48 /* Free output buffer */
49 free(output);
50 free(scratch);
51 }
52
test_arm_rfft_f16_real(const uint16_t * input,const uint16_t * ref,size_t length)53 static void test_arm_rfft_f16_real(
54 const uint16_t *input, const uint16_t *ref, size_t length)
55 {
56 test_arm_rfft_f16_real_backend(false, input, ref, length);
57 }
58
59 DEFINE_TEST_VARIANT3(transform_rf16,
60 arm_rfft_f16_real, noisy_32,
61 in_rfft_noisy_32, ref_rfft_noisy_32, 32);
62
63 DEFINE_TEST_VARIANT3(transform_rf16,
64 arm_rfft_f16_real, noisy_64,
65 in_rfft_noisy_64, ref_rfft_noisy_64, 64);
66
67 DEFINE_TEST_VARIANT3(transform_rf16,
68 arm_rfft_f16_real, noisy_128,
69 in_rfft_noisy_128, ref_rfft_noisy_128, 128);
70
71 DEFINE_TEST_VARIANT3(transform_rf16,
72 arm_rfft_f16_real, noisy_256,
73 in_rfft_noisy_256, ref_rfft_noisy_256, 256);
74
75 DEFINE_TEST_VARIANT3(transform_rf16,
76 arm_rfft_f16_real, noisy_512,
77 in_rfft_noisy_512, ref_rfft_noisy_512, 512);
78
79 DEFINE_TEST_VARIANT3(transform_rf16,
80 arm_rfft_f16_real, noisy_1024,
81 in_rfft_noisy_1024, ref_rfft_noisy_1024, 1024);
82
83 DEFINE_TEST_VARIANT3(transform_rf16,
84 arm_rfft_f16_real, noisy_2048,
85 in_rfft_noisy_2048, ref_rfft_noisy_2048, 2048);
86
87 DEFINE_TEST_VARIANT3(transform_rf16,
88 arm_rfft_f16_real, noisy_4096,
89 in_rfft_noisy_4096, ref_rfft_noisy_4096, 4096);
90
91 DEFINE_TEST_VARIANT3(transform_rf16,
92 arm_rfft_f16_real, step_32,
93 in_rfft_step_32, ref_rfft_step_32, 32);
94
95 DEFINE_TEST_VARIANT3(transform_rf16,
96 arm_rfft_f16_real, step_64,
97 in_rfft_step_64, ref_rfft_step_64, 64);
98
99 DEFINE_TEST_VARIANT3(transform_rf16,
100 arm_rfft_f16_real, step_128,
101 in_rfft_step_128, ref_rfft_step_128, 128);
102
103 DEFINE_TEST_VARIANT3(transform_rf16,
104 arm_rfft_f16_real, step_256,
105 in_rfft_step_256, ref_rfft_step_256, 256);
106
107 DEFINE_TEST_VARIANT3(transform_rf16,
108 arm_rfft_f16_real, step_512,
109 in_rfft_step_512, ref_rfft_step_512, 512);
110
111 DEFINE_TEST_VARIANT3(transform_rf16,
112 arm_rfft_f16_real, step_1024,
113 in_rfft_step_1024, ref_rfft_step_1024, 1024);
114
115 DEFINE_TEST_VARIANT3(transform_rf16,
116 arm_rfft_f16_real, step_2048,
117 in_rfft_step_2048, ref_rfft_step_2048, 2048);
118
119 DEFINE_TEST_VARIANT3(transform_rf16,
120 arm_rfft_f16_real, step_4096,
121 in_rfft_step_4096, ref_rfft_step_4096, 4096);
122
test_arm_rifft_f16_real(const uint16_t * input,const uint16_t * ref,size_t length)123 static void test_arm_rifft_f16_real(
124 const uint16_t *input, const uint16_t *ref, size_t length)
125 {
126 test_arm_rfft_f16_real_backend(true, input, ref, length);
127 }
128
129 DEFINE_TEST_VARIANT3(transform_rf16,
130 arm_rifft_f16_real, noisy_32,
131 in_rifft_noisy_32, in_rfft_noisy_32, 32);
132
133 DEFINE_TEST_VARIANT3(transform_rf16,
134 arm_rifft_f16_real, noisy_64,
135 in_rifft_noisy_64, in_rfft_noisy_64, 64);
136
137 DEFINE_TEST_VARIANT3(transform_rf16,
138 arm_rifft_f16_real, noisy_128,
139 in_rifft_noisy_128, in_rfft_noisy_128, 128);
140
141 DEFINE_TEST_VARIANT3(transform_rf16,
142 arm_rifft_f16_real, noisy_256,
143 in_rifft_noisy_256, in_rfft_noisy_256, 256);
144
145 DEFINE_TEST_VARIANT3(transform_rf16,
146 arm_rifft_f16_real, noisy_512,
147 in_rifft_noisy_512, in_rfft_noisy_512, 512);
148
149 DEFINE_TEST_VARIANT3(transform_rf16,
150 arm_rifft_f16_real, noisy_1024,
151 in_rifft_noisy_1024, in_rfft_noisy_1024, 1024);
152
153 DEFINE_TEST_VARIANT3(transform_rf16,
154 arm_rifft_f16_real, noisy_2048,
155 in_rifft_noisy_2048, in_rfft_noisy_2048, 2048);
156
157 DEFINE_TEST_VARIANT3(transform_rf16,
158 arm_rifft_f16_real, noisy_4096,
159 in_rifft_noisy_4096, in_rfft_noisy_4096, 4096);
160
161 DEFINE_TEST_VARIANT3(transform_rf16,
162 arm_rifft_f16_real, step_32,
163 in_rifft_step_32, in_rfft_step_32, 32);
164
165 DEFINE_TEST_VARIANT3(transform_rf16,
166 arm_rifft_f16_real, step_64,
167 in_rifft_step_64, in_rfft_step_64, 64);
168
169 DEFINE_TEST_VARIANT3(transform_rf16,
170 arm_rifft_f16_real, step_128,
171 in_rifft_step_128, in_rfft_step_128, 128);
172
173 DEFINE_TEST_VARIANT3(transform_rf16,
174 arm_rifft_f16_real, step_256,
175 in_rifft_step_256, in_rfft_step_256, 256);
176
177 DEFINE_TEST_VARIANT3(transform_rf16,
178 arm_rifft_f16_real, step_512,
179 in_rifft_step_512, in_rfft_step_512, 512);
180
181 DEFINE_TEST_VARIANT3(transform_rf16,
182 arm_rifft_f16_real, step_1024,
183 in_rifft_step_1024, in_rfft_step_1024, 1024);
184
185 DEFINE_TEST_VARIANT3(transform_rf16,
186 arm_rifft_f16_real, step_2048,
187 in_rifft_step_2048, in_rfft_step_2048, 2048);
188
189 DEFINE_TEST_VARIANT3(transform_rf16,
190 arm_rifft_f16_real, step_4096,
191 in_rifft_step_4096, in_rfft_step_4096, 4096);
192
193 ZTEST_SUITE(transform_rf16, NULL, NULL, NULL, NULL, NULL);
194