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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [cpu/] [dlx/] [execute.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cvs
/* execute.c -- DLX dependent simulation
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Most of the DLX simulation is done in this file. */
21
 
22
#include <stdlib.h>
23
#include <stdio.h>
24
#include <string.h>
25
 
26
#include "arch.h"
27
 
28
#include "branch_predict.h"
29
#include "abstract.h"
30
#include "parse.h"
31
#include "trace.h"
32
#include "execute.h"
33
#include "stats.h"
34
 
35
/* General purpose registers. */
36
machword reg[MAX_GPRS];
37
 
38
/* Instruction queue */
39
struct iqueue_entry iqueue[20];
40
 
41
/* Benchmark multi issue execution */
42
int multissue[20];
43
int supercycles;
44
 
45 6 lampret
/* Load and store stalls */
46
int loadcycles, storecycles;
47
 
48
/* Result forwarding stall cycles */
49
int forwardingcycles;
50
 
51 2 cvs
/* Completition queue */
52
struct icomplet_entry icomplet[20];
53
 
54
/* Program counter */
55
unsigned long pc;
56
 
57
/* Temporary program counter */
58
unsigned long pctemp;
59
 
60
/* Cycles counts fetch stages */
61
int cycles;
62
 
63
/* Implementation specific.
64
   Get an actual value of a specific register. */
65
 
66
machword eval_reg(char *regstr)
67
{
68
        int regno;
69
 
70
        regno = atoi(regstr + 1);
71
 
72
        if (regno < MAX_GPRS)
73
                return reg[regno];
74
        else {
75 997 markom
                PRINTF("\nABORT: read out of registers\n");
76 2 cvs
                cont_run = 0;
77
                return 0;
78
        }
79
}
80
 
81
/* Implementation specific.
82
   Set a specific register with value. */
83
 
84
void set_reg32(char *regstr, unsigned long value)
85
{
86
        int regno;
87
 
88
        regno = atoi(regstr + 1);
89
 
90
        if (regno == 0)          /* gpr0 is always zero */
91
                value = 0;
92
 
93
        if (regno < MAX_GPRS)
94
                reg[regno] = value;
95
        else {
96 997 markom
                PRINTF("\nABORT: write out of registers\n");
97 2 cvs
                cont_run = 0;
98
        }
99
 
100
        return;
101
}
102
 
103
/* Does srcoperand depend on computation of dstoperand? Return
104
   non-zero if yes.
105
 
106
 Cycle t                 Cycle t+1
107
dst: irrelevant         src: immediate                  always 0
108
dst: reg1 direct        src: reg2 direct                0 if reg1 != reg2
109
dst: reg1 disp          src: reg2 direct                always 0
110
dst: reg1 direct        src: reg2 disp                  0 if reg1 != reg2
111
dst: reg1 disp          src: reg2 disp                  always 1 (store must
112
                                                        finish before load)
113
*/
114
 
115
int depend_operands(char *dstoperand, char *srcoperand)
116
{
117
        char dst[OPERANDNAME_LEN];
118
        char src[OPERANDNAME_LEN];
119
 
120
        if (!srcoperand)
121
                return 0;
122
 
123
        if (!dstoperand)
124
                return 0;
125
 
126
        strcpy(dst, dstoperand);
127
        strcpy(src, srcoperand);
128
 
129
        if (*src == '#')                /* immediate */
130
                return 0;
131
        else
132
        if (!strstr(src, "("))
133
                if (*src == 'r') {      /* src: reg direct */
134
                        if (!strstr(dst, "("))
135
                                if (*dst == 'r')
136
                                        if (strcmp(dst, src) == 0)
137
                                                return 1; /* dst: reg direct */
138
                                        else
139
                                                return 0; /* dst: reg direct */
140
                                else
141
                                        return 0; /* dst: addr */
142
                        else
143
                                return 0; /* dst: reg disp */
144
                } else
145
                        return 0;        /* src: addr */
146
        else {                          /* src: register disp */
147
                char *regstr;
148
 
149
                regstr = strstr(src, "(r") + 1; /* regstr == "rXX)" */
150
                *strstr(regstr, ")") = '\0';            /* regstr == "rXX" */
151
 
152
                if (!strstr(dst, "("))
153
                        if (*dst == 'r')
154
                                if (strcmp(dst, regstr) == 0)
155
                                        return 1; /* dst: reg direct */
156
                                else
157
                                        return 0; /* dst: reg direct */
158
                        else
159
                                return 0; /* dst: addr */
160
                else
161
                        return 1; /* dst: reg disp */
162
        }
163
 
164
        return 0;
165
}
166
 
167
/* Implementation specific.
168
   Get an actual value represented by operand (register direct, register
169
   indirect (with displacement), immediate etc.).
170
 
171
   #n           - immediate n
172
   rXX          - register direct
173
   XX           - relative or absolute address (labels)
174
   n(XX)        - register indirect (with displacement) */
175
 
176 123 markom
machword eval_operand(char *srcoperand,int* breakpoint)
177 2 cvs
{
178
        char operand[OPERANDNAME_LEN];
179
 
180
        strcpy(operand, srcoperand);
181
 
182
        if (*operand == '#')            /* immediate */
183
                return strtoul(&operand[1], NULL, 0);
184
        else
185
        if (!strstr(operand, "("))      /* not indirect but ...*/
186
                if (*operand == 'r')    /* ... register direct */
187
                        return eval_reg(operand);
188
 
189
                else                    /* ... rel. or abs. address */
190
                        return eval_label(operand);
191
        else {                          /* register indirect */
192
                int disp;               /* with possible displacement */
193
                char *regstr;
194
                unsigned int memaddr;
195
 
196
                disp = atoi(operand);   /* operand == "nn(rXX)" */
197
                regstr = strstr(operand, "(r") + 1;     /* regstr == "rXX)" */
198
                *strstr(regstr, ")") = '\0';            /* regstr == "rXX" */
199
                memaddr = eval_reg(regstr) + disp;
200
 
201 123 markom
                return eval_mem32(memaddr,breakpoint);
202 2 cvs
        }
203
 
204
        return 0;
205
}
206
 
207
/* Implementation specific.
208
   Set destination operand (register direct, register indirect
209
   (with displacement) with value. */
210
 
211 123 markom
void set_operand(char *dstoperand, unsigned long value,int* breakpoint)
212 2 cvs
{
213
        char operand[OPERANDNAME_LEN];
214
 
215
        strcpy(operand, dstoperand);
216
 
217
        if (*operand == '#')            /* immediate */
218 997 markom
                PRINTF("INTERNAL ERROR: Can't set immediate operand.\n");
219 2 cvs
        else
220
        if (!strstr(operand, "("))      /* not indirect but ...*/
221
                if (*operand == 'r')    /* ... register direct */
222
                        set_reg32(operand, value);
223
                else                    /* ... rel. or abs. address */
224 997 markom
                        PRINTF("INTERNAL ERROR: Can't set addr operand.\n");
225 2 cvs
        else {                          /* register indirect */
226
                int disp;               /* with possible displacement */
227
                char *regstr;
228
                unsigned int memaddr;
229
 
230
                disp = atoi(operand);   /* operand == "nn(rXX)" */
231
                regstr = strstr(operand, "(r") + 1;     /* regstr == "rXX)" */
232
                *strstr(regstr, ")") = '\0';            /* regstr == "rXX" */
233
                memaddr = eval_reg(regstr) + disp;
234
 
235 123 markom
                set_mem32(memaddr, value, breakpoint);
236 2 cvs
        }
237
 
238
        return;
239
}
240
 
241
void reset()
242
{
243
        cycles = 0;
244
        supercycles = 0;
245 6 lampret
        loadcycles = 0;
246
        storecycles = 0;
247
        forwardingcycles = 0;
248 2 cvs
        memset(reg, 0, sizeof(reg));
249
        memset(iqueue, 0, sizeof(iqueue));
250
        memset(icomplet, 0, sizeof(icomplet));
251
        pctemp = eval_label("_main");
252
        pc = pctemp;
253
        set_reg32(STACK_REG , MEMORY_LEN - STACK_SIZE);
254
}
255
 
256
void fetch()
257
{
258
        /* Cycles after reset. */
259
        cycles++;
260
 
261 6 lampret
        /* Simulate instruction cache */
262
        ic_simulate(pc);
263
 
264 2 cvs
        /* Fetch instruction. */
265 30 lampret
        strcpy(iqueue[0].insn, mem[pc].insn->insn);
266
        strcpy(iqueue[0].op1, mem[pc].insn->op1);
267
        strcpy(iqueue[0].op2, mem[pc].insn->op2);
268
        strcpy(iqueue[0].op3, mem[pc].insn->op3);
269 2 cvs
        iqueue[0].insn_addr = pc;
270
        iqueue[0].dependdst = NULL;
271
        iqueue[0].dependsrc1 = NULL;
272
        iqueue[0].dependsrc2 = NULL;
273
 
274
        /* Increment program counter. */
275
        pc = pctemp;
276
        pctemp += 4;
277
 
278
        /* Check for breakpoint. */
279
        if (mem[pc].brk)
280
                cont_run = 0;    /* Breakpoint set. */
281
 
282
        return;
283
}
284
 
285
void decode(struct iqueue_entry *cur)
286
{
287 123 markom
  int breakpoint = 0;
288 2 cvs
 
289
        cur->dependdst = cur->op1;
290
        cur->dependsrc1 = cur->op2;     /* for calculating register */
291
        cur->dependsrc2 = cur->op3;     /* dependency */
292
 
293
        cur->func_unit = unknown;
294
 
295
        if (strcmp(cur->insn, "sw") == 0) {
296
                cur->func_unit = store;
297 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint),&breakpoint);
298 2 cvs
        } else
