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
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
7
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
28 enable_runfast();
0
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++) {
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
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
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
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
46 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
47
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
48 p = peck_fftr_alloc(N, 0, NULL, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
49 pi = peck_fftr_alloc(N, 1, NULL, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
50
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
51 for (j = 0; j < 10000; j++) {
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++)
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
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_fftr(p, in, out);
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++)
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
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
63 printf("----\n");
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
64 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
65
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
66 peck_fftri(pi, out, res);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
67
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
68 if (j == 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
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
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
71 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
72 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
73 peck_fftr_free(p);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
74 peck_fftr_free(pi);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
75 peck_fft_cleanup();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
76
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
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
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
79 fprintf(stderr, "!!!! ERROR !!!! at %d\n", i);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
80 exit(EXIT_FAILURE);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
81 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
82 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
83
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
84 return EXIT_SUCCESS;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
85 }

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