aboutsummaryrefslogtreecommitdiffstats
path: root/utils/convolvetest/main.c
blob: ff88ba5fd40375515ba6112789ed328a6435c5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdio.h>
#include <string.h>
#include <osmocom/core/utils.h>
#include "../../Transceiver52M/common/convolve.h"

#define TESTVEC_LEN 1000
#define DO_INIT 1

float x_vect[TESTVEC_LEN];
float y_vect[TESTVEC_LEN];
float h_vect[TESTVEC_LEN];

float *x;
float *h;
float *y;

/* Generate some random values for testing */
void gen_floats(float *vect, int len)
{
	int i;
	for(i=0;i<len;i++) {
		vect[i] = (float)rand()/(float)(RAND_MAX);
	}
}

/* Reset testvectors */
static void reset_testvec(int seed)
{
	srand(seed);
	memset(x_vect,0,sizeof(x_vect));
	memset(y_vect,0,sizeof(y_vect));
	memset(h_vect,0,sizeof(h_vect));

	x=x_vect + TESTVEC_LEN/2;
	y=y_vect + TESTVEC_LEN/2;
	h=h_vect + TESTVEC_LEN/2;

	gen_floats(x_vect,TESTVEC_LEN);
	gen_floats(h_vect,TESTVEC_LEN);
}

/* Show float vector data cut and paste friendly */
static void dump_floats(float *vect, int len, char *name)
{
	int i;

	printf("float %s[] = {", name);
	for(i=0;i<len;i++) {

		printf("%f",vect[i]);

		if(i<len-1)
			printf(",");
	}
	printf("}\n");
}

/* Test complex convolution */
static void test_convolve_complex(int h_len)
{
	int x_len;
	int y_len;
	int start;
	int len;
	int step;
	int offset;

	x_len=34;
	y_len=26;
	start=8;
	len=26;
	step=1;
	offset=1;
	reset_testvec(0);
	dump_floats(x,x_len,"x");
	printf("\n");
	dump_floats(h,h_len,"h");
	printf("\n");
	convolve_complex(x, x_len, h, h_len, y, y_len, start, len, step, offset);
	dump_floats(y,y_len,"y");
	printf("\n");
}

/* Test real convolution */
static void test_convolve_real(int h_len)
{
	int x_len;
	int y_len;
	int start;
	int len;
	int step;
	int offset;

	x_len=34;
	y_len=26;
	start=8;
	len=26;
	step=1;
	offset=1;
	reset_testvec(0);
	dump_floats(x,x_len,"x");
	printf("\n");
	dump_floats(h,h_len,"h");
	printf("\n");
	convolve_real(x, x_len, h, h_len, y, y_len, start, len, step, offset);
	dump_floats(y,y_len,"y");
	printf("\n");
}

int main(void)
{
#if DO_INIT == 1
	convolve_init();
#endif

	printf("==== TEST COMPLEX BASE IMPLEMENTATION ====\n");
	test_convolve_complex(17);

	printf("==== TEST COMPLEX SSE3 IMPLEMENTATION: (h_len%%4=0) ====\n");
	test_convolve_complex(20);

	printf("==== TEST COMPLEX SSE3 IMPLEMENTATION: (h_len%%8=0) ====\n");
	test_convolve_complex(16);

	printf("\n");
	printf("\n");

	printf("==== TEST REAL BASE IMPLEMENTATION ====\n");
	test_convolve_real(17);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=4) ====\n");
	test_convolve_real(4);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=8) ====\n");
	test_convolve_real(8);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=12) ====\n");
	test_convolve_real(12);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=16) ====\n");
	test_convolve_real(16);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (hlen=20) ====\n");
	test_convolve_real(20);

	printf("==== TEST REAL SSE3 IMPLEMENTATION (h_len%%4=0) ====\n");
	test_convolve_real(24);

	return 0;
}