299
        if (strcmp(cur->insn, "sb") == 0) {
300
                cur->func_unit = store;
301 123 markom
                set_operand(cur->op1, (eval_operand(cur->op2,&breakpoint) << 24) + (eval_operand(cur->op1,&breakpoint) & 0xffffff),&breakpoint);
302 2 cvs
        } else
303
        if (strcmp(cur->insn, "sh") == 0) {
304
                cur->func_unit = store;
305 123 markom
                set_operand(cur->op1, (eval_operand(cur->op2,&breakpoint) << 16) + (eval_operand(cur->op1,&breakpoint) & 0xffff),&breakpoint);
306 2 cvs
        } else
307
        if (strcmp(cur->insn, "lw") == 0) {
308
                cur->func_unit = load;
309 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint),&breakpoint);
310 2 cvs
        } else
311
        if (strcmp(cur->insn, "lb") == 0) {
312 123 markom
                signed char temp = (eval_operand(cur->op2,&breakpoint) >> 24);
313 2 cvs
                cur->func_unit = load;
314 123 markom
                set_operand(cur->op1, temp,&breakpoint);
315 2 cvs
        } else
316
        if (strcmp(cur->insn, "lbu") == 0) {
317 123 markom
                unsigned char temp = (eval_operand(cur->op2,&breakpoint) >> 24);
318 2 cvs
                cur->func_unit = load;
319 123 markom
                set_operand(cur->op1, temp,&breakpoint);
320 2 cvs
        } else
