Skip to content

Commit

Permalink
added energy annotations, refactored cell/inst name with delay info
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Jul 3, 2024
1 parent df9e17c commit 002500e
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 43 deletions.
16 changes: 9 additions & 7 deletions annotate_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ void annotate_pass_init (ActPass *ap)
ActDynamicPass *adp = dynamic_cast<ActDynamicPass *>(ap);
Assert (adp, "Hmm..");

ActPass *nlp = a->pass_find ("prs2net");
ActPass *bp = a->pass_find ("booleanize");

if (!nlp) {
nlp = new ActNetlistPass (a);
if (!bp) {
bp = new ActBooleanizePass (a);
}
adp->addDependency ("prs2net");
adp->addDependency ("booleanize");
}

/* Not defining this
Expand All @@ -49,9 +49,13 @@ void *annotate_pass_proc (ActPass *ap, Process *p, int mode)

if (!p || !dp->getRoot()) {
/* run on the top level global namespace */
printf ("SPEF pass must be run with a specified top-level process only.");
printf ("Annotation pass must be run with a specified top-level process only.");
return NULL;
}

if (dp->getRoot() == p) {
/* the root process: read SPEF/SDF as specified */
}

if (!dp->hasParam ("spef")) {
char buf[1024];
Expand Down Expand Up @@ -96,8 +100,6 @@ void *annotate_pass_proc (ActPass *ap, Process *p, int mode)
spf = (Spef *) dp->getPtrParam ("spef");
}
Assert (spf, "What?!");


return NULL;
}

Expand Down
169 changes: 149 additions & 20 deletions sdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const char *sdf_path::_names[] =
SDF::SDF (bool mangled_ids)
{
_l = NULL;
_extended = false;
#define TOKEN(a,b) a = -1;
#include "sdf.def"
_valid = false;
Expand All @@ -63,6 +64,7 @@ SDF::SDF (bool mangled_ids)
_h.temp.typ = 25.0;
_h.temp.worst = 25.0;
_h.timescale = 1.0;
_h.energyscale = 1.0;

_err_ctxt = NULL;

Expand Down Expand Up @@ -173,10 +175,16 @@ bool SDF::Read (FILE *fp)

// DELAYFILE
if (!_mustbe (_DELAYFILE)) {
_errmsg ("DELAYFILE");
goto error;
if (!_mustbe (_XDELAYFILE)) {
_errmsg ("DELAYFILE");
goto error;
}
_extended = true;
}

else {
_extended = false;
}

// sdf header
if (!_read_sdfheader ()) goto error;

Expand Down Expand Up @@ -341,6 +349,52 @@ bool SDF::_read_sdfheader ()
}
lex_getsym (_l);
}
else if (_extended && lex_have (_l, _ENERGYSCALE)) {
int val;
lex_pop_position (_l);
if (strcmp (lex_tokenstring (_l), "1") == 0 ||
strcmp (lex_tokenstring (_l), "1.0") == 0) {
val = 1;
}
else if (strcmp (lex_tokenstring (_l), "10") == 0 ||
strcmp (lex_tokenstring (_l), "10.0") == 0) {
val = 10;
}
else if (strcmp (lex_tokenstring (_l), "100") == 0 ||
strcmp (lex_tokenstring (_l), "100.0") == 0) {
val = 100;
}
else {
fprintf (stderr, "ENERGYSCALE specifier error!\n");
return false;
}
lex_getsym (_l);
if (strcmp (lex_tokenstring (_l), "J") == 0) {
_h.energyscale = val;
}
else if (strcmp (lex_tokenstring (_l), "mJ") == 0) {
_h.energyscale = val*1e-3;
}
else if (strcmp (lex_tokenstring (_l), "uJ") == 0) {
_h.energyscale = val*1e-6;
}
else if (strcmp (lex_tokenstring (_l), "nJ") == 0) {
_h.energyscale = val*1e-9;
}
else if (strcmp (lex_tokenstring (_l), "pJ") == 0) {
_h.energyscale = val*1e-12;
}
else if (strcmp (lex_tokenstring (_l), "fJ") == 0) {
_h.energyscale = val*1e-15;
}
else if (strcmp (lex_tokenstring (_l), "aJ") == 0) {
_h.energyscale = val*1e-18;
}
else {
fprintf (stderr, "ENERGYSCALE specifier error!\n");
}
lex_getsym (_l);
}
else {
lex_set_position (_l);
lex_pop_position (_l);
Expand All @@ -361,7 +415,7 @@ bool SDF::_read_sdfheader ()
return true;
}

