Mercurial > hg > peckfft
annotate peck_test.c @ 9:8726585681f6
backup
author | Peter Meerwald <p.meerwald@bct-electronic.com> |
---|---|
date | Wed, 21 Sep 2011 12:18:40 +0200 |
parents | 707be088ccc3 |
children | abdcde012978 |
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++) | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
70 printf("%d: %f\n", i, *(float*)&res[i] / 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++) { | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
0
diff
changeset
|
78 if (fabs(*(float*)&in[i] - *(float*)&res[i]/N) > 0.00001) { |
0 | 79 fprintf(stderr, "!!!! ERROR !!!! at %d\n", i); |
80 exit(EXIT_FAILURE); | |
81 } | |
82 } | |
83 | |
84 return EXIT_SUCCESS; | |
85 } |