321
        if (strcmp(cur->insn, "lh") == 0) {
322 123 markom
                signed short temp = (eval_operand(cur->op2,&breakpoint) >> 16);
323 2 cvs
                cur->func_unit = load;
324 123 markom
                set_operand(cur->op1, temp,&breakpoint);
325 2 cvs
        } else
326
        if (strcmp(cur->insn, "lhu") == 0) {
327 123 markom
                unsigned short temp = (eval_operand(cur->op2,&breakpoint) >> 16);
328 2 cvs
                cur->func_unit = load;
329 123 markom
                set_operand(cur->op1, temp,&breakpoint);
330 2 cvs
        } else
331
        if (strcmp(cur->insn, "lwi") == 0) {
332
                cur->func_unit = movimm;
333 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint),&breakpoint);
334 2 cvs
        } else
335
        if (strcmp(cur->insn, "lhi") == 0) {
336
                cur->func_unit = movimm;
337 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) << 16,&breakpoint);
338 2 cvs
        } else
339
        if (strcmp(cur->insn, "and") == 0) {
340
                cur->func_unit = arith;
341 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) & eval_operand(cur->op3,&breakpoint),&breakpoint);
342 2 cvs
        } else
343
        if (strcmp(cur->insn, "andi") == 0) {
344
                cur->func_unit = arith;
345 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) & eval_operand(cur->op3,&breakpoint),&breakpoint);
346 2 cvs
        } else
