@@ -451,13 +451,13 @@ void split_adder_for_sub(nnode_t* nodeo, int a, int b, int sizea, int sizeb, int
451451 }
452452 }
453453
454- for (i = offset; i < count; i++) {
454+ for (i = offset; i < count - 1 ; i++) {
455455 num = (b + 1 ) - i * sizeb;
456456 if (num > sizeb)
457457 num = sizeb;
458458
459459 for (j = 0 ; j < num; j++) {
460- if (i == count - 1 && flag == 1 ) {
460+ if (i == count - 2 && flag == 1 ) {
461461 /* If the input pin of not gate connects to gnd, replacing the input pin and the not gate with vcc;
462462 * if the input pin of not gate connects to vcc, replacing the input pin and the not gate with gnd.*/
463463 /* connecting untouched nets in the netlist creation to the pad node */
@@ -501,8 +501,8 @@ void split_adder_for_sub(nnode_t* nodeo, int a, int b, int sizea, int sizeb, int
501501 }
502502
503503 if ((flag == 0 || count > 1 ) && !configuration.adder_cin_global ) {
504- // connect the a[0] of first adder node to ground , and b[0] of first adder node to vcc
505- connect_nodes (netlist->gnd_node , 0 , node[0 ], 0 );
504+ // connect the a[0] of first adder node to vcc , and b[0] of first adder node to vcc
505+ connect_nodes (netlist->vcc_node , 0 , node[0 ], 0 );
506506 connect_nodes (netlist->vcc_node , 0 , node[0 ], sizea);
507507 // hang the first sumout
508508 node[0 ]->output_pins [1 ] = allocate_npin ();
@@ -573,6 +573,8 @@ void split_adder_for_sub(nnode_t* nodeo, int a, int b, int sizea, int sizeb, int
573573 // Pad outputs with a unique and descriptive name to avoid collisions.
574574 node[count - 1 ]->output_pins [0 ]->name = append_string (" " , " %s~dummy_output~%d~%d" , node[(count - 1 )]->name , (count - 1 ), 0 );
575575 // connect_nodes(node[count - 1], (node[(count - 1)]->num_output_pins - 1), netlist->gnd_node, 0);
576+ connect_nodes (netlist->vcc_node , 0 , node[count - 1 ], 0 );
577+ connect_nodes (netlist->gnd_node , 0 , node[count - 1 ], sizea);
576578 // }
577579
578580 /* Freeing the old node! */
@@ -626,17 +628,15 @@ void iterate_adders_for_sub(netlist_t* netlist) {
626628 b = node->input_port_sizes [0 ];
627629 num = (a >= b) ? a : b;
628630
629- if (num >= min_threshold_adder) {
630- // how many subtractors base on a can split
631- if ((a + 1 ) % sizea == 0 )
632- counta = (a + offset) / sizea;
633- else
634- counta = (a + 1 ) / sizea + 1 ;
635- // how many subtractors base on b can split
636- if ((b + 1 ) % sizeb == 0 )
637- countb = (b + offset) / sizeb;
638- else
639- countb = (b + 1 ) / sizeb + 1 ;
631+ if (num >= min_threshold_adder && num >= min_add) {
632+ // if the first cin in a chain is fed by a global input (offset = 0) the adder width is the
633+ // input width + 1 (to pass the last cout -> sumout) divided by size of the adder input ports
634+ // otherwise (offset = 1) a dummy adder is added to the chain to feed the first cin with gnd
635+ // how many adders a can split
636+ counta = (a + 1 ) / sizea + offset;
637+ // how many adders b can split
638+ countb = (b + 1 ) / sizeb + offset;
639+ // how many adders need to be split
640640 // how many subtractors need to be split
641641 if (counta >= countb)
642642 count = counta;
0 commit comments