OpenCores
URL https://opencores.org/ocsvn/raytrac/raytrac/trunk

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [utils/] [memMaker.c] - Diff between revs 79 and 101

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 79 Rev 101
/*
/*
 *  memMaker.c
 *  memMaker.c
 *  memoryMaker
 *  memoryMaker
 *
 *
 *  Created by julian on 23/02/11.
 *  Created by julian on 23/02/11.
 *  GPL LICENSED
 *  GPL LICENSED
 *  The goal of this peace of code is to create a memory initialization file of random fixed point numbers
 *  The goal of this peace of code is to create a memory initialization file of random fixed point numbers
 *  in order to simulate RtEngine.
 *  in order to simulate RtEngine.
 *  Usage is
 *  Usage is
 */
 */
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <math.h>
#include <math.h>
#include <time.h>
#include <time.h>
#include <string.h>
#include <string.h>
 
 
#ifdef __MINGW32__
#ifdef __MINGW32__
#define random() ((((long int)rand())<<17)|rand())
#define random() ((((long int)rand())<<17)|rand())
#define srandom srand
#define srandom srand
#endif
#endif
 
 
 
 
char australia[]="DEPTH = %03d;\nWIDTH = %02d;\nADDRESS_RADIX=HEX;\nDATA_RADIX=HEX;\nCONTENT\nBEGIN\n\n\0";
char australia[]="DEPTH = %03d;\nWIDTH = %02d;\nADDRESS_RADIX=HEX;\nDATA_RADIX=HEX;\nCONTENT\nBEGIN\n\n\0";
char canada[]="END;\n\0";
char canada[]="END;\n\0";
struct {
struct {
        int depth;
        int depth;
        int width;
        int width;
        int dec;
        int dec;
 
 
        char *initialheader;
        char *initialheader;
        char *end;
        char *end;
        int R;
        int R;
 
 
        int offset;
        int offset;
 