347
        if (strcmp(cur->insn, "or") == 0) {
348
                cur->func_unit = arith;
349 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) | eval_operand(cur->op3,&breakpoint),&breakpoint);
350 2 cvs
        } else
351
        if (strcmp(cur->insn, "ori") == 0) {
352
                cur->func_unit = arith;
353 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) | eval_operand(cur->op3,&breakpoint),&breakpoint);
354 2 cvs
        } else
355
        if (strcmp(cur->insn, "xor") == 0) {
356
                cur->func_unit = arith;
357 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) ^ eval_operand(cur->op3,&breakpoint),&breakpoint);
358 2 cvs
        } else
359
        if (strcmp(cur->insn, "add") == 0) {
360
                signed long temp3, temp2, temp1;
361
                signed char temp4;
362
 
363
                cur->func_unit = arith;
364 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
365
                temp2 = eval_operand(cur->op2,&breakpoint);
366 2 cvs
                temp1 = temp2 + temp3;
367 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
368 2 cvs
 
369
                temp4 = temp1;
370
                if (temp4 == temp1)
371
                        mstats.byteadd++;
372
        } else
373
        if (strcmp(cur->insn, "addi") == 0) {
374
                signed long temp3, temp2, temp1;
375
                signed char temp4;
376
 
377
                cur->func_unit = arith;
378 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
379
                temp2 = eval_operand(cur->op2,&breakpoint);
380 2 cvs
                temp1 = temp2 + temp3;
381 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
382 2 cvs
 
383
                temp4 = temp1;
384
                if (temp4 == temp1)
385
                        mstats.byteadd++;
386
        } else
387
        if (strcmp(cur->insn, "addui") == 0) {
388
                unsigned long temp3, temp2, temp1;
389
                unsigned char temp4;
390
 
391
                cur->func_unit = arith;
392 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
393
                temp2 = eval_operand(cur->op2,&breakpoint);
394 2 cvs
                temp1 = temp2 + temp3;
395 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
396 2 cvs
 
397
                temp4 = temp1;
398
                if (temp4 == temp1)
399
                        mstats.byteadd++;
400
        } else
401
        if (strcmp(cur->insn, "sub") == 0) {
402
                signed long temp3, temp2, temp1;
403
 
404
                cur->func_unit = arith;
405 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
406
                temp2 = eval_operand(cur->op2,&breakpoint);
407 2 cvs
                temp1 = temp2 - temp3;
408 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
409 2 cvs
        } else
410
        if (strcmp(cur->insn, "subui") == 0) {
411
                unsigned long temp3, temp2, temp1;
412
 
413
                cur->func_unit = arith;
414 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
415
                temp2 = eval_operand(cur->op2,&breakpoint);
416 2 cvs
                temp1 = temp2 - temp3;
417 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
418 2 cvs
        } else
419
        if (strcmp(cur->insn, "subi") == 0) {
420
                signed long temp3, temp2, temp1;
421
 
422
                cur->func_unit = arith;
423 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
424
                temp2 = eval_operand(cur->op2,&breakpoint);
425 2 cvs
                temp1 = temp2 - temp3;
426 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
427 2 cvs
        } else
