URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 905 to Rev 906
- ↔ Reverse comparison
Rev 905 → Rev 906
/trunk/or1ksim/cuc/cuc.h
166,7 → 166,7
} cuc_bb; |
|
/* Function entity */ |
typedef struct { |
typedef struct _cuc_func { |
/* Basic blocks */ |
int num_bb; |
cuc_bb bb[MAX_BB]; |
188,6 → 188,11
unsigned long start_addr; /* Address of first instruction inn function */ |
unsigned long end_addr; /* Address of last instruction inn function */ |
int memory_order; /* Memory order */ |
|
int nfdeps; /* Function dependencies */ |
struct _cuc_func **fdeps; |
|
int tmp; |
} cuc_func; |
|
/* Instructions from function */ |
/trunk/or1ksim/cuc/load.c
55,6 → 55,7
{"l.sfleu", II_SFLE}, {"l.sfleiu", II_SFLE}, |
{"l.j", II_BF }, |
{"l.bf", II_BF }, |
{"l.jal", II_CALL }, |
{"l.nop", II_NOP } |
}; |
|
307,6 → 308,47
} else insn[i].type &= ~IT_SIGNED; |
} |
|
/* expands calls to 7 instructions */ |
void expand_calls () |
{ |
int i, j, num_call = 0, d; |
for (i = 0; i < num_insn; i++) |
if (insn[i].index == II_CALL) num_call++; |
|
d = num_insn + num_call * 6; /* 6 parameters */ |
assert (d < MAX_INSNS); |
|
/* Split call instructions */ |
for (i = num_insn - 1; i >= 0; i--) |
/* We will expand signed memory later */ |
if (insn[i].index == II_CALL) { |
insn[--d] = insn[i]; |
insn[d].op[0] = insn[d].op[1]; insn[d].opt[0] = OPT_CONST; |
insn[d].opt[1] = OPT_NONE; |
insn[d].type |= IT_VOLATILE; |
|
for (j = 0; j < 6; j++) { |
insn[--d] = insn[i]; |
change_insn_type (&insn[d], II_ADD); |
insn[d].type = IT_VOLATILE; |
insn[d].op[0] = 3 + j; insn[d].opt[0] = OPT_REGISTER | OPT_DEST; |
insn[d].op[1] = 3 + j; insn[d].opt[1] = OPT_REGISTER; |
insn[d].op[2] = 0x80000000; insn[d].opt[2] = OPT_CONST; |
insn[d].opt[3] = OPT_NONE; |
} |
|
reloc[i] = d; |
} else { |
insn[--d] = insn[i]; |
reloc[i] = d; |
} |
num_insn += num_call * 6; |
for (i = 0; i < num_insn; i++) |
for (j = 0; j < MAX_OPERANDS; j++) |
if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP) |
insn[i].op[j] = reloc[insn[i].op[j]]; |
} |
|
/* Loads function from file into global array insn. |
Function returns nonzero if function cannot be converted. */ |
int cuc_load (char *in_fn) |
416,5 → 458,8
|
expand_signed (); |
if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_SIG", 0); |
|
expand_calls (); |
if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_CALLS", 0); |
return 0; |
} |
/trunk/or1ksim/cuc/bb.c
92,6 → 92,11
n->msched[i] = f->msched[i]; |
n->mtype[i] = f->mtype[i]; |
} |
n->nfdeps = f->nfdeps; |
if (f->nfdeps) { |
f->fdeps = (cuc_func **) malloc (sizeof (cuc_func *) * f->nfdeps); |
for (i = 0; i < f->nfdeps; i++) n->fdeps[i] = f->fdeps[i]; |
} |
return n; |
} |
|
/trunk/or1ksim/cuc/insn.c
59,6 → 59,7
{"cmov", 0,"assign \1 = \4 ? \2 : \3;"}, |
{"reg", 0, "always @(posedge clk or posedge rst)"}, |
|
{"call", 0, "/* function call */"}, |
{"nop", 0, NULL}}; |
|
/* Find known instruction and attach them to insn */ |
1002,7 → 1003,7
{ |
int i, first = 1; |
for (i = 0; i < nshared; i++) { |
printf ("%s%s%s", first ? "" : "-", cuc_insn_name (rf->INSN(shared[i].ref).index), |
printf ("%s%s%s", first ? "" : "-", cuc_insn_name (&rf->INSN(shared[i].ref)), |
shared[i].cmatch ? "!" : ""); |
first = 0; |
} |
/trunk/or1ksim/cuc/verilog.c
63,7 → 63,11
unsigned long opt = f->INSN(ref).opt[j]; |
switch (opt & ~OPT_DEST) { |
case OPT_NONE: assert (0); break; |
case OPT_CONST: sprintf (s, "32'h%x", op); break; |
case OPT_CONST: if (f->INSN(ref).type & IT_COND) { |
assert (op == 0 || op == 1); |
sprintf (s, "1'b%x", op); |
} else sprintf (s, "32'h%x", op); |
break; |
case OPT_REGISTER: |
if (opt & OPT_DEST) sprintf (s, "t%x_%x", REF_BB(ref), REF_I(ref)); |
else sprintf (s, "r%i_%c", op, opt & OPT_DEST ? 'o' : 'i'); |
/trunk/or1ksim/cuc/cuc.c
116,6 → 116,8
func->start_addr = start_addr; |
func->end_addr = end_addr; |
func->memory_order = memory_order; |
func->nfdeps = 0; |
func->fdeps = NULL; |
|
sprintf (tmp1, "%s.bin", module_name); |
cucdebug (2, "Loading %s.bin\n", module_name); |
449,6 → 451,73
static cuc_func *func[MAX_FUNCS]; |
static int func_v[MAX_FUNCS]; |
|
/* Detects function dependencies and removes */ |
static void set_func_deps () |
{ |
int f, b, i, j; |
restart: |
for (f = 0; f < prof_nfuncs - 1; f++) if (func[f]) { |
int fused[MAX_FUNCS] = {0}; |
int c; |
for (b = 0; b < func[f]->num_bb; b++) |
for (i = 0; i < func[f]->bb[b].ninsn; i++) { |
cuc_insn *ii = &func[f]->bb[b].insn[i]; |
if (ii->index == II_CALL) { |
assert (ii->opt[0] == OPT_CONST); |
for (j = 0; j < prof_nfuncs - 1; j++) |
if (func[j] && func[j]->start_addr == ii->op[0]) break; |
if (j >= prof_nfuncs - 1) { |
log ("%s is calling unknown function, address %08x\n", |
prof_func[f].name, ii->op[0]); |
debug (1, "%s is calling unknown function, address %08x\n", |
prof_func[f].name, ii->op[0]); |
free_func (func[f]); |
func[f] = NULL; |
goto restart; |
} else if (f == j) { |
log ("%s is recursive, ignoring\n", prof_func[f].name); |
debug (1, "%s is recursive, ignoring\n", prof_func[f].name); |
free_func (func[f]); |
func[f] = NULL; |
goto restart; |
} else fused[j]++; |
} |
} |
for (i = 0; i < MAX_FUNCS; i++) if (fused[i]) c++; |
if (func[f]->nfdeps) free (func[f]->fdeps); |
func[f]->nfdeps = c; |
func[f]->fdeps = (cuc_func **) malloc (sizeof (cuc_func *) * c); |
for (i = 0, j = 0; i < MAX_FUNCS; i++) |
if (fused[i]) func[f]->fdeps[j++] = func[i]; |
} |
|
/* Detect loops */ |
{ |
int change; |
for (f = 0; f < MAX_FUNCS; f++) if (func[f]) func[f]->tmp = 0; |
do { |
change = 0; |
for (f = 0; f < MAX_FUNCS; f++) if (func[f] && !func[f]->tmp) { |
int o = 1; |
for (i = 0; i < func[f]->nfdeps; i++) |
if (!func[f]->fdeps[i]->tmp) {o = 0; break;} |
if (o) { |
func[f]->tmp = 1; |
change = 1; |
} |
} |
} while (change); |
|
change = 0; |
for (f = 0; f < MAX_FUNCS; f++) if (func[f] && !func[f]->tmp) { |
free_func (func[f]); |
func[f] = NULL; |
change = 1; |
} |
if (change) goto restart; |
} |
} |
|
void main_cuc (char *filename) |
{ |
int i, j; |
494,9 → 563,11
end_addr, config.cuc.memory_order); |
func_v[i] = 0; |
} |
|
set_func_deps (); |
|
while (1) { |
char *s; |
wait_command: |
printf ("(cuc) "); |
fflush (stdout); |
fgets(tmp1, sizeof tmp1, stdin); |
503,8 → 574,11
for (s = tmp1; *s != '\0' && *s != '\n' && *s != '\r'; s++); |
*s = '\0'; |
|
/* quit command */ |
if (strcmp (tmp1, "q") == 0 || strcmp (tmp1, "quit") == 0) { |
break; |
|
/* profile command */ |
} else if (strcmp (tmp1, "p") == 0 || strcmp (tmp1, "profile") == 0) { |
int ntime = 0; |
int size = 0; |
546,17 → 620,30
printf ("-----------------------------------------------------------------------------\n"); |
printf ("Total %i cycles (was %i), total added gates = %i. Speed factor %.1f\n", |
ntime, prof_cycles, size, 1. * prof_cycles / ntime); |
|
/* debug command */ |
} else if (strncmp (tmp1, "d", 1) == 0 || strncmp (tmp1, "debug", 5) == 0) { |
/* debug command */ |
sscanf (tmp1, "%*s %i", &cuc_debug); |
if (cuc_debug < 0) cuc_debug = 0; |
if (cuc_debug > 9) cuc_debug = 9; |
|
/* generate command */ |
} else if (strcmp (tmp1, "g") == 0 || strcmp (tmp1, "generate") == 0) { |
/* generate command */ |
/* check for function dependencies */ |
for (i = 0; i < prof_nfuncs; i++) |
if (func[i]) func[i]->tmp = func_v[i]; |
for (i = 0; i < prof_nfuncs; i++) |
for (j = 0; j < func[i]->nfdeps; j++) |
if (!func[i]->fdeps[j] || !func[i]->fdeps[j]->tmp) { |
printf ("Function %s must be selected for translation (required by %s)\n", |
prof_func[j].name, prof_func[i].name); |
goto wait_command; |
} |
for (i = 0; i < prof_nfuncs; i++) |
if (func[i] && func_v[i]) generate_function (func[i], prof_func[i].name); |
|
/* select command */ |
} else if (strncmp (tmp1, "s", 1) == 0 || strncmp (tmp1, "select", 6) == 0) { |
/* select command */ |
char tmp[50], ch; |
int p, o, b, f; |
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch); |
587,14 → 674,15
print_shared (func[f], func[f]->bb[b].tim[o].shared, func[f]->bb[b].tim[o].nshared); |
printf ("\n"); |
} |
continue; |
goto wait_command; |
invalid_option: |
printf ("Invalid option.\n"); |
} |
} else printf ("Invalid function.\n"); |
} |
|
/* unselect command */ |
} else if (strncmp (tmp1, "u", 1) == 0 || strncmp (tmp1, "unselect", 8) == 0) { |
/* unselect command */ |
char tmp[50], ch; |
int p, o, b, f; |
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch); |
621,9 → 709,10
} |
} else printf ("Invalid function.\n"); |
} |
|
/* options command */ |
} else if (strcmp (tmp1, "o") == 0 || strcmp (tmp1, "options") == 0) { |
int any = 0; |
/* options command */ |
printf ("Available options:\n"); |
for (i = 0; i < prof_nfuncs; i++) |
if (func[i]) { |
632,10 → 721,12
} |
if (any) printf ("-----------------------------------------------------------------------------\n"); |
else printf ("Sorry. No available options.\n"); |
|
/* Ignore empty string */ |
} else if (strcmp (tmp1, "") == 0) { |
/* Ignore empty string */ |
|
/* help command */ |
} else { |
/* help command */ |
if (strcmp (tmp1, "h") != 0 && strcmp (tmp1, "help") != 0) |
printf ("Unknown command.\n"); |
printf ("OpenRISC Custom Unit Compiler command prompt\n"); |
/trunk/or1ksim/cuc/insn.h
50,7 → 50,8
#define II_CMOV 24 |
#define II_REG 25 |
#define II_NOP 26 |
#define II_LAST 26 |
#define II_CALL 27 |
#define II_LAST 27 |
|
/* misc flags */ |
#define II_MASK 0x0fff |