#define ERR_RET if (cur) cur->clear(); lex_set_position (_l); lex_pop_position (_l); return false
#define ERR_RET if (cur) { cur->clear(); delete cur; } lex_set_position (_l); lex_pop_position (_l); return false

bool SDF::_read_cell()
{
Expand All @@ -385,12 +439,13 @@ bool SDF::_read_cell()
_errmsg ("string");
ERR_RET;
}
A_NEW (_cells, struct sdf_cell);
new (&A_NEXT (_cells)) sdf_cell();
A_NEW (_cells, struct sdf_cellinfo);
A_NEXT (_cells).data = new sdf_cell;
A_NEXT (_cells).inst = NULL;
A_NEXT (_cells).celltype = Strdup (lex_prev (_l) + 1);
A_NEXT (_cells).celltype[strlen (A_NEXT(_cells).celltype)-1] = '\0';

cur = &A_NEXT(_cells);
cur = A_NEXT(_cells).data;

if (!_mustbe (_tok_rpar)) {
_errmsg (")");
Expand Down Expand Up @@ -418,8 +473,8 @@ bool SDF::_read_cell()
}
else {
// parse hierarchical id
cur->inst = _parse_hier_id ();
if (!cur->inst) {
A_NEXT (_cells).inst = _parse_hier_id ();
if (!A_NEXT (_cells).inst) {
_errmsg ("path-to-inst");
ERR_RET;
}
Expand Down Expand Up @@ -615,24 +670,27 @@ bool SDF::_read_cell()
ERR_RET;
}
}
}
else if (_extended && lex_have (_l, _LEAKAGE)) {

}
else if (_extended && lex_have (_l, _ENERGY)) {

}
else if (lex_have (_l, _TIMINGCHECK) || lex_have (_l, _TIMINGENV)
|| lex_have (_l, _LABEL)) {
_skip_to_endpar ();
}
else {
A_NEXT (_cells).clear();
_errmsg ("delay/timing checks");
ERR_RET;
}
if (!_mustbe (_tok_rpar)) {
A_NEXT (_cells).clear();
ERR_RET;
}
}