428
        if (strcmp(cur->insn, "mul") == 0) {
429
                signed long temp3, temp2, temp1;
430
 
431
                cur->func_unit = arith;
432 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
433
                temp2 = eval_operand(cur->op2,&breakpoint);
434 2 cvs
                temp1 = temp2 * temp3;
435 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
436 2 cvs
        } else
437
        if (strcmp(cur->insn, "div") == 0) {
438
                signed long temp3, temp2, temp1;
439
 
440
                cur->func_unit = arith;
441 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
442
                temp2 = eval_operand(cur->op2,&breakpoint);
443 2 cvs
                temp1 = temp2 / temp3;
444 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
445 2 cvs
        } else
446
        if (strcmp(cur->insn, "divu") == 0) {
447
                unsigned long temp3, temp2, temp1;
448
 
449
                cur->func_unit = arith;
450 123 markom
                temp3 = eval_operand(cur->op3,&breakpoint);
451
                temp2 = eval_operand(cur->op2,&breakpoint);
452 2 cvs
                temp1 = temp2 / temp3;
453 123 markom
                set_operand(cur->op1, temp1,&breakpoint);
454 2 cvs
        } else
455
        if (strcmp(cur->insn, "slli") == 0) {
456
                cur->func_unit = shift;
457 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) << eval_operand(cur->op3,&breakpoint),&breakpoint);
458 2 cvs
        } else
459
        if (strcmp(cur->insn, "sll") == 0) {
460
                cur->func_unit = shift;
461 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) << eval_operand(cur->op3,&breakpoint),&breakpoint);
462 2 cvs
        } else
463
        if (strcmp(cur->insn, "srl") == 0) {
464
                cur->func_unit = shift;
465 123 markom
                set_operand(cur->op1, eval_operand(cur->op2,&breakpoint) >> eval_operand(cur->op3,&breakpoint),&breakpoint);
466 2 cvs
        } else
467
        if (strcmp(cur->insn, "srai") == 0) {
468
                cur->func_unit = shift;
469 123 markom
                set_operand(cur->op1, (signed)eval_operand(cur->op2,&breakpoint) / (1 << eval_operand(cur->op3,&breakpoint)),&breakpoint);
470 2 cvs
        } else
471
        if (strcmp(cur->insn, "sra") == 0) {
472
                cur->func_unit = shift;
473 123 markom
                set_operand(cur->op1, (signed)eval_operand(cur->op2,&breakpoint) / (1 << eval_operand(cur->op3,&breakpoint)),&breakpoint);
474 2 cvs
        } else
475
        if (strcmp(cur->insn, "jal") == 0) {
476
                cur->func_unit = jump;
477 123 markom
                pctemp = eval_operand(cur->op1,&breakpoint);
478 2 cvs
                set_reg32(LINK_REG, pc + 4);
479
        } else
480
        if (strcmp(cur->insn, "jr") == 0) {
481
                cur->func_unit = jump;
482
                cur->dependsrc1 = cur->op1;
483 123 markom
                pctemp = eval_operand(cur->op1,&breakpoint);
484 2 cvs
        } else
485
        if (strcmp(cur->insn, "j") == 0) {
486
                cur->func_unit = jump;
487 123 markom
                pctemp = eval_operand(cur->op1,&breakpoint);
488 2 cvs
        } else
489
        if (strcmp(cur->insn, "nop") == 0) {
490
                cur->func_unit = nop;
491
        } else
492
        if (strcmp(cur->insn, "beqz") == 0) {
493
                cur->func_unit = branch;
494
                cur->dependsrc1 = cur->op1;
495 123 markom
                if (eval_operand(cur->op1,&breakpoint) == 0) {
496
                        pctemp = eval_operand(cur->op2,&breakpoint);
497 2 cvs
                        mstats.beqz.taken++;
498
                        bpb_update(cur->insn_addr, 1);
499
                        btic_update(pctemp);
500
                } else {
501
                        mstats.beqz.nottaken++;
502
                        bpb_update(cur->insn_addr, 0);
503
                        btic_update(pc);
504
                }
505
        } else
