00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include "types.h"
00028 #include "globals.h"
00029 #include "errors.h"
00030 #include "netlist_utils.h"
00031 #include "odin_util.h"
00032 #include "ast_util.h"
00033 #include "util.h"
00034 #include "activity_estimation.h"
00035 #include "netlist_check.h"
00036
00037 #define DEFAULT_STATIC_PROBABILITY .5
00038 #define DEFAULT_TRANSITION_DENSITY .5
00039
00040 #define ACT_NUM_ITER 3
00041
00042 #define activation_t struct activation_t_t
00043 activation_t
00044 {
00045 double *static_probability;
00046 double *transition_probability;
00047 double *transition_density;
00048 };
00049
00050 void initialize_probabilities(char *input_file, netlist_t *netlist);
00051 void calc_transition_density(netlist_t *netlist);
00052 void calc_probabilities_and_init_act_data(netlist_t *netlist);
00053 short *boolean_difference(nnode_t *node, int variable_spot);
00054 double calc_density(nnode_t *node, int variable_spot, short *boolean_difference);
00055 void output_activation_file_ace_and_function_file(char *output_filename, int lut_size, netlist_t *LUT_netlist, netlist_t *CLUSTER_netlist);
00056 void cleanup_activation(netlist_t *netlist);
00057
00058
00059
00060
00061 void activity_estimation(char *input_filename, char *output_filename, int lut_size, netlist_t *LUT_netlist, netlist_t *CLUSTER_netlist)
00062 {
00063
00064 levelize_and_check_for_combinational_loop_and_liveness(FALSE, LUT_netlist);
00065
00066
00067 initialize_probabilities(input_filename, LUT_netlist);
00068
00069
00070 calc_probabilities_and_init_act_data(LUT_netlist);
00071
00072
00073 calc_transition_density(LUT_netlist);
00074
00075
00076 output_activation_file_ace_and_function_file(output_filename, lut_size, LUT_netlist, CLUSTER_netlist);
00077
00078
00079 cleanup_activation(LUT_netlist);
00080
00081
00082
00083 }
00084
00085
00086
00087
00088 void calc_transition_density(netlist_t *netlist)
00089 {
00090 int i, j, m;
00091 activation_t *act_data;
00092
00093
00094 for (i = 0; i < netlist->num_forward_levels; i++)
00095 {
00096 for (j = 0; j < netlist->num_at_forward_level[i]; j++)
00097 {
00098
00099 nnode_t *current_node = netlist->forward_levels[i][j];
00100 act_data = (activation_t*)current_node->node_data;
00101
00102
00103 if (current_node->type == BLIF_FUNCTION)
00104 {
00105
00106 act_data->transition_density = (double*)malloc(sizeof(double));
00107
00108 if (current_node->num_input_pins == 1)
00109 {
00110
00111 nnode_t *input_node = current_node->input_pins[0]->net->driver_pin->node;
00112 int input_node_pin = current_node->input_pins[0]->net->driver_pin->pin_node_idx;
00113 activation_t *input_data = (activation_t*)input_node->node_data;
00114 oassert(input_node->unique_node_data_id == ACTIVATION);
00115
00116 if ((current_node->associated_function[0] == 0) && (current_node->associated_function[1] == 0))
00117
00118 act_data->transition_density[0] = 0;
00119 if ((current_node->associated_function[0] == 0) && (current_node->associated_function[1] == 1))
00120
00121 act_data->transition_density[0] = input_data->transition_density[input_node_pin];
00122 if ((current_node->associated_function[0] == 1) && (current_node->associated_function[1] == 0))
00123
00124 act_data->transition_density[0] = input_data->transition_density[input_node_pin];
00125 if ((current_node->associated_function[0] == 1) && (current_node->associated_function[1] == 1))
00126
00127 act_data->transition_density[0] = 0;
00128 }
00129 else
00130 {
00131 double density_val = 0.0;
00132
00133
00134 for (m = 0; m < current_node->num_input_pins; m++)
00135 {
00136 short *boolean_difference_function;
00137
00138
00139 boolean_difference_function = boolean_difference(current_node, m);
00140
00141
00142 density_val = density_val + calc_density(current_node, m, boolean_difference_function);
00143
00144
00145 free(boolean_difference_function);
00146 }
00147
00148 act_data->transition_density[0] = density_val;
00149 }
00150 }
00151 else if (current_node->type == FF_NODE)
00152 {
00153 nnode_t *input_node = current_node->input_pins[0]->net->driver_pin->node;
00154 int input_node_pin = current_node->input_pins[0]->net->driver_pin->pin_node_idx;
00155 activation_t *input_data = (activation_t*)input_node->node_data;
00156 oassert(input_node->unique_node_data_id == ACTIVATION);
00157
00158
00159 act_data->transition_density = (double*)malloc(sizeof(double));
00160 act_data->transition_density[0] = 2 * (input_data->static_probability[input_node_pin] * (1-input_data->static_probability[input_node_pin]));
00161 }
00162 else if (current_node->type == OUTPUT_NODE)
00163 {
00164 nnode_t *input_node = current_node->input_pins[0]->net->driver_pin->node;
00165 int input_node_pin = current_node->input_pins[0]->net->driver_pin->pin_node_idx;
00166 activation_t *input_data = (activation_t*)input_node->node_data;
00167 oassert(input_node->unique_node_data_id == ACTIVATION);
00168
00169
00170 act_data->transition_density = (double*)malloc(sizeof(double));
00171 act_data->transition_density[0] = input_data->static_probability[input_node_pin];
00172 }
00173 else if ((current_node->type == INPUT_NODE) || (current_node->type == VCC_NODE) || (current_node->type == GND_NODE))
00174 {
00175 oassert(current_node->unique_node_data_id == ACTIVATION);
00176 }
00177 else
00178 {
00179 oassert(FALSE);
00180 }
00181 }
00182 }
00183 }
00184
00185
00186
00187
00188 void initialize_probabilities(char *input_file, netlist_t *netlist)
00189 {
00190 int i, j;
00191 activation_t *act_data;
00192
00193 for (i = 0; i < netlist->num_forward_levels; i++)
00194 {
00195 for (j = 0; j < netlist->num_at_forward_level[i]; j++)
00196 {
00197
00198 nnode_t *current_node = netlist->forward_levels[i][j];
00199 oassert(current_node->unique_node_data_id == RESET);
00200
00201 current_node->unique_node_data_id = ACTIVATION;
00202 act_data = (activation_t*)malloc(sizeof(activation_t));
00203 current_node->node_data = (void*)act_data;
00204
00205 if (current_node->type == INPUT_NODE)
00206 {
00207 oassert(i == 0);
00208
00209 if (input_file != NULL)
00210 {
00211
00212 oassert(FALSE);
00213
00214
00215
00216
00217 i = netlist->num_forward_levels;
00218 }
00219 else
00220 {
00221
00222 act_data->static_probability = (double*)malloc(sizeof(double));
00223 act_data->transition_probability = (double*)malloc(sizeof(double));
00224 act_data->transition_density = (double*)malloc(sizeof(double));
00225
00226 act_data->static_probability[0] = DEFAULT_STATIC_PROBABILITY;
00227 act_data->transition_probability[0] = -1;
00228 act_data->transition_density[0] = DEFAULT_TRANSITION_DENSITY;
00229 }
00230 }
00231 else if (current_node->type == GND_NODE)
00232 {
00233
00234 act_data->static_probability = (double*)malloc(sizeof(double));
00235 act_data->transition_probability = (double*)malloc(sizeof(double));
00236 act_data->transition_density = (double*)malloc(sizeof(double));
00237
00238 act_data->static_probability[0] = 0.0;
00239 act_data->transition_probability[0] = -1;
00240 act_data->transition_density[0] = 0;
00241
00242 }
00243 else if (current_node->type == VCC_NODE)
00244 {
00245
00246 act_data->static_probability = (double*)malloc(sizeof(double));
00247 act_data->transition_probability = (double*)malloc(sizeof(double));
00248 act_data->transition_density = (double*)malloc(sizeof(double));
00249
00250 act_data->static_probability[0] = 1.0;
00251 act_data->transition_probability[0] = -1;
00252 act_data->transition_density[0] = 0;
00253
00254 }
00255 else if (current_node->type == FF_NODE)
00256 {
00257
00258 act_data->static_probability = (double*)malloc(sizeof(double));
00259 act_data->transition_probability = (double*)malloc(sizeof(double));
00260 act_data->transition_density = (double*)malloc(sizeof(double));
00261
00262 act_data->static_probability[0] = DEFAULT_STATIC_PROBABILITY;
00263 act_data->transition_probability[0] = -1;
00264 act_data->transition_density[0] = -1;
00265 }
00266 }
00267 }
00268 }
00269
00270
00271
00272
00273
00274
00275 void calc_probabilities_and_init_act_data(netlist_t *netlist)
00276 {
00277 int i, j, k, l, rep;
00278 activation_t *act_data;
00279
00280 for (rep = 0; rep < ACT_NUM_ITER; rep++)
00281 {
00282
00283 for (i = 0; i < netlist->num_forward_levels; i++)
00284 {
00285 for (j = 0; j < netlist->num_at_forward_level[i]; j++)
00286 {
00287
00288 nnode_t *current_node = netlist->forward_levels[i][j];
00289 act_data = (activation_t*)current_node->node_data;
00290
00291
00292 if (current_node->type == BLIF_FUNCTION)
00293 {
00294 double totalProb = 0;
00295 int function_size = pow2(current_node->num_input_pins);
00296
00297 if (rep == 0)
00298 {
00299
00300 act_data->static_probability = (double*)malloc(sizeof(double));
00301 }
00302
00303 for (k = 0; k < function_size; k++)
00304 {
00305 long long int place = 1;
00306 double probVal = 1;
00307
00308 if (current_node->associated_function[k] == 1)
00309 {
00310
00311 for (l = 0; l < current_node->num_input_pins; l++)
00312 {
00313 nnode_t *input_node = current_node->input_pins[l]->net->driver_pin->node;
00314 int input_node_pin = current_node->input_pins[l]->net->driver_pin->pin_node_idx;
00315 activation_t *input_data = (activation_t*)input_node->node_data;
00316 oassert(input_node->unique_node_data_id == ACTIVATION);
00317
00318 if ((k & place) > 0)
00319 {
00320 probVal = probVal * input_data->static_probability[input_node_pin];
00321 }
00322 else
00323 {
00324 probVal = probVal * (1-input_data->static_probability[input_node_pin]);
00325 }
00326
00327 place = place << 1;
00328 }
00329
00330 totalProb += probVal;
00331 }
00332
00333 }
00334
00335 act_data->static_probability[0] = totalProb;
00336 }
00337 else if (current_node->type == FF_NODE)
00338 {
00339 if (rep != 0)
00340 {
00341
00342 nnode_t *input_node = current_node->input_pins[0]->net->driver_pin->node;
00343 int input_node_pin = current_node->input_pins[0]->net->driver_pin->pin_node_idx;
00344 activation_t *input_data = (activation_t*)input_node->node_data;
00345 oassert(input_node->unique_node_data_id == ACTIVATION);
00346
00347 act_data->static_probability[0] = input_data->static_probability[input_node_pin];
00348 }
00349 }
00350 else if (current_node->type == OUTPUT_NODE)
00351 {
00352 nnode_t *input_node = current_node->input_pins[0]->net->driver_pin->node;
00353 int input_node_pin = current_node->input_pins[0]->net->driver_pin->pin_node_idx;
00354 activation_t *input_data = (activation_t*)input_node->node_data;
00355 oassert(input_node->unique_node_data_id == ACTIVATION);
00356
00357 if (rep == 0)
00358 {
00359
00360 act_data->static_probability = (double*)malloc(sizeof(double));
00361 }
00362
00363 act_data->static_probability[0] = input_data->static_probability[input_node_pin];
00364 }
00365 else if ((current_node->type == INPUT_NODE) || (current_node->type == VCC_NODE) || (current_node->type == GND_NODE))
00366 {
00367 oassert(current_node->unique_node_data_id == ACTIVATION);
00368 continue;
00369 }
00370 else
00371 {
00372 oassert(FALSE);
00373 }
00374
00375 if (rep == 0)
00376 {
00377
00378 act_data->transition_probability = (double*)malloc(sizeof(double)*current_node->num_output_pins);
00379 }
00380
00381 for (k = 0; k < current_node->num_output_pins; k++)
00382 {
00383 act_data->transition_probability[k] = 2 * (act_data->static_probability[k] * (1-act_data->static_probability[k]));
00384 }
00385 }
00386 }
00387 }
00388 }
00389
00390
00391
00392
00393 short *boolean_difference(nnode_t *node, int variable_spot)
00394 {
00395 int i, l;
00396 short *return_function;
00397 int function_size;
00398 long long skip_size = 1 << variable_spot;
00399 int index;
00400
00401 oassert(node->num_input_pins < sizeof (long long int)*8);
00402 oassert(node->associated_function != NULL);
00403 oassert(node->num_input_pins > 1);
00404
00405
00406 function_size = pow2(node->num_input_pins-1);
00407
00408 return_function = (short*)calloc(sizeof(short), function_size);
00409
00410 for (i = 0; i < function_size; i++)
00411 {
00412 long long int place = 1;
00413 long long int index_plus = 1;
00414 index = 0;
00415
00416
00417 for (l = 0; l < node->num_input_pins-1; l++)
00418 {
00419
00420 if (l == variable_spot)
00421 {
00422 index_plus = index_plus << 1;
00423 }
00424
00425 if ((i & place) > 0)
00426 {
00427 index += index_plus;
00428 }
00429
00430 place = place << 1;
00431 index_plus = index_plus << 1;
00432 }
00433
00434
00435 return_function[i] = node->associated_function[index] ^ node->associated_function[index+skip_size];
00436 }
00437
00438 return return_function;
00439 }
00440
00441
00442
00443
00444 double calc_density(nnode_t *node, int variable_spot, short *boolean_difference)
00445 {
00446 int i, l;
00447 int function_size;
00448 double totalProb = 0;
00449 double input_density;
00450
00451 oassert(node->num_input_pins < sizeof (long long int)*8);
00452
00453 if ((node->input_pins[variable_spot] != NULL) && (node->input_pins[variable_spot]->net->driver_pin != NULL) && (node->input_pins[variable_spot]->net->driver_pin->node != NULL))
00454 {
00455 nnode_t *input_node = node->input_pins[variable_spot]->net->driver_pin->node;
00456 int input_node_pin = node->input_pins[variable_spot]->net->driver_pin->pin_node_idx;
00457 activation_t *input_data = (activation_t*)input_node->node_data;
00458 oassert(input_node->unique_node_data_id == ACTIVATION);
00459
00460 input_density = input_data->transition_density[input_node_pin];
00461 }
00462 else
00463 {
00464 oassert(FALSE);
00465 }
00466
00467
00468 function_size = pow2(node->num_input_pins-1);
00469
00470 for (i = 0; i < function_size; i++)
00471 {
00472 long long int place = 1;
00473 double probVal = 1;
00474 int index = -1;
00475
00476 if (boolean_difference[i] == 1)
00477 {
00478
00479 for (l = 0; l < node->num_input_pins-1; l++)
00480 {
00481 nnode_t *input_node;
00482 activation_t *input_data;
00483 int input_node_pin;
00484
00485
00486 if (l == variable_spot)
00487 {
00488
00489 index += 2;
00490 }
00491 else
00492 {
00493 index ++;
00494 }
00495
00496 input_node = node->input_pins[index]->net->driver_pin->node;
00497 input_node_pin = node->input_pins[index]->net->driver_pin->pin_node_idx;
00498 input_data = (activation_t*)input_node->node_data;
00499 oassert(input_node->unique_node_data_id == ACTIVATION);
00500
00501 if ((i & place) > 0)
00502 {
00503 probVal = probVal * input_data->static_probability[input_node_pin];
00504 }
00505 else
00506 {
00507 probVal = probVal * (1-input_data->static_probability[input_node_pin]);
00508 }
00509
00510 place = place << 1;
00511 }
00512 totalProb += probVal;
00513 }
00514 }
00515
00516 oassert(totalProb <= 1.1);
00517 if (totalProb > 1)
00518 totalProb = 1;
00519
00520
00521 return totalProb * input_density;
00522 }
00523
00524
00525
00526
00527
00528
00529
00530
00531 void output_activation_file_ace_and_function_file(char *output_filename, int lut_size, netlist_t *LUT_netlist, netlist_t *CLUSTER_netlist)
00532 {
00533 char *ace_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
00534 char *ac2_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
00535 char *function_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
00536 int i, j, k, l;
00537 FILE *ace_out;
00538 FILE *ac2_out;
00539 FILE *function_out;
00540 long sc_spot;
00541 nnode_t *lut_node;
00542 activation_t *act_data;
00543
00544 sprintf(ace_file_name, "%s.ace", output_filename);
00545 sprintf(ac2_file_name, "%s.ac2", output_filename);
00546 sprintf(function_file_name, "%s.fun", output_filename);
00547
00548 ace_out = fopen(ace_file_name, "w");
00549 if (ace_out == NULL)
00550 {
00551 error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", ace_file_name);
00552 }
00553 ac2_out = fopen(ac2_file_name, "w");
00554 if (ac2_out == NULL)
00555 {
00556 error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", ac2_file_name);
00557 }
00558 function_out = fopen(function_file_name, "w");
00559 if (function_out == NULL)
00560 {
00561 error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", function_file_name);
00562 }
00563
00564
00565 for (i = 0; i < LUT_netlist->num_forward_levels; i++)
00566 {
00567 for (j = 0; j < LUT_netlist->num_at_forward_level[i]; j++)
00568 {
00569
00570 nnode_t *current_node = LUT_netlist->forward_levels[i][j];
00571 activation_t *act_data = (activation_t*)current_node->node_data;
00572
00573 if (current_node->type != OUTPUT_NODE)
00574 {
00575 for (k = 0; k < current_node->num_output_pins; k++)
00576 {
00577 if (current_node->output_pins[0]->net->num_fanout_pins != 0)
00578 {
00579
00580 fprintf(ace_out, "%s %f %f\n", current_node->name, act_data->static_probability[k], act_data->transition_density[k]);
00581 }
00582 }
00583 }
00584 else
00585 {
00586 fprintf(ace_out, "out:%s %f %f\n", current_node->name, act_data->static_probability[0], act_data->transition_density[0]);
00587 }
00588 }
00589 }
00590
00591 fclose(ace_out);
00592
00593
00594
00595
00596 for (i = 0; i < CLUSTER_netlist->num_clocks; i++)
00597 {
00598 nnode_t *cluster_node = CLUSTER_netlist->clocks[i];
00599 fprintf (ac2_out, "global_net_probability %s 0.5\n", cluster_node->name);
00600 fprintf (ac2_out, "global_net_density %s 2.0\n", cluster_node->name);
00601 }
00602
00603
00604 for (i = 0; i < CLUSTER_netlist->num_top_input_nodes; i++)
00605 {
00606 nnode_t *cluster_node = CLUSTER_netlist->top_input_nodes[i];
00607
00608 if (cluster_node->type == CLOCK_NODE)
00609 {
00610 continue;
00611 }
00612
00613
00614 if ((sc_spot = sc_lookup_string(LUT_netlist->nodes_sc, cluster_node->name)) == -1)
00615 {
00616 warning_message(ACTIVATION_ERROR, -1, -1, "Could not find %s INPUT in LUT netlist ...\n", cluster_node->name);
00617 continue;
00618 }
00619 lut_node = (nnode_t *)LUT_netlist->nodes_sc->data[sc_spot];
00620 act_data = (activation_t*)lut_node->node_data;
00621
00622 oassert(lut_node->num_output_pins == 1);
00623 fprintf (ac2_out, "intercluster_net_probability %s %f\n", cluster_node->name, act_data->static_probability[0]);
00624 fprintf (ac2_out, "intercluster_net_density %s %f\n", cluster_node->name, act_data->transition_density[0]);
00625 }
00626
00627
00628 for (i = 0; i < CLUSTER_netlist->num_top_output_nodes; i++)
00629 {
00630 nnode_t *cluster_node = CLUSTER_netlist->top_output_nodes[i];
00631
00632
00633 if ((sc_spot = sc_lookup_string(LUT_netlist->nodes_sc, cluster_node->name)) == -1)
00634 {
00635 warning_message(ACTIVATION_ERROR, -1, -1, "Could not find %s OUTPUT in LUT netlist ...\n", cluster_node->name);
00636 continue;
00637 }
00638 lut_node = (nnode_t *)LUT_netlist->nodes_sc->data[sc_spot];
00639 act_data = (activation_t*)lut_node->node_data;
00640
00641 oassert(lut_node->num_output_pins == 0);
00642 fprintf (ac2_out, "intercluster_net_probability %s %f\n", (cluster_node->name+4), act_data->static_probability[0]);
00643 fprintf (ac2_out, "intercluster_net_density %s %f\n", (cluster_node->name+4), act_data->transition_density[0]);
00644 }
00645
00646
00647 for (i = 0; i < CLUSTER_netlist->num_internal_nodes; i++)
00648 {
00649 nnode_t *cluster_node = CLUSTER_netlist->internal_nodes[i];
00650 netlist_t* internal_subblocks = cluster_node->internal_netlist;
00651
00652 if (internal_subblocks == NULL)
00653 {
00654
00655 continue;
00656 }
00657
00658
00659 for (k = 0; k < internal_subblocks->num_internal_nodes; k++)
00660 {
00661 nnode_t *current_subblock = internal_subblocks->internal_nodes[k];
00662 char *output_search_name = (char*)malloc(sizeof(char)*(strlen(current_subblock->name)+1+4));
00663 sprintf(output_search_name, "out:%s", current_subblock->name);
00664
00665 if ((sc_spot = sc_lookup_string(internal_subblocks->nodes_sc, output_search_name)) != -1)
00666 {
00667
00668
00669
00670
00671 if ((sc_spot = sc_lookup_string(LUT_netlist->nodes_sc, current_subblock->name)) == -1)
00672 {
00673 error_message(ACTIVATION_ERROR, -1, -1, "Could not find %s in LUT netlist ...\n", current_subblock->name);
00674 }
00675 lut_node = (nnode_t *)LUT_netlist->nodes_sc->data[sc_spot];
00676 act_data = (activation_t*)lut_node->node_data;
00677
00678
00679 fprintf (ac2_out, "intercluster_net_probability %s %f\n", current_subblock->name, act_data->static_probability[0]);
00680 fprintf (ac2_out, "intercluster_net_density %s %f\n", current_subblock->name, act_data->transition_density[0]);
00681 }
00682
00683 free(output_search_name);
00684 }
00685 }
00686
00687
00688 for (i = 0; i < CLUSTER_netlist->num_internal_nodes; i++)
00689 {
00690 nnode_t *cluster_node = CLUSTER_netlist->internal_nodes[i];
00691 netlist_t* internal_subblocks = cluster_node->internal_netlist;
00692
00693 if (internal_subblocks == NULL)
00694 {
00695
00696 oassert(FALSE);
00697 continue;
00698 }
00699
00700
00701 for (k = 0; k < internal_subblocks->num_internal_nodes; k++)
00702 {
00703 nnode_t *current_subblock = internal_subblocks->internal_nodes[k];
00704 char probability_string[4096];
00705 char density_string[4096];
00706 int input_active_count = 0;
00707 short is_clock = FALSE;
00708 int input_index = 0;
00709
00710 sprintf(probability_string, "subblock_probability %s", current_subblock->name);
00711 sprintf(density_string, "subblock_density %s", current_subblock->name);
00712
00713
00714 for (l = 0; l < lut_size+1; l++)
00715 {
00716 if (current_subblock->input_pins[input_index] != NULL)
00717 {
00718 nnode_t *input_node = current_subblock->input_pins[input_index]->net->driver_pin->node;
00719
00720
00721 if ((sc_spot = sc_lookup_string(LUT_netlist->nodes_sc, input_node->name)) == -1)
00722 {
00723 error_message(ACTIVATION_ERROR, -1, -1, "Could not find %s in LUT netlist ...\n", input_node->name);
00724 }
00725 lut_node = (nnode_t *)LUT_netlist->nodes_sc->data[sc_spot];
00726 act_data = (activation_t*)lut_node->node_data;
00727
00728 if (lut_node->type == CLOCK_NODE)
00729 {
00730
00731 if (l == lut_size)
00732 {
00733
00734 sprintf(probability_string, "%s %f", probability_string, act_data->static_probability[0]);
00735 sprintf(density_string, "%s %f", density_string, act_data->transition_density[0]);
00736 is_clock = TRUE;
00737 }
00738 else
00739 {
00740 sprintf(probability_string, "%s 0.0", probability_string);
00741 sprintf(density_string, "%s 0.0", density_string);
00742 }
00743 }
00744 else
00745 {
00746 sprintf(probability_string, "%s %f", probability_string, act_data->static_probability[0]);
00747 sprintf(density_string, "%s %f", density_string, act_data->transition_density[0]);
00748
00749 input_index++;
00750 }
00751
00752 input_active_count ++;
00753 }
00754 else
00755 {
00756
00757 sprintf(probability_string, "%s 0.0", probability_string);
00758 sprintf(density_string, "%s 0.0", density_string);
00759 }
00760 }
00761
00762 if (is_clock == FALSE)
00763 {
00764
00765 sprintf(probability_string, "%s 0.0", probability_string);
00766 sprintf(density_string, "%s 0.0", density_string);
00767 }
00768
00769
00770
00771 if ((sc_spot = sc_lookup_string(LUT_netlist->nodes_sc, current_subblock->name)) == -1)
00772 {
00773 error_message(ACTIVATION_ERROR, -1, -1, "Could not find %s in LUT netlist ...\n", current_subblock->name);
00774 }
00775 lut_node = (nnode_t *)LUT_netlist->nodes_sc->data[sc_spot];
00776 act_data = (activation_t*)lut_node->node_data;
00777
00778
00779 if ((lut_node->type == FF_NODE) && (input_active_count > 0))
00780 {
00781
00782
00783 activation_t *input_node_to_ff_act_data = (activation_t *)lut_node->input_pins[0]->net->driver_pin->node->node_data;
00784 sprintf(probability_string, "%s %f", probability_string, input_node_to_ff_act_data->static_probability[0]);
00785 sprintf(density_string, "%s %f", density_string, input_node_to_ff_act_data->transition_density[0]);
00786
00787
00788 oassert (lut_node->input_pins[0]->net->driver_pin->node->associated_function != NULL)
00789 fprintf(function_out, "subblock_function %s ", lut_node->name);
00790
00791 for (l = 0; l < pow2(lut_size); l++)
00792 {
00793 fprintf(function_out, "%d", lut_node->input_pins[0]->net->driver_pin->node->associated_function[l]);
00794 }
00795
00796 fprintf(function_out, "\n");
00797 }
00798 else if (lut_node->type == FF_NODE)
00799 {
00800
00801
00802 sprintf(probability_string, "%s 0.0", probability_string);
00803 sprintf(density_string, "%s 0.0", density_string);
00804
00805
00806 fprintf(function_out, "subblock_function %s ", lut_node->name);
00807 for (l = 0; l < pow2(lut_size); l++)
00808 {
00809 if (l % 2 == 0)
00810 {
00811 fprintf(function_out, "0");
00812 }
00813 else
00814 {
00815 fprintf(function_out, "1");
00816 }
00817 }
00818 fprintf(function_out, "\n");
00819 }
00820 else
00821 {
00822
00823
00824 oassert (lut_node->associated_function != NULL)
00825 fprintf(function_out, "subblock_function %s ", lut_node->name);
00826
00827 for (l = 0; l < pow2(lut_size); l++)
00828 {
00829 fprintf(function_out, "%d", lut_node->associated_function[l]);
00830 }
00831
00832 fprintf(function_out, "\n");
00833 }
00834
00835
00836 sprintf(probability_string, "%s %f", probability_string, act_data->static_probability[0]);
00837 sprintf(density_string, "%s %f", density_string, act_data->transition_density[0]);
00838
00839
00840 fprintf(ac2_out, "%s\n", probability_string);
00841 fprintf(ac2_out, "%s\n", density_string);
00842 }
00843 }
00844
00845 fclose(function_out);
00846 fclose(ac2_out);
00847 }
00848
00849
00850
00851
00852 void cleanup_activation(netlist_t *netlist)
00853 {
00854 int i, j;
00855
00856 for (i = 0; i < netlist->num_forward_levels; i++)
00857 {
00858 for (j = 0; j < netlist->num_at_forward_level[i]; j++)
00859 {
00860
00861 nnode_t *current_node = netlist->forward_levels[i][j];
00862 activation_t *act_data = (activation_t*)current_node->node_data;
00863 oassert(act_data != NULL);
00864
00865 if (act_data->static_probability != NULL)
00866 free(act_data->static_probability);
00867 if (act_data->transition_density != NULL)
00868 free(act_data->transition_density);
00869 if (act_data->transition_probability != NULL)
00870 free(act_data->transition_probability);
00871
00872 free(act_data);
00873 current_node->unique_node_data_id = RESET;
00874 }
00875 }
00876 }