@@ -33,6 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
33
33
#include "activity_estimation.h"
34
34
#include "netlist_check.h"
35
35
36
+
36
37
#define DEFAULT_STATIC_PROBABILITY .5
37
38
#define DEFAULT_TRANSITION_DENSITY .5
38
39
@@ -102,7 +103,7 @@ void calc_transition_density(netlist_t *netlist)
102
103
if (current_node -> type == BLIF_FUNCTION )
103
104
{
104
105
/* only one output */
105
- act_data -> transition_density = (double * )malloc ( sizeof (double )); // only one output
106
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double )); // only one output
106
107
107
108
if (current_node -> num_input_pins == 1 )
108
109
{
@@ -155,7 +156,7 @@ void calc_transition_density(netlist_t *netlist)
155
156
oassert (input_node -> unique_node_data_id == ACTIVATION );
156
157
157
158
/* just store since allocated in the initialization */
158
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
159
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
159
160
act_data -> transition_density [0 ] = 2 * (input_data -> static_probability [input_node_pin ] * (1 - input_data -> static_probability [input_node_pin ]));
160
161
}
161
162
else if (current_node -> type == OUTPUT_NODE )
@@ -166,7 +167,7 @@ void calc_transition_density(netlist_t *netlist)
166
167
oassert (input_node -> unique_node_data_id == ACTIVATION );
167
168
168
169
/* allocate and stre through */
169
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
170
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
170
171
act_data -> transition_density [0 ] = input_data -> static_probability [input_node_pin ];
171
172
}
172
173
else if ((current_node -> type == INPUT_NODE ) || (current_node -> type == VCC_NODE ) || (current_node -> type == GND_NODE ))
@@ -198,7 +199,7 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
198
199
oassert (current_node -> unique_node_data_id == RESET );
199
200
200
201
current_node -> unique_node_data_id = ACTIVATION ;
201
- act_data = (activation_t * )malloc ( sizeof (activation_t ));
202
+ act_data = (activation_t * )calloc ( 1 , sizeof (activation_t ));
202
203
current_node -> node_data = (void * )act_data ;
203
204
204
205
if (current_node -> type == INPUT_NODE )
@@ -218,9 +219,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
218
219
else
219
220
{
220
221
/* initialize all the initial probabilities */
221
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
222
- act_data -> transition_probability = (double * )malloc ( sizeof (double ));
223
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
222
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
223
+ act_data -> transition_probability = (double * )calloc ( 1 , sizeof (double ));
224
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
224
225
225
226
act_data -> static_probability [0 ] = DEFAULT_STATIC_PROBABILITY ;
226
227
act_data -> transition_probability [0 ] = -1 ;
@@ -230,9 +231,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
230
231
else if (current_node -> type == GND_NODE )
231
232
{
232
233
/* initialize all the initial probabilities */
233
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
234
- act_data -> transition_probability = (double * )malloc ( sizeof (double ));
235
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
234
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
235
+ act_data -> transition_probability = (double * )calloc ( 1 , sizeof (double ));
236
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
236
237
237
238
act_data -> static_probability [0 ] = 0.0 ;
238
239
act_data -> transition_probability [0 ] = -1 ;
@@ -242,9 +243,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
242
243
else if (current_node -> type == VCC_NODE )
243
244
{
244
245
/* initialize all the initial probabilities */
245
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
246
- act_data -> transition_probability = (double * )malloc ( sizeof (double ));
247
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
246
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
247
+ act_data -> transition_probability = (double * )calloc ( 1 , sizeof (double ));
248
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
248
249
249
250
act_data -> static_probability [0 ] = 1.0 ;
250
251
act_data -> transition_probability [0 ] = -1 ;
@@ -254,9 +255,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
254
255
else if (current_node -> type == FF_NODE )
255
256
{
256
257
/* initialize all the initial probabilities */
257
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
258
- act_data -> transition_probability = (double * )malloc ( sizeof (double ));
259
- act_data -> transition_density = (double * )malloc ( sizeof (double ));
258
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
259
+ act_data -> transition_probability = (double * )calloc ( 1 , sizeof (double ));
260
+ act_data -> transition_density = (double * )calloc ( 1 , sizeof (double ));
260
261
261
262
act_data -> static_probability [0 ] = DEFAULT_STATIC_PROBABILITY ;
262
263
act_data -> transition_probability [0 ] = -1 ;
@@ -296,7 +297,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
296
297
if (rep == 0 )
297
298
{
298
299
/* only one output */
299
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
300
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
300
301
}
301
302
302
303
for (k = 0 ; k < function_size ; k ++ )
@@ -356,7 +357,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
356
357
if (rep == 0 )
357
358
{
358
359
/* only one output */
359
- act_data -> static_probability = (double * )malloc ( sizeof (double ));
360
+ act_data -> static_probability = (double * )calloc ( 1 , sizeof (double ));
360
361
}
361
362
362
363
act_data -> static_probability [0 ] = input_data -> static_probability [input_node_pin ];
@@ -374,7 +375,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
374
375
if (rep == 0 )
375
376
{
376
377
/* calculate transition probability */
377
- act_data -> transition_probability = (double * )malloc ( sizeof ( double ) * current_node -> num_output_pins );
378
+ act_data -> transition_probability = (double * )calloc ( current_node -> num_output_pins , sizeof ( double ) );
378
379
}
379
380
380
381
for (k = 0 ; k < current_node -> num_output_pins ; k ++ )
@@ -404,7 +405,7 @@ short *boolean_difference(nnode_t *node, int variable_spot)
404
405
/* calculate the size of the boolean difference */
405
406
function_size = pow2 (node -> num_input_pins - 1 );
406
407
407
- return_function = (short * )calloc (sizeof (short ), function_size );
408
+ return_function = (short * )calloc (function_size , sizeof (short ));
408
409
409
410
for (i = 0 ; i < function_size ; i ++ )
410
411
{
@@ -529,9 +530,9 @@ double calc_density(nnode_t *node, int variable_spot, short *boolean_difference)
529
530
*-------------------------------------------------------------------------------------------*/
530
531
void output_activation_file_ace_and_function_file (char * output_filename , int lut_size , netlist_t * LUT_netlist , netlist_t * CLUSTER_netlist )
531
532
{
532
- char * ace_file_name = (char * )malloc ( sizeof ( char ) * ( strlen (output_filename )+ 4 + 1 ));
533
- char * ac2_file_name = (char * )malloc ( sizeof ( char ) * ( strlen (output_filename )+ 4 + 1 ));
534
- char * function_file_name = (char * )malloc ( sizeof ( char ) * ( strlen (output_filename )+ 4 + 1 ));
533
+ char * ace_file_name = (char * )calloc (( strlen (output_filename )+ 4 + 1 ), sizeof ( char ));
534
+ char * ac2_file_name = (char * )calloc (( strlen (output_filename )+ 4 + 1 ), sizeof ( char ));
535
+ char * function_file_name = (char * )calloc (( strlen (output_filename )+ 4 + 1 ), sizeof ( char ));
535
536
int i , j , k , l ;
536
537
FILE * ace_out ;
537
538
FILE * ac2_out ;
@@ -545,20 +546,22 @@ void output_activation_file_ace_and_function_file(char *output_filename, int lut
545
546
sprintf (function_file_name , "%s.fun" , output_filename );
546
547
547
548
ace_out = fopen (ace_file_name , "w" );
548
- if (ace_out == NULL )
549
- {
549
+ if (!ace_out ){
550
550
error_message (ACTIVATION_ERROR , -1 , -1 , "Could not open output file %s\n" , ace_file_name );
551
551
}
552
+ free (ace_out );
553
+
552
554
ac2_out = fopen (ac2_file_name , "w" );
553
- if (ac2_out == NULL )
554
- {
555
+ if (!ac2_out ){
555
556
error_message (ACTIVATION_ERROR , -1 , -1 , "Could not open output file %s\n" , ac2_file_name );
556
557
}
558
+ free (ac2_out );
559
+
557
560
function_out = fopen (function_file_name , "w" );
558
- if (function_out == NULL )
559
- {
561
+ if (!function_out ){
560
562
error_message (ACTIVATION_ERROR , -1 , -1 , "Could not open output file %s\n" , function_file_name );
561
563
}
564
+ free (function_out );
562
565
563
566
/* Go through the LUT netlist and print out the ace files */
564
567
for (i = 0 ; i < LUT_netlist -> num_forward_levels ; i ++ )
@@ -658,7 +661,7 @@ void output_activation_file_ace_and_function_file(char *output_filename, int lut
658
661
for (k = 0 ; k < internal_subblocks -> num_internal_nodes ; k ++ )
659
662
{
660
663
nnode_t * current_subblock = internal_subblocks -> internal_nodes [k ];
661
- char * output_search_name = (char * )malloc ( sizeof ( char ) * ( strlen (current_subblock -> name )+ 1 + 4 ));
664
+ char * output_search_name = (char * )calloc (( strlen (current_subblock -> name )+ 1 + 4 ), sizeof ( char ));
662
665
sprintf (output_search_name , "out:%s" , current_subblock -> name );
663
666
664
667
if ((sc_spot = sc_lookup_string (internal_subblocks -> nodes_sc , output_search_name )) != -1 )
0 commit comments