Mercurial > hg > peckfft
annotate peck_test.c @ 11:abdcde012978
backup
author | Peter Meerwald <p.meerwald@bct-electronic.com> |
---|---|
date | Thu, 22 Sep 2011 15:19:18 +0200 |
parents | 707be088ccc3 |
children |
rev | line source |
---|---|
0 | 1 #include <stdlib.h> |
2 #include <stdio.h> | |
3 #include <float.h> | |
4 | |
5 #include <peck_fft.h> | |
6 #include <peck_fftr.h> | |
7 | |
8 void enable_runfast() { | |
9 #ifdef __arm__ | |
10 static const unsigned int x = 0x04086060; | |
11 static const unsigned int y = 0x03000000; | |
12 int r; | |
13 asm volatile ( | |
14 "fmrx %0, fpscr \n\t" //r0 = FPSCR | |
15 "and %0, %0, %1 \n\t" //r0 = r0 & 0x04086060 | |
16 "orr %0, %0, %2 \n\t" //r0 = r0 | 0x03000000 | |
17 "fmxr fpscr, %0 \n\t" //FPSCR = r0 | |
18 : "=r"(r) | |
19 : "r"(x), "r"(y) | |
20 ); | |
21 #endif | |
22 } | |
23 | |
24 int main(int argc, char *argv[]) { | |
25 unsigned int i, j; | |
26 peck_fftr_cfg p, pi; | |
27 | |
7 | 28 enable_runfast(); |
0 | 29 |
30 const unsigned int N = 256; | |
31 | |
32 peck_fft_scalar in[N]; | |
33 peck_fft_cpx out[N/2 + 1]; | |
34 peck_fft_scalar res[N]; | |
35 | |
36 for (i = 0; i < N; i++) { | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
37 #if USE_SIMD == SIMD_SSE2 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
38 in[i] = _mm_set1_ps((i % 13) / 3); |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
39 #elif USE_SIMD == SIMD_NEON4 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
40 in[i] = vdupq_n_f32((i % 13) / 3); |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
41 #elif USE_SIMD == SIMD_NEON2 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
42 in[i] = vdup_n_f32((i % 13) / 3); |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
43 #else |
0 | 44 in[i] = (i % 13) / 3; |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
45 #endif |
0 | 46 } |
47 | |
48 p = peck_fftr_alloc(N, 0, NULL, NULL); | |
49 pi = peck_fftr_alloc(N, 1, NULL, NULL); | |
50 | |
51 for (j = 0; j < 10000; j++) { | |
52 if (j == 0) { | |
53 for (i = 0; i < 8; i++) | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
54 printf("%d: %f\n", i, *(float*)&in[i]); |
0 | 55 printf("----\n"); |
56 } | |
57 | |
58 peck_fftr(p, in, out); | |
59 | |
60 if (j == 0) { | |
61 for (i = 0; i < 8; i++) | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
62 printf("%d: %f %f\n", i, *(float*)&out[i].r, *(float*)&out[i].i); |
0 | 63 printf("----\n"); |
64 } | |
65 | |
66 peck_fftri(pi, out, res); | |
67 | |
68 if (j == 0) { | |
69 for (i = 0; i < 8; i++) | |
11 | 70 printf("%d: %f %f\n", i, ((float*)&res[i])[0] / N, ((float*)&res[i])[1] / N); |
0 | 71 } |
72 } | |
73 peck_fftr_free(p); | |
74 peck_fftr_free(pi); | |
75 peck_fft_cleanup(); | |
76 | |
77 for (i = 0; i < N; i++) { | |
11 | 78 if (fabs(((float*)&in[i])[0] - ((float*)&res[i])[0]/N) > 0.00001) { |
79 fprintf(stderr, "!!!! ERROR0 !!!! at %d\n", i); | |
80 exit(EXIT_FAILURE); | |
81 } | |
82 if (fabs(((float*)&in[i])[1] - ((float*)&res[i])[1]/N) > 0.00001) { | |
83 fprintf(stderr, "!!!! ERROR1 !!!! at %d\n", i); | |
0 | 84 exit(EXIT_FAILURE); |
85 } | |
86 } | |
87 | |
88 return EXIT_SUCCESS; | |
89 } |