summaryrefslogtreecommitdiff
path: root/plugins/supereq/shibatch_rdft.c
blob: db453eb846b2b624de8e17d158f66bcf896cac25 (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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>

#include "SIMDBase.h"
#include "DFT.h"

#define TYPE SIMDBase_TYPE_FLOAT

void rfft(int n,int isign,float *x) {
    static DFT *p = NULL;
    static float *buf = NULL;
    static int ipsize = 0;
    static int mode = 0;
    static int veclen = 0;
    int newipsize;
    if (n == 0) {
        if (buf) {
            SIMDBase_alignedFree (buf);
            buf = NULL;
        }
        if (p) {
            DFT_dispose(p, mode);
            p = NULL;
        }
        return;
    }
    int nn = n;
    n = 1<<n;
    newipsize = n;
    if (newipsize != ipsize) {
        ipsize = newipsize;

        if (buf) {
            SIMDBase_alignedFree (buf);
            buf = NULL;
        }

        if (p) {
            DFT_dispose(p, mode);
            p = NULL;
        }

        buf = SIMDBase_alignedMalloc (n * sizeof (float));

        mode = SIMDBase_chooseBestMode(TYPE);
        veclen = SIMDBase_getModeParamInt(SIMDBase_PARAMID_VECTOR_LEN, mode);
        int sizeOfVect = SIMDBase_getModeParamInt(SIMDBase_PARAMID_SIZE_OF_VECT, mode);
        printf ("n: %d, veclen: %d, sizeOfVect: %d\n", n, veclen, sizeOfVect);
        p = DFT_init(mode, n/veclen, DFT_FLAG_REAL);
    }

    // store in simd order
    int asize = n / veclen;
    int i, j;
    for(j=0;j<veclen;j++) {
        for (i = 0; i < asize; i++) {
            buf[i * veclen + j] = x[j * asize + i];
        }
    }

    DFT_execute(p, mode, buf, isign);

#define THRES 1e-3
    for(j=0;j<veclen;j++) {
        for (i = 0; i < asize; i++) {
            x[j * asize + i] = buf[i * veclen + j];
        }
    }
}