506
        if (strcmp(cur->insn, "bnez") == 0) {
507
                cur->func_unit = branch;
508
                cur->dependsrc1 = cur->op1;
509 123 markom
                if (eval_operand(cur->op1,&breakpoint) != 0) {
510
                        pctemp = eval_operand(cur->op2,&breakpoint);
511 2 cvs
                        mstats.bnez.taken++;
512
                        bpb_update(cur->insn_addr, 1);
513
                        btic_update(pctemp);
514
                } else {
515
                        mstats.bnez.nottaken++;
516
                        bpb_update(cur->insn_addr, 0);
517
                        btic_update(pc);
518
                }
519
        } else
520
        if (strcmp(cur->insn, "seq") == 0) {
521
                cur->func_unit = compare;
522 123 markom
                if (eval_operand(cur->op2,&breakpoint) == eval_operand(cur->op3,&breakpoint))
523
                        set_operand(cur->op1, 1,&breakpoint);
524 2 cvs
                else
525 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
526 2 cvs
        } else
527
        if (strcmp(cur->insn, "snei") == 0) {
528
                cur->func_unit = compare;
529 123 markom
                if (eval_operand(cur->op2,&breakpoint) != eval_operand(cur->op3,&breakpoint))
530
                        set_operand(cur->op1, 1,&breakpoint);
531 2 cvs
                else
532 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
533 2 cvs
        } else
534
        if (strcmp(cur->insn, "sne") == 0) {
535
                cur->func_unit = compare;
536 123 markom
                if (eval_operand(cur->op2,&breakpoint) != eval_operand(cur->op3,&breakpoint))
537
                        set_operand(cur->op1, 1,&breakpoint);
538 2 cvs
                else
539 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
540 2 cvs
        } else
541
        if (strcmp(cur->insn, "seqi") == 0) {
542
                cur->func_unit = compare;
543 123 markom
                if (eval_operand(cur->op2,&breakpoint) == eval_operand(cur->op3,&breakpoint))
544
                        set_operand(cur->op1, 1,&breakpoint);
545 2 cvs
                else
546 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
547 2 cvs
        } else
548
        if (strcmp(cur->insn, "sgt") == 0) {
549
                cur->func_unit = compare;
550 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) >
551
                    (signed)eval_operand(cur->op3,&breakpoint))
552
                        set_operand(cur->op1, 1,&breakpoint);
553 2 cvs
                else
554 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
555 2 cvs
        } else
556
        if (strcmp(cur->insn, "sgtui") == 0) {
557
                cur->func_unit = compare;
558 123 markom
                if ((unsigned)eval_operand(cur->op2,&breakpoint) >
559
                    (unsigned)eval_operand(cur->op3,&breakpoint))
560
                        set_operand(cur->op1, 1,&breakpoint);
561 2 cvs
                else
562 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
563 2 cvs
        } else
564
        if (strcmp(cur->insn, "sgeui") == 0) {
565
                cur->func_unit = compare;
566 123 markom
                if ((unsigned)eval_operand(cur->op2,&breakpoint) >=
567
                    (unsigned)eval_operand(cur->op3,&breakpoint))
568
                        set_operand(cur->op1, 1,&breakpoint);
569 2 cvs
                else
570 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
571 2 cvs
        } else
572
        if (strcmp(cur->insn, "sgei") == 0) {
573
                cur->func_unit = compare;
574 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) >= (signed)eval_operand(cur->op3,&breakpoint))
575
                        set_operand(cur->op1, 1,&breakpoint);
576 2 cvs
                else
577 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
578 2 cvs
        } else
579
        if (strcmp(cur->insn, "sgti") == 0) {
580
                cur->func_unit = compare;
581 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) >
582
                    (signed)eval_operand(cur->op3,&breakpoint))