        int addressoffset;
 
 
 
 
}memparam={0,0,0,australia,canada,0,1};
}memparam={0,0,0,australia,canada,0,1,0};
 
 
//mpx memparam={0,0,australia};
//mpx memparam={0,0,australia};
 
 
void optParser(int argc, char ** argv){
void optParser(int argc, char ** argv){
 
 
        char a=0;
        char a=0;
        int e=0,d=0,t=0,s=0,i=0;
        int e=0,d=0,t=0,s=0,i=0;
        /*memparam.initialheader=australia;
        /*memparam.initialheader=australia;
        memparam.width=0;
        memparam.width=0;
        memparam.depth=0;*/
        memparam.depth=0;*/
        while ((a=getopt(argc,argv,"o:t:e:d:Rr"))!=-1){
        while ((a=getopt(argc,argv,"a:o:t:e:d:Rr"))!=-1){
                switch(a){
                switch(a){
 
                        case 'a':
 
                                memparam.addressoffset=atoi(optarg);
 
                                break;
                        case 'o':
                        case 'o':
                                memparam.offset=atoi(optarg);
                                memparam.offset=atoi(optarg);
                                break;
                                break;
                        case 'R': //Raiz Cuadrada
                        case 'R': //Raiz Cuadrada
                                memparam.R=1;
                                memparam.R=1;
                                break;
                                break;
                        case 'r': //random
                        case 'r': //random
                                memparam.R=2;
                                memparam.R=2;
                                break;
                                break;
                        case 't':
                        case 't':
                                if (t){
                                if (t){
                                        fprintf (stdout, "error:Doble parametro t...\n");
                                        fprintf (stdout, "error:Doble parametro t...\n");
                                        exit(-1);
                                        exit(-1);
                                }
                                }
                                t++;
                                t++;
                                memparam.depth=atoi(optarg);
                                memparam.depth=atoi(optarg);
                                break;
                                break;
                        case 'e':
                        case 'e':
                                if (e){
                                if (e){
                                        fprintf (stdout, "error:Doble parametro e...\n");
                                        fprintf (stdout, "error:Doble parametro e...\n");
                                        exit(-1);
                                        exit(-1);
                                }
                                }
                                e++;
                                e++;
                                memparam.width+=atoi(optarg);
                                memparam.width+=atoi(optarg);
                                break;
                                break;
                        case 'd':
                        case 'd':
                                if (d){
                                if (d){
                                        fprintf (stdout,"error:Doble parametro d...\n");
                                        fprintf (stdout,"error:Doble parametro d...\n");
                                        exit(-1);
                                        exit(-1);
                                }
                                }
                                d++;
                                d++;
                                memparam.dec=atoi(optarg);
                                memparam.dec=atoi(optarg);
                                memparam.width+=memparam.dec;
                                memparam.width+=memparam.dec;
 
 
                                break;
                                break;
                        case '?':
                        case '?':
                                fprintf(stdout,"error: WTF! %c !?\n",optopt);
                                fprintf(stdout,"error: WTF! %c !?\n",optopt);
                                exit(-1);
                                exit(-1);
                                break;
                                break;
                }
                }
        }
        }
        if (!e || !d || !t){
        if (!e || !d || !t){
                fprintf(stdout,"uso: memMaker -t numeroDePosicionesDeMemoria -e numeroDeBitsParaLaRepresentacionEntera -d numeroDeBitsParaLaRepresentacionDecimal\n");
                fprintf(stdout,"uso: memMaker -t numeroDePosicionesDeMemoria -e numeroDeBitsParaLaRepresentacionEntera -d numeroDeBitsParaLaRepresentacionDecimal\n");
                exit(-1);
                exit(-1);
        }
        }
        if ((e+d)>31){
        if ((e+d)>31){
                fprintf(stdout,"enteros + decimales no puede ser mayor a 31 bits!\n");
                fprintf(stdout,"enteros + decimales no puede ser mayor a 31 bits!\n");
                exit(-1);
                exit(-1);
        }
        }
}
}
 
 
int hexreq(long int x){
int hexreq(long int x){
        return ((int)(log2(x)/4))+1;
        return ((int)(log2(x)/4))+1;
}
}
int f0inv(float x){
int f0inv(float x){
        int I;
        int I;
        float fI;
        float fI;
        fI=(1/x);
        fI=(1/x);
        //fprintf (stdout," %f %f ", x, fI);
        //fprintf (stdout," %f %f ", x, fI);
        fI*=pow(2,memparam.dec);
        fI*=pow(2,memparam.dec);
        I=fI;
        I=fI;
        I&=0x3ffff;
        I&=0x3ffff;
        return I;
        return I;
}
}
 
 
int f1sqrt(float x){
int f1sqrt(float x){
        int S;
        int S;
        float fS;
        float fS;
        fS=(sqrt(x)*pow(2,memparam.dec));
        fS=(sqrt(x)*pow(2,memparam.dec));
        S=fS;
        S=fS;
        S&=0x3ffff;
        S&=0x3ffff;
        return S;
        return S;
}
}
 
 
int f2random(float x){
int f2random(float x){
        int mask=pow(2,memparam.width+1)-1;
        int mask=pow(2,memparam.width+1)-1;
        return random()&mask;
        return random()&mask;
}
}
typedef int (*ff2i)(float);
typedef int (*ff2i)(float);
void generatenums(void){
void generatenums(void){
 
 
        int index;
        int index;
        unsigned long int factor;
        unsigned long int factor;
        float ffactor,epsilon;
        float ffactor,epsilon;
        char buff[1024],sign;
        char buff[1024],sign;
        ff2i xf[]={f0inv,f1sqrt,f2random};
        ff2i xf[]={f0inv,f1sqrt,f2random};
        int depthpfw=hexreq(memparam.depth);
        int depthpfw=hexreq(memparam.depth);
        int widthpfw=((int)(memparam.width/4))+(memparam.width%4?1:0);
        int widthpfw=((int)(memparam.width/4))+(memparam.width%4?1:0);
        srandom(time(0));
        srandom(time(0));
        epsilon=1/(float)memparam.depth;
        epsilon=1/(float)memparam.depth;
 
 
        fprintf(stdout,"-- epsilon: %f\n",epsilon);
        fprintf(stdout,"-- epsilon: %f\n",epsilon);
        for(index=0;index<memparam.depth ;index++){
        for(index=memparam.addressoffset;index<memparam.depth+memparam.addressoffset;index++){
                factor=xf[memparam.R](memparam.offset*(1+index*epsilon));
                factor=xf[memparam.R](memparam.offset*(1+(index-memparam.addressoffset)*epsilon));
                sign=memparam.R==2?((factor&(1<<memparam.width))?'-':'+'):'+';
                sign=memparam.R==2?((factor&(1<<memparam.width))?'-':'+'):'+';
                ffactor=(factor&(1<<memparam.width))?(factor^(int)(pow(2,memparam.width+1)-1))+1:factor;
                ffactor=(factor&(1<<memparam.width))?(factor^(int)(pow(2,memparam.width+1)-1))+1:factor;
                ffactor/=pow(2,memparam.dec);
                ffactor/=pow(2,memparam.dec);
                memset(buff,0,1024);
                memset(buff,0,1024);
                sprintf(buff,"%c0%dx : %c0%dx; -- FIXED => %x . %x (%d . %d) FLOAT %c%f\n",
                sprintf(buff,"%c0%dx : %c0%dx; -- FIXED => %x . %x (%d . %d) FLOAT %c%f\n",
                                '%',
                                '%',
                                depthpfw,
                                depthpfw,
                                '%',
                                '%',
                                widthpfw,
                                widthpfw,
                                factor>>memparam.dec,
                                factor>>memparam.dec,
                                factor&(int)(pow(2,memparam.dec)-1),
                                factor&(int)(pow(2,memparam.dec)-1),
                                factor>>memparam.dec,
                                factor>>memparam.dec,
                                factor&(int)(pow(2,memparam.dec)-1),
                                factor&(int)(pow(2,memparam.dec)-1),
                                sign,
                                sign,
                                ffactor);
                                ffactor);
                fprintf(stdout,buff,index,factor);
                fprintf(stdout,buff,index,factor);
        }
        }
 
 
}
}
void printmem(void){
void printmem(void){
        fprintf (stdout,memparam.initialheader,memparam.depth,memparam.width+1);
        fprintf (stdout,memparam.initialheader,memparam.depth,memparam.width+1);
        generatenums();
        generatenums();
        fprintf (stdout,memparam.end);
        fprintf (stdout,memparam.end);
 
 
}
}
 
 
int main (int argc, char **argv){
int main (int argc, char **argv){
 
 
        fprintf (stdout,"--RAND MAX: 0x%x\n", RAND_MAX);
        fprintf (stdout,"--RAND MAX: 0x%x\n", RAND_MAX);
#ifdef __MINGW32__
#ifdef __MINGW32__
        fprintf (stdout,"--MINGW32 VERSION\n");
        fprintf (stdout,"--MINGW32 VERSION\n");
#else 
#else 
        fprintf (stdout,"--UNIX BASED VERSION\n");
        fprintf (stdout,"--UNIX BASED VERSION\n");
#endif
#endif
 
 
        optParser(argc,argv);
        optParser(argc,argv);
        printmem();
        printmem();
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.