1 #include "ComplexTestsQ31.h" 2 #include <stdio.h> 3 #include "Error.h" 4 5 #define SNR_THRESHOLD 100 6 7 /* 8 9 Reference patterns are generated with 10 a double precision computation. 11 12 */ 13 #define ABS_ERROR_Q31 ((q31_t)100) 14 #define ABS_ERROR_Q63 ((q63_t)(1<<18)) 15 16 test_cmplx_conj_q31()17 void ComplexTestsQ31::test_cmplx_conj_q31() 18 { 19 const q31_t *inp1=input1.ptr(); 20 q31_t *outp=output.ptr(); 21 22 arm_cmplx_conj_q31(inp1,outp,input1.nbSamples() >> 1 ); 23 24 ASSERT_EMPTY_TAIL(output); 25 26 27 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 28 29 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31); 30 31 } 32 33 test_cmplx_dot_prod_q31()34 void ComplexTestsQ31::test_cmplx_dot_prod_q31() 35 { 36 q63_t re,im; 37 38 const q31_t *inp1=input1.ptr(); 39 const q31_t *inp2=input2.ptr(); 40 q63_t *outp=dotOutput.ptr(); 41 42 arm_cmplx_dot_prod_q31(inp1,inp2,input1.nbSamples() >> 1 ,&re,&im); 43 44 outp[0] = re; 45 outp[1] = im; 46 47 ASSERT_SNR(dotOutput,dotRef,(float32_t)SNR_THRESHOLD); 48 49 ASSERT_NEAR_EQ(dotOutput,dotRef,ABS_ERROR_Q63); 50 51 ASSERT_EMPTY_TAIL(dotOutput); 52 53 54 } 55 test_cmplx_mag_q31()56 void ComplexTestsQ31::test_cmplx_mag_q31() 57 { 58 const q31_t *inp1=input1.ptr(); 59 q31_t *outp=output.ptr(); 60 61 arm_cmplx_mag_q31(inp1,outp,input1.nbSamples() >> 1 ); 62 63 ASSERT_EMPTY_TAIL(output); 64 65 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 66 67 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31); 68 69 } 70 test_cmplx_mag_squared_q31()71 void ComplexTestsQ31::test_cmplx_mag_squared_q31() 72 { 73 const q31_t *inp1=input1.ptr(); 74 q31_t *outp=output.ptr(); 75 76 arm_cmplx_mag_squared_q31(inp1,outp,input1.nbSamples() >> 1 ); 77 78 ASSERT_EMPTY_TAIL(output); 79 80 81 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 82 83 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31); 84 85 } 86 test_cmplx_mult_cmplx_q31()87 void ComplexTestsQ31::test_cmplx_mult_cmplx_q31() 88 { 89 const q31_t *inp1=input1.ptr(); 90 const q31_t *inp2=input2.ptr(); 91 q31_t *outp=output.ptr(); 92 93 arm_cmplx_mult_cmplx_q31(inp1,inp2,outp,input1.nbSamples() >> 1 ); 94 95 ASSERT_EMPTY_TAIL(output); 96 97 98 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 99 100 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31); 101 102 } 103 test_cmplx_mult_real_q31()104 void ComplexTestsQ31::test_cmplx_mult_real_q31() 105 { 106 const q31_t *inp1=input1.ptr(); 107 const q31_t *inp2=input2.ptr(); 108 q31_t *outp=output.ptr(); 109 110 arm_cmplx_mult_real_q31(inp1,inp2,outp,input1.nbSamples() >> 1 ); 111 112 ASSERT_EMPTY_TAIL(output); 113 114 115 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 116 117 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31); 118 119 } 120 setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)121 void ComplexTestsQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr) 122 { 123 124 Testing::nbSamples_t nb=MAX_NB_SAMPLES; 125 (void)params; 126 127 128 switch(id) 129 { 130 case ComplexTestsQ31::TEST_CMPLX_CONJ_Q31_1: 131 nb = 3; 132 ref.reload(ComplexTestsQ31::REF_CONJ_Q31_ID,mgr,nb << 1); 133 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 134 135 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 136 break; 137 case ComplexTestsQ31::TEST_CMPLX_CONJ_Q31_2: 138 nb = 8; 139 ref.reload(ComplexTestsQ31::REF_CONJ_Q31_ID,mgr,nb << 1); 140 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 141 142 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 143 break; 144 case ComplexTestsQ31::TEST_CMPLX_CONJ_Q31_3: 145 nb = 11; 146 ref.reload(ComplexTestsQ31::REF_CONJ_Q31_ID,mgr,nb << 1); 147 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 148 149 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 150 break; 151 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_4: 152 nb = 3; 153 dotRef.reload(ComplexTestsQ31::REF_DOT_PROD_3_Q31_ID,mgr); 154 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 155 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 156 157 dotOutput.create(dotRef.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 158 break; 159 160 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_5: 161 nb = 8; 162 dotRef.reload(ComplexTestsQ31::REF_DOT_PROD_4N_Q31_ID,mgr); 163 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 164 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 165 166 dotOutput.create(dotRef.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 167 break; 168 169 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_6: 170 nb = 11; 171 dotRef.reload(ComplexTestsQ31::REF_DOT_PROD_4N1_Q31_ID,mgr); 172 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 173 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 174 175 dotOutput.create(dotRef.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 176 break; 177 case ComplexTestsQ31::TEST_CMPLX_MAG_Q31_7: 178 nb = 3; 179 ref.reload(ComplexTestsQ31::REF_MAG_Q31_ID,mgr,nb); 180 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 181 182 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 183 break; 184 case ComplexTestsQ31::TEST_CMPLX_MAG_Q31_8: 185 nb = 8; 186 ref.reload(ComplexTestsQ31::REF_MAG_Q31_ID,mgr,nb); 187 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 188 189 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 190 break; 191 case ComplexTestsQ31::TEST_CMPLX_MAG_Q31_9: 192 nb = 11; 193 ref.reload(ComplexTestsQ31::REF_MAG_Q31_ID,mgr,nb); 194 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 195 196 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 197 break; 198 case ComplexTestsQ31::TEST_CMPLX_MAG_SQUARED_Q31_10: 199 nb = 3; 200 ref.reload(ComplexTestsQ31::REF_MAG_SQUARED_Q31_ID,mgr,nb); 201 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 202 203 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 204 break; 205 case ComplexTestsQ31::TEST_CMPLX_MAG_SQUARED_Q31_11: 206 nb = 8; 207 ref.reload(ComplexTestsQ31::REF_MAG_SQUARED_Q31_ID,mgr,nb); 208 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 209 210 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 211 break; 212 case ComplexTestsQ31::TEST_CMPLX_MAG_SQUARED_Q31_12: 213 nb = 11; 214 ref.reload(ComplexTestsQ31::REF_MAG_SQUARED_Q31_ID,mgr,nb); 215 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 216 217 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 218 break; 219 case ComplexTestsQ31::TEST_CMPLX_MULT_CMPLX_Q31_13: 220 nb = 3; 221 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_CMPLX_Q31_ID,mgr,nb << 1); 222 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 223 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 224 225 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 226 break; 227 case ComplexTestsQ31::TEST_CMPLX_MULT_CMPLX_Q31_14: 228 nb = 8; 229 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_CMPLX_Q31_ID,mgr,nb << 1); 230 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 231 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 232 233 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 234 break; 235 case ComplexTestsQ31::TEST_CMPLX_MULT_CMPLX_Q31_15: 236 nb = 11; 237 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_CMPLX_Q31_ID,mgr,nb << 1); 238 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 239 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 240 241 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 242 break; 243 case ComplexTestsQ31::TEST_CMPLX_MULT_REAL_Q31_16: 244 nb = 3; 245 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_REAL_Q31_ID,mgr,nb << 1); 246 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 247 input2.reload(ComplexTestsQ31::INPUT3_Q31_ID,mgr,nb); 248 249 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 250 break; 251 case ComplexTestsQ31::TEST_CMPLX_MULT_REAL_Q31_17: 252 nb = 8; 253 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_REAL_Q31_ID,mgr,nb << 1); 254 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 255 input2.reload(ComplexTestsQ31::INPUT3_Q31_ID,mgr,nb); 256 257 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 258 break; 259 case ComplexTestsQ31::TEST_CMPLX_MULT_REAL_Q31_18: 260 nb = 11; 261 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_REAL_Q31_ID,mgr,nb << 1); 262 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 263 input2.reload(ComplexTestsQ31::INPUT3_Q31_ID,mgr,nb); 264 265 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 266 break; 267 268 case ComplexTestsQ31::TEST_CMPLX_CONJ_Q31_19: 269 nb = 256; 270 ref.reload(ComplexTestsQ31::REF_CONJ_Q31_ID,mgr,nb << 1); 271 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 272 273 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 274 break; 275 276 case ComplexTestsQ31::TEST_CMPLX_MAG_Q31_20: 277 nb = 256; 278 ref.reload(ComplexTestsQ31::REF_MAG_Q31_ID,mgr,nb); 279 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 280 281 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 282 break; 283 284 case ComplexTestsQ31::TEST_CMPLX_MAG_SQUARED_Q31_21: 285 nb = 256; 286 ref.reload(ComplexTestsQ31::REF_MAG_SQUARED_Q31_ID,mgr,nb); 287 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 288 289 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 290 break; 291 292 case ComplexTestsQ31::TEST_CMPLX_MULT_CMPLX_Q31_22: 293 nb = 256; 294 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_CMPLX_Q31_ID,mgr,nb << 1); 295 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 296 input2.reload(ComplexTestsQ31::INPUT2_Q31_ID,mgr,nb << 1); 297 298 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 299 break; 300 301 case ComplexTestsQ31::TEST_CMPLX_MULT_REAL_Q31_23: 302 nb = 256; 303 ref.reload(ComplexTestsQ31::REF_CMPLX_MULT_REAL_Q31_ID,mgr,nb << 1); 304 input1.reload(ComplexTestsQ31::INPUT1_Q31_ID,mgr,nb << 1); 305 input2.reload(ComplexTestsQ31::INPUT3_Q31_ID,mgr,nb); 306 307 output.create(ref.nbSamples(),ComplexTestsQ31::OUT_SAMPLES_Q31_ID,mgr); 308 break; 309 310 } 311 312 313 314 } 315 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)316 void ComplexTestsQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 317 { 318 (void)id; 319 switch(id) 320 { 321 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_4: 322 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_5: 323 case ComplexTestsQ31::TEST_CMPLX_DOT_PROD_Q31_6: 324 dotOutput.dump(mgr); 325 break; 326 327 default: 328 output.dump(mgr); 329 } 330 } 331