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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [tb/] [msimtest.c] - Blame information for rev 78

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 57 jguarin200
/*
2 67 jguarin200
 *! \file msimtest.c
3
 *  \brief Archivo de cabecera de mismtest. Este programa tiene por proposito verificar que los resultados arrojados por la ejecución del testbench sean validos. Este programa está muy mal escrito. Por favor no lo tome como referencia de ninguna manera, esta HORRIBLEMENTE escrito!.
4 57 jguarin200
 *
5
 *  Created by julian on 21/03/11.
6
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
7
 *
8
 */
9
 
10
#include "msimtest.h"
11
 
12
#include <stdio.h>
13
#include <stdlib.h>
14
#include <string.h>
15
#include <ctype.h>
16
#include <unistd.h>
17
 
18
 
19
altrom_reg innuendo[RESULT_LINES];
20
 
21
FILE * fprom, *fpdec, *fpmul, *fpresults;
22
 
23
 
24
 
25
#define LB      '{'
26
#define RB      '}'
27
#define CM      ','
28
 
29
 
30
 
31
 
32
 
33
 
34
ssize_t getline(char ** lptr, size_t n, FILE * stream){
35
 
36
        int cnt;
37
        char *pc;
38
 
39
        if (feof(stream))
40
                return -1;
41
 
42
 
43
 
44
        //clear buffer  
45
        for (cnt=0,pc=lptr[0]; cnt<(int)n; cnt++)
46
                *((char*)(pc+cnt))=0;
47
 
48
        cnt=0;
49
 
50
        //till end of line
51
        do {
52
                //check if buffer size is appropiate
53
                if (cnt>=(int)n){
54
                        pc=(char*)realloc(lptr[0],cnt+1);
55
 
56
                        lptr[0]=pc;
57
                }
58
 
59
                //read one byte should not be any problem
60
                if (!fread(pc+cnt, 1, 1, stream))
61
                        return -1;
62
 
63
                if (pc[cnt]==0x0a || pc[cnt]==0x0 || feof(stream))
64
                        return cnt+1;
65
 
66
                cnt++;
67
 
68
        } while (1);
69
}
70 58 jguarin200
#define ONEPAD(x,s) x |= (1<<(s-1))&x?(((long long int)-1)<<s):0 
71 57 jguarin200
void onespadding(int s){
72
 
73
 
74
        int index0,index1;
75
        for (index0=0; index0<ROM_LINES; index0++)
76
                for (index1=0; index1<15; index1++)
77
                        ONEPAD(innuendo[index0].rom[index1],s);
78
 
79
}
80
 
81
 
82
#define SEARCHTOKEN(pc,t) while(*(pc++)!=t)
83
void vph(void*v,void*r,char e){
84
 
85
        //find {
86
        char ** pv=(char**)v;
87
        char * c=pv[0];
88 58 jguarin200
        long long int * Pv=r;
89 57 jguarin200
 
90
        //SEARCHTOKEN(c,s);
91
        *Pv=0;
92
        do{
93
                if (isxdigit(*c)){
94
                        *Pv<<=4;
95
                        (*Pv)+=((*c)>=0x30 && (*c)<0x40)?(*c)-0x30:(islower(*c)?(*c)-82:(*c)-55);
96
                }
97
 
98
        }SEARCHTOKEN(c,e);
99
 
100
        pv[0]=c;
101
 
102
}
103
void vpi(void*v,void*r,char e){
104
 
105
        char ** pv=(char**)v;
106
        char * c=pv[0];
107 58 jguarin200
        long long int * Pv=r;
108 57 jguarin200
 
109
        //SEARCHTOKEN(c,s);
110
        *Pv=0;
111
        do{
112
                if (isdigit(*c)){
113
                        *Pv*=10;
114
                        (*Pv)+=*c-0x30;
115
                }
116
 
117
        }SEARCHTOKEN(c,e);
118
        pv[0]=c;
119
}
120
#undef SEARCHTOKEN
121
 
122
#define ROM_DELAY 0
123
#define DEC_DELAY 1
124
#define MUL_DELAY 2
125
#define CROSS_DELAY 3
126
#define DOTP_DELAY 4
127
 
128
//parsing method model
129
vvp pmodelrom[] =       {vpi,vph,vpi,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,0x0};
130
vvp pmodeldec[] =       {vpi,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,vph,0x0};
131
vvp pmodelmult[]=       {vpi,vph,vph,vph,vph,vph,vph,0x0};
132
vvp pmodelresult[]=     {vpi,vph,vph,vph,vph,vph,0x0};
133
 
134
void * pmodel[]={pmodelrom,pmodeldec,pmodelmult,pmodelresult};
135
 
136
char edrom[]=   {RB,RB,RB,CM,CM,RB,CM,CM,RB,CM,CM,RB,CM,CM,RB};
137
char eddec[]=   {RB,CM,RB,CM,RB,CM,RB,CM,RB,CM,RB,CM,RB};
138
char edmult[]=  {RB,RB,RB,RB,RB,RB,RB};
139
char edresult[]=        {RB,CM,CM,RB,RB,RB};
140
 
141
char *enddelimiter[]= {edrom,eddec,edmult,edresult};
142
 
143
 
144
//slots
145
int psmodel[]={ROM_SLOTS,DEC_SLOTS,MUL_SLOTS,RESULT_SLOTS,0x0};
146
//lines
147
int plmodel[]={ROM_LINES, DEC_LINES, MULT_LINES, RESULT_LINES, 0x0};
148
 