583
                        set_operand(cur->op1, 1,&breakpoint);
584 2 cvs
                else
585 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
586 2 cvs
        } else
587
        if (strcmp(cur->insn, "slt") == 0) {
588
                cur->func_unit = compare;
589 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) <
590
                    (signed)eval_operand(cur->op3,&breakpoint))
591
                        set_operand(cur->op1, 1,&breakpoint);
592 2 cvs
                else
593 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
594 2 cvs
        } else
595
        if (strcmp(cur->insn, "slti") == 0) {
596
                cur->func_unit = compare;
597 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) <
598
                    (signed)eval_operand(cur->op3,&breakpoint))
599
                        set_operand(cur->op1, 1,&breakpoint);
600 2 cvs
                else
601 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
602 2 cvs
        } else
603
        if (strcmp(cur->insn, "sle") == 0) {
604
                cur->func_unit = compare;
605 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) <=
606
                    (signed)eval_operand(cur->op3,&breakpoint))
607
                        set_operand(cur->op1, 1,&breakpoint);
608 2 cvs
                else
609 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
610 2 cvs
        } else
611
        if (strcmp(cur->insn, "slei") == 0) {
612
                cur->func_unit = compare;
613 123 markom
                if ((signed)eval_operand(cur->op2,&breakpoint) <=
614
                    (signed)eval_operand(cur->op3,&breakpoint))
615
                        set_operand(cur->op1, 1,&breakpoint);
616 2 cvs
                else
617 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
618 2 cvs
        } else
619
        if (strcmp(cur->insn, "sleui") == 0) {
620
                cur->func_unit = compare;
621 123 markom
                if ((unsigned)eval_operand(cur->op2,&breakpoint) <=
622
                    (unsigned)eval_operand(cur->op3,&breakpoint))
623
                        set_operand(cur->op1, 1,&breakpoint);
624 2 cvs
                else
625 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
626 2 cvs
        } else
627
        if (strcmp(cur->insn, "sleu") == 0) {
628
                cur->func_unit = compare;
629 123 markom
                if ((unsigned)eval_operand(cur->op2,&breakpoint) <=
630
                    (unsigned)eval_operand(cur->op3,&breakpoint))
631
                        set_operand(cur->op1, 1,&breakpoint);
632 2 cvs
                else
633 123 markom
                        set_operand(cur->op1, 0,&breakpoint);
634 2 cvs
        } else
635
        if (strcmp(cur->insn, "simrdtsc") == 0) {
636 123 markom
                set_operand(cur->op1, cycles+loadcycles+storecycles+forwardingcycles,&breakpoint);
637 2 cvs
        } else
638
        if (strcmp(cur->insn, "simprintf") == 0) {
639
                unsigned long stackaddr;
640
 
641
                stackaddr = eval_reg(FRAME_REG);
642
                simprintf(stackaddr, 0);
643 997 markom
                /* PRINTF("simprintf %x %x %x\n", stackaddr, fmtaddr, args); */
644 2 cvs
        } else {
645 997 markom
                PRINTF("\nABORT: illegal opcode %s ", cur->insn);
646
                PRINTF("at %.8lx\n", cur->insn_addr);
647 2 cvs
                cont_run = 0;
648
        }
649
 
650
        /* Dynamic, dependency stats. */
651
        adddstats(icomplet[0].insn, iqueue[0].insn, 1, check_depend());
652
 
653
        /* Dynamic, functional units stats. */
654
        addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
655
 
656
        /* Dynamic, single stats. */
657
        addsstats(iqueue[0].insn, 1, 0);
658
 
659 6 lampret
        if (cur->func_unit == store)
660
                storecycles += 0;
661
 
662
        if (cur->func_unit == load)
663
                loadcycles += 0;
664
 
665
        if (check_depend())
666
                forwardingcycles += 0;
667
 
668 2 cvs
        /* Pseudo multiple issue benchmark */
