XCORE SDK
XCORE Software Development Kit
testing.h
1 // Copyright 2020-2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 #pragma once
4 
5 #include "xs3_math_conf.h"
6 #include "xs3_api.h"
7 #include "xs3_math_types.h"
8 
9 
14 C_API
15 unsigned getTimestamp();
16 
17 
18 /*
19  * Type conversion
20  */
21 
22 typedef enum {
23 
24  //In trying to convert to a integer type the exponent of the float forces
25  //the mantissa of the integer type to not fit in its storage type.
26  CANNOT_FIT_MANTISSA=1,
27 
28  //In trying to convert to a unsinged type the float contains a negative number.
29  NEGATIVE_TO_UNSIGNED=2,
30 
31  //In trying to convert to a float type the exponent of the integer is out of range.
32  CANNOT_FIT_EXPONENT=4,
33 
34 } conv_error_e;
35 
36 C_API double conv_s8_to_double (const int8_t x, const exponent_t x_exp, conv_error_e *error);
37 C_API double conv_u8_to_double(const uint8_t x, const exponent_t x_exp, conv_error_e *error);
38 C_API double conv_s16_to_double(const int16_t x, const exponent_t x_exp, conv_error_e *error);
39 C_API double conv_u16_to_double(const uint16_t x, const exponent_t x_exp, conv_error_e *error);
40 C_API double conv_s32_to_double (const int32_t x, const exponent_t x_exp, conv_error_e *error);
41 C_API double conv_u32_to_double(const uint32_t x, const exponent_t x_exp, conv_error_e *error);
42 C_API double conv_s64_to_double (const int64_t x, const exponent_t x_exp, conv_error_e *error);
43 C_API double conv_u64_to_double(const uint64_t x, const exponent_t x_exp, conv_error_e *error);
44 
45 
46 C_API int8_t conv_double_to_s8 (double d, const exponent_t d_exp, conv_error_e *error);
47 C_API uint8_t conv_double_to_u8(double d, const exponent_t d_exp, conv_error_e *error);
48 C_API int16_t conv_double_to_s16 (double d, const exponent_t d_exp, conv_error_e *error);
49 C_API uint16_t conv_double_to_u16(double d, const exponent_t d_exp, conv_error_e *error);
50 C_API int32_t conv_double_to_s32 (double d, const exponent_t d_exp, conv_error_e *error);
51 C_API uint32_t conv_double_to_u32(double d, const exponent_t d_exp, conv_error_e *error);
52 C_API int64_t conv_double_to_s64 (double d, const exponent_t d_exp, conv_error_e *error);
53 C_API uint64_t conv_double_to_u64(double d, const exponent_t d_exp, conv_error_e *error);
54 
55 
56 C_API complex_double_t conv_complex_s16_to_complex_double(complex_s16_t x, const exponent_t x_exp, conv_error_e *error);
57 C_API complex_double_t conv_complex_s32_to_complex_double(complex_s32_t x, const exponent_t x_exp, conv_error_e *error);
58 C_API complex_s16_t conv_complex_double_to_complex_s16(complex_double_t x, const exponent_t x_exp, conv_error_e *error);
59 C_API complex_s32_t conv_complex_double_to_complex_s32(complex_double_t x, const exponent_t x_exp, conv_error_e *error);
60 C_API complex_s64_t conv_complex_double_to_complex_s64(complex_double_t x, const exponent_t x_exp, conv_error_e* error);
61 
62 
63 C_API void conv_vect_s16_to_double(double output[], const int16_t input[], const unsigned length, const exponent_t input_exp, conv_error_e *error);
64 C_API void conv_vect_s32_to_double(double output[], const int32_t input[], const unsigned length, const exponent_t input_exp, conv_error_e *error);
65 C_API void conv_vect_complex_s16_to_complex_double(complex_double_t output[], const complex_s16_t input[], const unsigned length, const exponent_t input_exp, conv_error_e *error);
66 C_API void conv_vect_complex_s32_to_complex_double(complex_double_t output[], const complex_s32_t input[], const unsigned length, const exponent_t input_exp, conv_error_e *error);
67 C_API void conv_vect_complex_s32_to_complex_double_v2(double out_real[], double out_imag[], const complex_s32_t input[], const unsigned length, const exponent_t input_exp, conv_error_e *error);
68 
69 
70 /*
71  * Float/Fixed comparision
72  */
73 C_API unsigned abs_diff_complex_s16(complex_s16_t B, const exponent_t B_exp, complex_double_t f, conv_error_e* error);
74 C_API unsigned abs_diff_complex_s32(complex_s32_t B, const exponent_t B_exp, complex_double_t f, conv_error_e* error);
75 C_API unsigned abs_diff_s8(int8_t B, const exponent_t B_exp, double f, conv_error_e* error);
76 C_API unsigned abs_diff_s16( int16_t B, const exponent_t B_exp, double f, conv_error_e* error);
77 C_API unsigned abs_diff_s32(int32_t B, const exponent_t B_exp, double f, conv_error_e* error);
78 C_API unsigned abs_diff_u8(uint8_t B, const exponent_t B_exp, double f, conv_error_e* error);
79 C_API unsigned abs_diff_u16(uint16_t B, const exponent_t B_exp, double f, conv_error_e* error);
80 C_API unsigned abs_diff_u32(uint32_t B, const exponent_t B_exp, double f, conv_error_e* error);
81 
82 
83 /*
84  * Float/Fixed vector comparision
85  */
86 C_API unsigned abs_diff_vect_complex_s16(complex_s16_t * B, const exponent_t B_exp, complex_double_t * f, unsigned length, conv_error_e* error);
87 C_API unsigned abs_diff_vect_complex_s32(complex_s32_t * B, const exponent_t B_exp, complex_double_t * f, unsigned length, conv_error_e* error);
88 C_API unsigned abs_diff_vect_s8( int8_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
89 C_API unsigned abs_diff_vect_s16( int16_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
90 C_API unsigned abs_diff_vect_s32( int32_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
91 C_API unsigned abs_diff_vect_u8(uint8_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
92 C_API unsigned abs_diff_vect_u16(uint16_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
93 C_API unsigned abs_diff_vect_u32(uint32_t * B, const exponent_t B_exp, double * f, unsigned length,conv_error_e* error);
94 
95 
96 #define TESTING_FLOAT_NUM_DIGITS 22
97 
98 #define PRINT_VAR(VAR, THING) do{ printf("%s = ", VAR); THING; } while(0)
99 
100 C_API void print_vect_complex_s16(complex_s16_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
101 C_API void print_vect_complex_s16_fft(complex_s16_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
102 C_API void print_vect_complex_s32(complex_s32_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
103 C_API void print_vect_complex_s32_fft(complex_s32_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
104 C_API void print_vect_complex_s32_raw(complex_s32_t * B, unsigned length);
105 C_API void print_vect_complex_s32_fft_raw(complex_s32_t * B, unsigned length);
106 C_API void print_vect_complex_double(complex_double_t * B, unsigned length, conv_error_e* error);
107 C_API void print_vect_complex_double_fft(complex_double_t * B, unsigned length, conv_error_e* error);
108 C_API void print_vect_s8(int8_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
109 C_API void print_vect_s16(int16_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
110 C_API void print_vect_s32(int32_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
111 C_API void print_vect_s64(int64_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
112 C_API void print_vect_u8(uint8_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
113 C_API void print_vect_u16(uint16_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
114 C_API void print_vect_u32(uint32_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
115 C_API void print_vect_u64(uint64_t * B, const exponent_t B_exp, unsigned length, conv_error_e* error);
116 C_API void print_vect_double(double * B, unsigned length, conv_error_e* error);
117 
118 #define PRINT_PLOT_DIFF_COMPLEX(A, B) \
119  do{ printf("[(plt.plot(np.real(qwer),label='real'),plt.plot(np.imag(qwer),label='imag')) for qwer in [\n"); \
120  A; printf(" - \n"); B; printf("]]\n"); } while(0)
121 
122 
123 // Get a (weakly) pseudo-random unsigned integer derived from the name of
124 // the containing function. This is intended to provide a unique random seed
125 // for each test case.
126 #define SEED_FROM_FUNC_NAME() get_seed(__func__, sizeof(__func__))
127 C_API unsigned get_seed(const char* str, const unsigned len);
int exponent_t
An exponent.
Definition: xs3_math_types.h:76
A complex number with a double-precision floating-point real part and a double-precision floating-poi...
Definition: xs3_math_types.h:409
A complex number with a 16-bit real part and 16-bit imaginary part.
Definition: xs3_math_types.h:60
A complex number with a 32-bit real part and 32-bit imaginary part.
Definition: xs3_math_types.h:49
A complex number with a 64-bit real part and 64-bit imaginary part.
Definition: xs3_math_types.h:38