annotate peck_test.c @ 2:3d08140650d8

cleanup
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Fri, 16 Sep 2011 13:02:34 +0200
parents 723f588b82ac
children 2d6c49fcafcb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
1 #include <stdlib.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
2 #include <stdio.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
3 #include <float.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
4
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
5 #include <peck_fft.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
6 #include <peck_fftr.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
7
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
8 void enable_runfast() {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
9 #ifdef __arm__
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
10 static const unsigned int x = 0x04086060;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
11 static const unsigned int y = 0x03000000;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
12 int r;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
13 asm volatile (
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
14 "fmrx %0, fpscr \n\t" //r0 = FPSCR
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
15 "and %0, %0, %1 \n\t" //r0 = r0 & 0x04086060
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
16 "orr %0, %0, %2 \n\t" //r0 = r0 | 0x03000000
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
17 "fmxr fpscr, %0 \n\t" //FPSCR = r0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
18 : "=r"(r)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
19 : "r"(x), "r"(y)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
20 );
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
21 #endif
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
22 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
23
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
24 int main(int argc, char *argv[]) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
25 unsigned int i, j;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
26 peck_fftr_cfg p, pi;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
27
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
28 enable_runfast();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
29
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
30 const unsigned int N = 256;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
31
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
32 peck_fft_scalar in[N];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
33 peck_fft_cpx out[N/2 + 1];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
34 peck_fft_scalar res[N];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
35
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
36 for (i = 0; i < N; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
37 in[i] = (i % 13) / 3;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
38 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
39
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
40 p = peck_fftr_alloc(N, 0, NULL, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
41 pi = peck_fftr_alloc(N, 1, NULL, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
42
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
43 for (j = 0; j < 10000; j++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
44 if (j == 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
45 for (i = 0; i < 8; i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
46 printf("%d: %f\n", i, in[i]);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
47 printf("----\n");
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
48 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
49
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
50 peck_fftr(p, in, out);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
51
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
52 if (j == 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
53 for (i = 0; i < 8; i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
54 printf("%d: %f %f\n", i, out[i].r, out[i].i);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
55 printf("----\n");
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
56 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
57
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
58 peck_fftri(pi, out, res);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
59
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
60 if (j == 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
61 for (i = 0; i < 8; i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
62 printf("%d: %f\n", i, res[i] / N);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
63 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
64 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
65 peck_fftr_free(p);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
66 peck_fftr_free(pi);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
67 peck_fft_cleanup();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
68
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
69 for (i = 0; i < N; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
70 if (fabs(in[i] - res[i]/N) > 0.00001) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
71 fprintf(stderr, "!!!! ERROR !!!! at %d\n", i);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
72 exit(EXIT_FAILURE);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
73 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
74 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
75
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
76 return EXIT_SUCCESS;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
77 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.