669
        if ((multissue[cur->func_unit] == 0) || (check_depend())) {
670
                int i;
671
                for (i = 0; i < 20; i++)
672 6 lampret
                        multissue[i] = 9;
673 2 cvs
                supercycles++;
674 6 lampret
                multissue[arith] = 9;
675
                multissue[store] = 9;
676
                multissue[load] = 9;
677 2 cvs
        }
678
        multissue[cur->func_unit]--;
679
 
680
        return;
681
}
682
 
683
void execute()
684
{
685
        int i;
686
 
687
        /* Here comes real execution someday... */
688
 
689
        /* Instruction waits in completition buffer until retired. */
690
        strcpy(icomplet[0].insn, iqueue[0].insn);
691
        strcpy(icomplet[0].op1, iqueue[0].op1);
692
        strcpy(icomplet[0].op2, iqueue[0].op2);
693
        strcpy(icomplet[0].op3, iqueue[0].op3);
694
        icomplet[0].func_unit = iqueue[0].func_unit;
695
        icomplet[0].insn_addr = iqueue[0].insn_addr;
696
 
697
        if (iqueue[0].dependdst == iqueue[0].op1)
698
                icomplet[0].dependdst = icomplet[0].op1;
699
        else
700
        if (iqueue[0].dependdst == iqueue[0].op2)
701
                icomplet[0].dependdst = icomplet[0].op2;
702
        else
703
        if (iqueue[0].dependdst == iqueue[0].op3)
704
                icomplet[0].dependdst = icomplet[0].op3;
705
        else
706
                icomplet[0].dependdst = NULL;
707
 
708
        if (iqueue[0].dependsrc1 == iqueue[0].op1)
709
                icomplet[0].dependsrc1 = icomplet[0].op1;
710
        else
711
        if (iqueue[0].dependsrc1 == iqueue[0].op2)
712
                icomplet[0].dependsrc1 = icomplet[0].op2;
713
        else
714
        if (iqueue[0].dependsrc1 == iqueue[0].op3)
715
                icomplet[0].dependsrc1 = icomplet[0].op3;
716
        else
717
                icomplet[0].dependsrc1 = NULL;
718
 
719
        if (iqueue[0].dependsrc2 == iqueue[0].op1)
720
                icomplet[0].dependsrc2 = icomplet[0].op1;
721
        else
722
        if (iqueue[0].dependsrc2 == iqueue[0].op2)
723
                icomplet[0].dependsrc2 = icomplet[0].op2;
724
        else
725
        if (iqueue[0].dependsrc2 == iqueue[0].op3)
726
                icomplet[0].dependsrc2 = icomplet[0].op3;
727
        else
728
                icomplet[0].dependsrc2 = NULL;
729
 
730
        /* History of execution */
731
        for (i = HISTEXEC_LEN - 1; i; i--)
732
                histexec[i] = histexec[i - 1];
733
        histexec[0] = icomplet[0].insn_addr;      /* add last insn */
734
 
735
        return;
736
}
737
 
738
void dumpreg()
739
{
740
        int i;
741
 
742 997 markom
        PRINTF("\n\nIQ[0]:");
743 2 cvs
        dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4);
744 997 markom
        PRINTF(" (just executed)\tCYCLES: %u \nSuperscalar CYCLES: %u\n", cycles, supercycles);
745
        PRINTF("Additional LOAD CYCLES: %u  STORE CYCLES: %u\n", loadcycles, storecycles);
746
        PRINTF("Additional RESULT FORWARDING CYCLES: %u\nPC:", forwardingcycles);
747 2 cvs
        dumpmemory(pc, pc + 4);
748 997 markom
        PRINTF(" (next insn)");
749 2 cvs
        for(i = 0; i < MAX_GPRS; i++) {
750
                if (i % 4 == 0)
751 997 markom
                        PRINTF("\n");
752
                PRINTF("GPR%.2u: %.8lx  ", i, reg[i]);
753 2 cvs
        }
754
}

powered by: WebSVN 2.1.0

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