if (lex_eof (_l)) {
A_NEXT (_cells).clear();
ERR_RET;
}
else {
Expand All @@ -649,7 +707,12 @@ bool SDF::_read_cell()
void SDF::Print (FILE *fp)
{
fprintf (fp, "// Status: %s\n", _valid ? "valid" : "invalid");
fprintf (fp, "(DELAYFILE\n");
if (_extended) {
fprintf (fp, "(XDELAYFILE\n");
}
else {
fprintf (fp, "(DELAYFILE\n");
}
#define EMIT_STRING(name,prefix) \
if (_h.prefix) { \
fprintf (fp, " (%s \"%s\")\n", name, _h.prefix); \
Expand Down Expand Up @@ -709,6 +772,44 @@ void SDF::Print (FILE *fp)
}
fprintf (fp, "%d %s)\n", ts, suffix);

if (_extended) {
fprintf (fp, " (ENERGYSCALE ");
const char *suffix;
int ts;
if (_h.energyscale >= 1) {
suffix = "J";
ts = _h.energyscale;
}
else if (_h.energyscale >= 1e-3) {
suffix = "mJ";
ts = 1e3*_h.energyscale;
}
else if (_h.energyscale >= 1e-6) {
suffix = "uJ";
ts = 1e6*_h.energyscale;
}
else if (_h.energyscale >= 1e-9) {
suffix = "nJ";
ts = 1e9*_h.energyscale;
}
else if (_h.energyscale >= 1e-12) {
suffix = "pJ";
ts = 1e12*_h.energyscale;
}
else if (_h.energyscale >= 1e-15) {
suffix = "fJ";
ts = 1e15*_h.energyscale;
}
else if (_h.energyscale >= 1e-18) {
suffix = "aJ";
ts = 1e15*_h.energyscale;
}
else {
fatal_error ("Internal inconsistency!");
}
fprintf (fp, "%d %s)\n", ts, suffix);
}

for (int i=0; i < A_LEN (_cells); i++) {
fprintf (fp, " (CELL\n");
if (_cells[i].celltype) {
Expand All @@ -723,30 +824,58 @@ void SDF::Print (FILE *fp)
}
fprintf (fp, ")\n");

fprintf (fp, " (DELAY\n");
fprintf (fp, " (DELAY\n");
int prev = -1;
for (int j=0; j < A_LEN (_cells[i]._paths); j++) {
sdf_path *p = &_cells[i]._paths[j];
for (int j=0; j < A_LEN (_cells[i].data->_paths); j++) {
sdf_path *p = &_cells[i].data->_paths[j];
if (p->abs != prev) {
if (prev != -1) {
fprintf (fp, " )\n");
fprintf (fp, " )\n");
}
prev = p->abs;
if (prev) {
fprintf (fp, " (ABSOLUTE\n");
fprintf (fp, " (ABSOLUTE\n");
}
else {
fprintf (fp, " (INCREMENT\n");
fprintf (fp, " (INCREMENT\n");
}
}
fprintf (fp, " ");
p->Print (fp, _h.divider);
fprintf (fp, "\n");
}
if (prev != -1) {
fprintf (fp, " )\n");
}
fprintf (fp, " )\n");

if (_extended) {
fprintf (fp, " (ENERGY\n");
int prev = -1;
for (int j=0; j < A_LEN (_cells[i].data->_epaths); j++) {
sdf_path *p = &_cells[i].data->_epaths[j];
if (p->abs != prev) {
if (prev != -1) {
fprintf (fp, " )\n");
}
prev = p->abs;
if (prev) {
fprintf (fp, " (ABSOLUTE\n");
}
else {
fprintf (fp, " (INCREMENT\n");
}
}
fprintf (fp, " ");
p->Print (fp, _h.divider);
fprintf (fp, "\n");
}
if (prev != -1) {
fprintf (fp, " )\n");
}
fprintf (fp, " )\n");
}
fprintf (fp, " )\n");

fprintf (fp, " )\n");
}

Expand Down
5 changes: 5 additions & 0 deletions sdf.def
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN(_DELAYFILE, "DELAYFILE")
TOKEN(_XDELAYFILE, "XDELAYFILE")
TOKEN(_SDFVERSION, "SDFVERSION")
TOKEN(_DESIGN, "DESIGN")
TOKEN(_DATE, "DATE")
Expand All @@ -10,10 +11,12 @@ TOKEN(_VOLTAGE,"VOLTAGE")
TOKEN(_PROCESS,"PROCESS")
TOKEN(_TEMPERATURE,"TEMPERATURE")
TOKEN(_TIMESCALE,"TIMESCALE")
TOKEN(_ENERGYSCALE,"ENERGYSCALE")
TOKEN(_CELL,"CELL")
TOKEN(_CELLTYPE,"CELLTYPE")
TOKEN(_INSTANCE,"INSTANCE")
TOKEN(_DELAY,"DELAY")
TOKEN(_ENERGY,"ENERGY")
TOKEN(_TIMINGCHECK,"TIMINGCHECK")
TOKEN(_TIMINGENV,"TIMINGENV")
TOKEN(_LABEL,"LABEL")
Expand All @@ -28,6 +31,8 @@ TOKEN(_CONDELSE,"CONDELSE")
TOKEN(_PORT,"PORT")
TOKEN(_INTERCONNECT,"INTERCONNECT")
TOKEN(_NETDELAY,"NETDELAY")
TOKEN(_NETENERGY,"NETENERGY")
TOKEN(_LEAKAGE,"LEAKAGE")
TOKEN(_DEVICE,"DEVICE")
TOKEN(_SETUP,"SETUP")
TOKEN(_HOLD,"HOLD")
Expand Down
Loading

0 comments on commit 002500e

Please sign in to comment.