149
//delay model
150
int dmodel[]={0,20,60,60,80,0x0};
151
 
152
 
153
typedef struct parce{
154
        vvp ** pfunc;
155
        int * smodel;
156
        int * lmodel;
157
        FILE * fp[4];
158
}xparser;
159
 
160
typedef xparser* pxparser;
161
 
162
pxparser xp;
163
 
164
void quickgetfile(int i){
165
 
166
        unsigned char padthai;
167
 
168
        long int * slot[]={&innuendo[0].rom[0],&innuendo[0].dec[0],&innuendo[0].mul[0],&innuendo[0].res[0]};
169
 
170 58 jguarin200
        long long int * xslot=slot[i];
171 57 jguarin200
        vvp * pfunc     = (vvp*)pmodel[i];
172
 
173
        int smodel      = psmodel[i];
174
        int lmodel      = plmodel[i];
175
        FILE * fp       = xp->fp[i];
176
 
177
 
178
        int index=0,index1,nread;
179
        char * b[1];
180
        char * c;
181
 
182
 
183
        long int * pv;
184
        *b=0x0;
185
        do{
186
 
187
                /*
188
                This function reads an entire line from stream, storing the text (including the newline and a terminating null character) in a buffer and storing the buffer address in *lineptr.
189
                Before calling getline, you should place in *lineptr the address of a buffer *n bytes long, allocated with malloc. If this buffer is long enough to hold the line, getline stores the line in this buffer.
190
                Otherwise, getline makes the buffer bigger using realloc, storing the new buffer address back in *lineptr and the increased size back in *n. See Unconstrained Allocation.
191
                If you set *lineptr to a null pointer, and *n to zero, before the call, then getline allocates the initial buffer for you by calling malloc.
192
                In either case, when getline returns, *lineptr is a char * which points to the text of the line.
193
                When getline is successful, it returns the number of characters read (including the newline, but not including the terminating null). This value enables you to distinguish null characters that are part of the line from the null character inserted as a terminator.
194
                This function is a GNU extension, but it is the recommended way to read lines from a stream. The alternative standard functions are unreliable.
195
                If an error occurs or end of file is reached without any bytes read, getline returns -1.
196
                */
197
 
198
                do {
199
                        if (*b)
200
                                free(*b);
201
                        *b=(char*)malloc(1);
202
                        if (!b)
203
                                exit(EXIT_FAILURE);
204
                        nread=getline(b,1,fp);
205
                        if (nread==-1)
206
                                exit(EXIT_FAILURE);
207
                        c=b[0];
208
 
209
                } while (*c=='#');
210
 
211
                for (index1=0;pfunc[index1];index1++){
212
                        pfunc[index1](&c,&(xslot[index1]),enddelimiter[i][index1]);
213
                        if (i==1 || i==3) {
214
                                padthai=(i==1)?18:32;
215
                                ONEPAD(xslot[index1],padthai);
216
                        }
217
 
218
                }
219 58 jguarin200
                xslot+=(sizeof(altrom_reg)/8);
220 57 jguarin200
 
221
 
222
 
223
                index++;
224
 
225
        }while (index<plmodel[i]);
226
        fclose(fp);
227
        return;
228
 
229
}
230 58 jguarin200
void vdisp(void){
231
 
232
        int index0,index1,op;
233
        long long int ms[6];
234
        for (index0=0; index0<1535; index0++) {
235
                op=innuendo[index0].rom[2];
236
                for (index1=0; index1<6; index1++) {
237
                        ms[index1]=innuendo[index0+1].dec[1+2*index1]*innuendo[index0+1].dec[2+2*index1];
238
                        ms[index1]>>=4;
239
 
240
 
241
                        fprintf(stdout, "T: %d I: %d\n",index1,innuendo[index0+3].mul[0]);
242
                        fprintf(stdout,"C: %llx S: %llx\n",ms[index1],(innuendo[index0+3].mul[index1+1]<<32)>>32);
243
                }
244
 
245
        }
246 57 jguarin200
 
247
 
248 58 jguarin200
 
249
}
250
 
251 57 jguarin200
int main (int argc, char ** argv){
252
 
253
        int index,openingerror;
254
 
255
        int size=sizeof(long int);
256
 
257
        xp=(pxparser)malloc(sizeof(xparser));
258
 
259
        //Open files
260
        for (index=1,openingerror=0;index>0 && index<5;){
261
                if (!openingerror) {
262
                        xp->fp[index-1]=fopen(argv[index],"r");
263
                        if (!(xp->fp[index-1])) {
264
                                openingerror=1;
265
                                index--;
266
                        }
267
                        else
268
                                index++;
269
 
270
                }
271
                else
272
                        fclose(xp->fp[--index]);
273
 
274
        }
275
 
276
        if (openingerror){
277
                fprintf(stdout,"error: no se encontro(aron) el(los) archivo(s) con la informacion\n");
278
                return -1;
279
        }
280
 
281
        memset(innuendo,0,sizeof(altrom_reg)*RESULT_LINES);
282
 
283
 
284
 
285
 
286
        quickgetfile(0);
287
        quickgetfile(1);
288
        quickgetfile(2);
289
        quickgetfile(3);
290 58 jguarin200
        vdisp();
291 57 jguarin200
        onespadding(18);
292
 
293
        return 1;
294
}
295
 
296
 
297
 
298
 
299
 
300
 
301
 

powered by: WebSVN 2.1.0

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