URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 936 to Rev 937
- ↔ Reverse comparison
Rev 936 → Rev 937
/trunk/or1ksim/cuc/cuc.h
97,7 → 97,7
|
#define cucdebug(x,s...) {if ((x) <= cuc_debug) printf (s);} |
|
#define CUC_WIDTH_ITERATIONS 1000 |
#define CUC_WIDTH_ITERATIONS 256 |
|
/* Options */ |
/* Whether we are debugging cuc (0-9) */ |
/trunk/or1ksim/cuc/insn.c
58,7 → 58,7
{"cmov", 0,"assign \1 = \4 ? \2 : \3;"}, |
{"reg", 0, "always @(posedge clk)"}, |
|
{"nop", 0, NULL}, |
{"nop", 1, ""}, |
{"call", 0, "/* function call */"}}; |
|
/* Find known instruction and attach them to insn */ |
71,6 → 71,7
for (j = 0; j < MAX_OPERANDS; j++) i->opt[j] = OPT_NONE; |
i->type = 0; |
i->dep = NULL; |
i->disasm[0] = '\0'; |
} |
} |
|
90,12 → 91,14
if (verbose) { |
printf ("%-20s insn = %08x, index = %i, type = %04x ", |
insn[i].disasm, insn[i].insn, insn[i].index, insn[i].type); |
} else printf ("max = %08x type = %04x ", insn[i].max, insn[i].type); |
} else printf ("type = %04x ", insn[i].type); |
for (j = 0; j < MAX_OPERANDS; j++) { |
if (insn[i].opt[j] & OPT_DEST) printf ("*"); |
switch (insn[i].opt[j] & ~OPT_DEST) { |
case OPT_NONE: break; |
case OPT_CONST: printf ("0x%08x, ", insn[i].op[j]); break; |
case OPT_CONST: if (insn[i].type & IT_COND && (insn[i].index == II_CMOV |
|| insn[i].index == II_ADD)) printf ("%x, ", insn[i].op[j]); |
else printf ("0x%08x, ", insn[i].op[j]); break; |
case OPT_JUMP: printf ("J%x ", insn[i].op[j]); break; |
case OPT_REGISTER: printf ("r%i, ", insn[i].op[j]); break; |
case OPT_REF: printf ("[%x.%x], ", REF_BB(insn[i].op[j]), REF_I(insn[i].op[j])); break; |
/trunk/or1ksim/cuc/verilog.c
82,7 → 82,8
unsigned long opt = f->INSN(ref).opt[j]; |
switch (opt & ~OPT_DEST) { |
case OPT_NONE: assert (0); break; |
case OPT_CONST: if (f->INSN(ref).type & IT_COND && f->INSN(ref).insn == II_CMOV) { |
case OPT_CONST: if (f->INSN(ref).type & IT_COND && (f->INSN(ref).index == II_CMOV |
|| f->INSN(ref).index == II_ADD)) { |
assert (op == 0 || op == 1); |
sprintf (s, "1'b%x", op); |
} else sprintf (s, "32'h%x", op); |
/trunk/or1ksim/cuc/memory.c
116,12 → 116,11
if (otype == MO_NONE || otype == MO_WEAK) insn[i].type |= IT_FLAG1; /* mark unscheduled */ |
} |
} |
#if 0 |
|
for (i = 0; i < f->nmsched; i++) |
printf ("[%i]%i%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
printf ("\n"); |
#endif |
|
cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
cucdebug (2, "\n"); |
|
/* We can reorder just more loose types |
We assume, that memory accesses are currently in valid (but not neccesserly) |
optimal order */ |
152,11 → 151,9
} |
} |
|
#if 0 |
for (i = 0; i < f->nmsched; i++) |
printf ("[%i]%i%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
printf ("\n"); |
#endif |
cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
cucdebug (2, "\n"); |
|
/* Assign memory types */ |
for (i = 0; i < f->nmsched; i++) { |
201,7 → 198,7
f->bb[b].insn[i].op[j] = t1; |
|
} else goto keep; |
} |
} else goto keep; |
} else { |
keep: |
f->msched[j] = f->msched[i]; |
210,6 → 207,11
f->nmsched = j; |
} |
|
for (i = 0; i < f->nmsched; i++) |
cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
cucdebug (2, "\n"); |
if (cuc_debug > 5) print_cuc_bb (f, "AFTER_MEM_REMOVAL"); |
|
if (config.cuc.enable_bursts) { |
//printf ("\n"); |
for (i = 1; i < f->nmsched; i++) { |
238,12 → 240,9
} |
} |
|
#if 0 |
printf ("\n"); |
for (i = 0; i < f->nmsched; i++) |
printf ("[%i]%i%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
printf ("\n"); |
#endif |
cucdebug (2, "[%x]%x%c ", f->msched[i], f->mtype[i] & MT_WIDTH, (f->mtype[i] & MT_BURST) ? (f->mtype[i] & MT_BURSTE) ? 'E' : 'B' : ' '); |
cucdebug (2, "\n"); |
|
/* We don't need dependencies in non-memory instructions */ |
for (b = 0; b < f->num_bb; b++) { |
266,6 → 265,7
dep_list *tmp = f->INSN(f->msched[i]).dep; |
while (tmp) { |
if (f->INSN(tmp->ref).type & IT_MEMORY && REF_BB(tmp->ref) == REF_BB(f->msched[i])) { |
printf ("%i %x %x\n", i, f->msched[i], tmp->ref); |
/* Search for the reference */ |
for (j = 0; j < f->nmsched; j++) if (f->msched[j] == tmp->ref) break; |
assert (j < f->nmsched); |
/trunk/or1ksim/cuc/cuc.c
113,8 → 113,10
} |
} while (modified); |
set_io (func); |
#if 0 |
detect_max_values (func); |
if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_MAX_VALUES"); |
#endif |
} |
|
/* Pre/unrolls basic block and optimizes it */ |
/trunk/or1ksim/cuc/adv.c
0,0 → 1,285
/* adv.c -- OpenRISC Custom Unit Compiler, Advanced Optimizations |
* Copyright (C) 2002 Marko Mlinar, markom@opencores.org |
* |
* This file is part of OpenRISC 1000 Architectural Simulator. |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <stdarg.h> |
#include <assert.h> |
#include "sim-config.h" |
#include "abstract.h" |
#include "cuc.h" |
#include "insn.h" |
#include "support/profile.h" |
|
/* Marks successor of b with mask m */ |
static void mark_successors (cuc_func *f, int b, int m, int stopb) |
{ |
if (b < 0 || b == BBID_END) return; |
if (f->bb[b].tmp & m) return; |
f->bb[b].tmp |= m; |
/* mark stopb also; and stop searching -- we will gen new result in stopb */ |
if (b == stopb) return; |
mark_successors (f, f->bb[b].next[0], m, stopb); |
mark_successors (f, f->bb[b].next[1], m, stopb); |
} |
|
static unsigned long mask (unsigned long c) |
{ |
if (c) return (1 << (log2 (c) + 1)) - 1; |
else return 0; |
} |
|
/* Calculates facts, that are determined by conditionals */ |
void insert_conditional_facts (cuc_func *f) |
{ |
int b, i, j; |
int b1, i1, j1; |
cuc_insn n[2]; |
for (b = 0; b < f->num_bb; b++) if (f->bb[b].ninsn > 0) { |
cuc_insn *ii = &f->bb[b].insn[f->bb[b].ninsn - 1]; |
/* We have following situation |
x <= ... |
sfxx f, x, CONST |
bf ..., f */ |
if (ii->type & IT_BRANCH && ii->opt[1] & OPT_REF && REF_BB(ii->op[1]) == b |
&& f->INSN(ii->op[1]).opt[2] & OPT_CONST) { |
int ok = 0; |
unsigned long c = f->INSN(ii->op[1]).op[2]; |
int rref = f->INSN(ii->op[1]).op[1]; |
unsigned long r; |
if (!(f->INSN(ii->op[1]).opt[1] & OPT_REF)) continue; |
r = f->INSN(rref).op[0]; |
for (j = 0; j < 2; j++) { |
change_insn_type (&n[j], II_ADD); |
n[j].type = 0; |
n[j].dep = NULL; |
n[j].op[0] = r; n[j].opt[0] = OPT_REGISTER | OPT_DEST; |
n[j].op[1] = 0; n[j].opt[1] = OPT_CONST; |
n[j].op[2] = rref; n[j].opt[2] = OPT_REF; |
n[j].opt[3] = OPT_NONE; |
sprintf (n[j].disasm, "conditional %s fact", j ? "false" : "true"); |
} |
|
/* First get the conditional and two instruction to place after the current BB */ |
switch (f->INSN(ii->op[1]).index) { |
case II_SFEQ: |
change_insn_type (&n[0], II_ADD); |
n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST; |
n[0].op[1] = 0; n[0].opt[1] = OPT_CONST; |
n[0].op[2] = c; n[0].opt[2] = OPT_CONST; |
ok = 1; |
break; |
case II_SFNE: |
change_insn_type (&n[1], II_ADD); |
n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST; |
n[1].op[1] = 0; n[1].opt[1] = OPT_CONST; |
n[1].op[2] = c; n[1].opt[2] = OPT_CONST; |
ok = 2; |
break; |
case II_SFLT: |
change_insn_type (&n[0], II_AND); |
n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST; |
n[0].op[1] = rref; n[0].opt[1] = OPT_REF; |
n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST; |
ok = 1; |
break; |
case II_SFGT: |
change_insn_type (&n[1], II_ADD); |
n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST; |
n[1].op[1] = rref; n[1].opt[1] = OPT_REF; |
n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST; |
ok = 2; |
break; |
case II_SFLE: |
change_insn_type (&n[0], II_AND); |
n[0].op[0] = r; n[0].opt[0] = OPT_REGISTER | OPT_DEST; |
n[0].op[1] = rref; n[0].opt[1] = OPT_REF; |
n[0].op[2] = mask (c); n[0].opt[2] = OPT_CONST; |
ok = 1; |
break; |
case II_SFGE: |
change_insn_type (&n[1], II_ADD); |
n[1].op[0] = r; n[1].opt[0] = OPT_REGISTER | OPT_DEST; |
n[1].op[1] = rref; n[1].opt[1] = OPT_REF; |
n[1].op[2] = mask (c + 1); n[1].opt[2] = OPT_CONST; |
ok = 2; |
break; |
default: |
ok = 0; |
break; |
} |
|
/* Now add two BBs at the end and relink */ |
if (ok) { |
int cnt = 0; |
printf ("%x rref %x cnt %i\n", b, rref, cnt); |
fflush (stdout); |
for (j = 0; j < 2; j++) { |
int nb = f->num_bb++; |
int sb; |
int k; |
assert (nb < MAX_BB); |
f->bb[nb].type = 0; |
f->bb[nb].first = -1; f->bb[nb].last = -1; |
f->bb[nb].prev[0] = b; f->bb[nb].prev[1] = -1; |
sb = f->bb[nb].next[0] = f->bb[b].next[j]; f->bb[nb].next[1] = -1; |
assert (cnt >= 0); |
printf ("%x %x %x rref %x cnt %i\n", b, sb, nb, rref, cnt); |
fflush (stdout); |
assert (sb >= 0); |
f->bb[b].next[j] = nb; |
if (sb != BBID_END) { |
if (f->bb[sb].prev[0] == b) f->bb[sb].prev[0] = nb; |
else if (f->bb[sb].prev[1] == b) f->bb[sb].prev[1] = nb; |
else assert (0); |
} |
f->bb[nb].insn = (cuc_insn *) malloc (sizeof (cuc_insn) * (cnt + 1)); |
assert (f->bb[nb].insn); |
f->bb[nb].insn[0] = n[j]; |
f->bb[nb].ninsn = cnt + 1; |
f->bb[nb].mdep = NULL; |
f->bb[nb].nmemory = 0; |
f->bb[nb].cnt = 0; |
f->bb[nb].unrolled = 0; |
f->bb[nb].ntim = 0; |
f->bb[nb].selected_tim = -1; |
} |
for (b1 = 0; b1 < f->num_bb; b1++) f->bb[b1].tmp = 0; |
|
/* Find successor blocks and change links accordingly */ |
mark_successors (f, f->num_bb - 2, 2, b); |
mark_successors (f, f->num_bb - 1, 1, b); |
for (b1 = 0; b1 < f->num_bb - 2; b1++) if (f->bb[b1].tmp == 1 || f->bb[b1].tmp == 2) { |
int end; |
if (REF_BB (rref) == b1) end = REF_I (rref) + 1; |
else end = f->bb[b1].ninsn; |
for (i1 = 0; i1 < end; i1++) |
for (j1 = 0; j1 < MAX_OPERANDS; j1++) |
if (f->bb[b1].insn[i1].opt[j1] & OPT_REF && f->bb[b1].insn[i1].op[j1] == rref) |
f->bb[b1].insn[i1].op[j1] = REF (f->num_bb - f->bb[b1].tmp, 0); |
} |
print_cuc_bb (f, "FACT"); |
} |
} |
} |
} |
|
static unsigned long max_op (cuc_func *f, int ref, int o) |
{ |
if (f->INSN(ref).opt[o] & OPT_REF) return f->INSN(f->INSN(ref).op[o]).max; |
else if (f->INSN(ref).opt[o] & OPT_CONST) return f->INSN(ref).op[o]; |
else if (f->INSN(ref).opt[o] & OPT_REGISTER) return 0xffffffff; |
else assert (0); |
} |
|
/* Returns maximum value, based on inputs */ |
static unsigned long calc_max (cuc_func *f, int ref) |
{ |
cuc_insn *ii = &f->INSN(ref); |
if (ii->type & IT_COND) return 1; |
switch (ii->index) { |
case II_ADD : return MIN ((unsigned long long) max_op (f, ref, 1) |
+ (unsigned long long)max_op (f, ref, 2), 0xffffffff); |
case II_SUB : return 0xffffffff; |
case II_AND : return MIN (max_op (f, ref, 1), max_op (f, ref, 2)); |
case II_OR : return max_op (f, ref, 1) | max_op (f, ref, 2); |
case II_XOR : return max_op (f, ref, 1) | max_op (f, ref, 2); |
case II_MUL : return MIN ((unsigned long long) max_op (f, ref, 1) |
* (unsigned long long)max_op (f, ref, 2), 0xffffffff); |
case II_SLL : if (ii->opt[2] & OPT_CONST) return max_op (f, ref, 1) << ii->op[2]; |
else return max_op (f, ref, 1); |
case II_SRA : return max_op (f, ref, 1); |
case II_SRL : if (ii->opt[2] & OPT_CONST) return max_op (f, ref, 1) >> ii->op[2]; |
else return max_op (f, ref, 1); |
case II_LB : return 0xff; |
case II_LH : return 0xffff; |
case II_LW : return 0xffffffff; |
case II_SB : |
case II_SH : |
case II_SW : return 0; |
case II_SFEQ: |
case II_SFNE: |
case II_SFLE: |
case II_SFLT: |
case II_SFGE: |
case II_SFGT: return 1; |
case II_BF : return 0; |
case II_LRBB: return 1; |
case II_CMOV: return MAX (max_op (f, ref, 1), max_op (f, ref, 2)); |
case II_REG : return max_op (f, ref, 1); |
case II_NOP : assert (0); |
case II_CALL: assert (0); |
default: assert (0); |
} |
return -1; |
} |
|
/* Width optimization -- detect maximum values; |
these values are actually estimates, since the problem |
is to hard otherwise... |
We calculate these maximums iteratively -- we are slowly |
approaching final solution. This algorithm is surely finite, |
but can be very slow; so we stop after some iterations; |
normal loops should be in this range */ |
void detect_max_values (cuc_func *f) |
{ |
int b, i, j; |
int modified = 0; |
int iteration = 0; |
|
for (b = 0; b < f->num_bb; b++) { |
for (i = 0; i < f->bb[b].ninsn; i++) f->bb[b].insn[i].max = 0; |
f->bb[b].tmp = 1; |
} |
|
/* Repeat until something is changing */ |
do { |
modified = 0; |
for (b = 0; b < f->num_bb; b++) { |
if (f->bb[b].tmp) { |
for (i = 0; i < f->bb[b].ninsn; i++) { |
unsigned long m = calc_max (f, REF (b, i)); |
if (m > f->bb[b].insn[i].max) { |
f->bb[b].insn[i].max = m; |
modified = 1; |
} |
} |
} |
} |
if (iteration++ > CUC_WIDTH_ITERATIONS) break; |
} while (modified); |
|
/* Something bad has happened; now we will assign 0xffffffff to all unsatisfied |
instructions; this one is stoppable in O(n ^ 2) */ |
if (iteration > CUC_WIDTH_ITERATIONS) { |
do { |
modified = 0; |
for (b = 0; b < f->num_bb; b++) |
for (i = 0; i < f->bb[b].ninsn; i++) { |
unsigned long m = calc_max (f, REF (b, i)); |
if (m > f->bb[b].insn[i].max) { |
f->bb[b].insn[i].max = 0xffffffff; |
modified = 1; |
} |
} |
} while (modified); |
} |
cucdebug (1, "detect_max_values %i iterations\n", iteration); |
} |
|