Philipp Maier | dfe0aef | 2017-03-16 18:43:33 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <osmocom/core/utils.h> |
| 4 | #include "../../Transceiver52M/common/convolve.h" |
| 5 | |
| 6 | #define TESTVEC_LEN 1000 |
| 7 | #define DO_INIT 1 |
| 8 | |
| 9 | float x_vect[TESTVEC_LEN]; |
| 10 | float y_vect[TESTVEC_LEN]; |
| 11 | float h_vect[TESTVEC_LEN]; |
| 12 | |
| 13 | float *x; |
| 14 | float *h; |
| 15 | float *y; |
| 16 | |
| 17 | /* Generate some random values for testing */ |
| 18 | void gen_floats(float *vect, int len) |
| 19 | { |
| 20 | int i; |
| 21 | for(i=0;i<len;i++) { |
| 22 | vect[i] = (float)rand()/(float)(RAND_MAX); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /* Reset testvectors */ |
| 27 | static void reset_testvec(int seed) |
| 28 | { |
| 29 | srand(seed); |
| 30 | memset(x_vect,0,sizeof(x_vect)); |
| 31 | memset(y_vect,0,sizeof(y_vect)); |
| 32 | memset(h_vect,0,sizeof(h_vect)); |
| 33 | |
| 34 | x=x_vect + TESTVEC_LEN/2; |
| 35 | y=y_vect + TESTVEC_LEN/2; |
| 36 | h=h_vect + TESTVEC_LEN/2; |
| 37 | |
| 38 | gen_floats(x_vect,TESTVEC_LEN); |
| 39 | gen_floats(h_vect,TESTVEC_LEN); |
| 40 | } |
| 41 | |
| 42 | /* Show float vector data cut and paste friendly */ |
| 43 | static void dump_floats(float *vect, int len, char *name) |
| 44 | { |
| 45 | int i; |
| 46 | |
| 47 | printf("float %s[] = {", name); |
| 48 | for(i=0;i<len;i++) { |
| 49 | |
| 50 | printf("%f",vect[i]); |
| 51 | |
| 52 | if(i<len-1) |
| 53 | printf(","); |
| 54 | } |
| 55 | printf("}\n"); |
| 56 | } |
| 57 | |
| 58 | /* Test complex convolution */ |
| 59 | static void test_convolve_complex(int h_len) |
| 60 | { |
| 61 | int x_len; |
| 62 | int y_len; |
| 63 | int start; |
| 64 | int len; |
| 65 | int step; |
| 66 | int offset; |
| 67 | |
| 68 | x_len=34; |
| 69 | y_len=26; |
| 70 | start=8; |
| 71 | len=26; |
| 72 | step=1; |
| 73 | offset=1; |
| 74 | reset_testvec(0); |
| 75 | dump_floats(x,x_len,"x"); |
| 76 | printf("\n"); |
| 77 | dump_floats(h,h_len,"h"); |
| 78 | printf("\n"); |
| 79 | convolve_complex(x, x_len, h, h_len, y, y_len, start, len, step, offset); |
| 80 | dump_floats(y,y_len,"y"); |
| 81 | printf("\n"); |
| 82 | } |
| 83 | |
| 84 | /* Test real convolution */ |
| 85 | static void test_convolve_real(int h_len) |
| 86 | { |
| 87 | int x_len; |
| 88 | int y_len; |
| 89 | int start; |
| 90 | int len; |
| 91 | int step; |
| 92 | int offset; |
| 93 | |
| 94 | x_len=34; |
| 95 | y_len=26; |
| 96 | start=8; |
| 97 | len=26; |
| 98 | step=1; |
| 99 | offset=1; |
| 100 | reset_testvec(0); |
| 101 | dump_floats(x,x_len,"x"); |
| 102 | printf("\n"); |
| 103 | dump_floats(h,h_len,"h"); |
| 104 | printf("\n"); |
| 105 | convolve_real(x, x_len, h, h_len, y, y_len, start, len, step, offset); |
| 106 | dump_floats(y,y_len,"y"); |
| 107 | printf("\n"); |
| 108 | } |
| 109 | |
| 110 | int main(void) |
| 111 | { |
| 112 | #if DO_INIT == 1 |
| 113 | convolve_init(); |
| 114 | #endif |
| 115 | |
| 116 | printf("==== TEST COMPLEX BASE IMPLEMENTATION ====\n"); |
| 117 | test_convolve_complex(17); |
| 118 | |
| 119 | printf("==== TEST COMPLEX SSE3 IMPLEMENTATION: (h_len%%4=0) ====\n"); |
| 120 | test_convolve_complex(20); |
| 121 | |
| 122 | printf("==== TEST COMPLEX SSE3 IMPLEMENTATION: (h_len%%8=0) ====\n"); |
| 123 | test_convolve_complex(16); |
| 124 | |
| 125 | printf("\n"); |
| 126 | printf("\n"); |
| 127 | |
| 128 | printf("==== TEST REAL BASE IMPLEMENTATION ====\n"); |
| 129 | test_convolve_real(17); |
| 130 | |
| 131 | printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=4) ====\n"); |
| 132 | test_convolve_real(4); |
| 133 | |
| 134 | printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=8) ====\n"); |
| 135 | test_convolve_real(8); |
| 136 | |
| 137 | printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=12) ====\n"); |
| 138 | test_convolve_real(12); |
| 139 | |
| 140 | printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=16) ====\n"); |
| 141 | test_convolve_real(16); |
| 142 | |
| 143 | printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=20) ====\n"); |
| 144 | test_convolve_real(20); |
| 145 | |
| 146 | printf("==== TEST REAL SSE3 IMPLEMENTATION (h_len%%4=0) ====\n"); |
| 147 | test_convolve_real(24); |
| 148 | |
| 149 | return 0; |
| 150 | } |