Skip to content

Commit aba95fd

Browse files
committed
Bug fix: float number comparison in various functions
1 parent 6efb192 commit aba95fd

File tree

3 files changed

+88
-69
lines changed

3 files changed

+88
-69
lines changed

include/macros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#ifndef _3DICE_MACROS_H_
4040
#define _3DICE_MACROS_H_
41-
41+
#define EPSILON 1e-6
4242
/*! \file macros.h */
4343

4444
#ifdef __cplusplus

sources/ic_element.c

+24-11
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,35 @@ bool check_intersection
182182
if (icelement_a == icelement_b)
183183

184184
return false ;
185+
ChipDimension_t minkowski_x1 = icelement_a->SW_X - icelement_b->SW_X - icelement_b->Length ;
186+
ChipDimension_t minkowski_y1 = icelement_a->SW_Y - icelement_b->SW_Y - icelement_b->Width ;
187+
ChipDimension_t minkowski_x2 = icelement_a->SW_X + icelement_a->Length - icelement_b->SW_X ;
188+
ChipDimension_t minkowski_y2 = icelement_a->SW_Y + icelement_a->Width - icelement_b->SW_Y ;
189+
if (fabs(minkowski_x1 * minkowski_x2) > EPSILON && fabs(minkowski_y1 * minkowski_y2) > EPSILON )
190+
{
191+
if (minkowski_x1 * minkowski_x2 < 0 && minkowski_y1 * minkowski_y2 < 0)
192+
return true ;
193+
}
185194

186-
if ( (icelement_a->SW_X + icelement_a->Length)
187-
<= icelement_b->SW_X
188-
|| icelement_a->SW_X
189-
>= (icelement_b->SW_X + icelement_b->Length))
195+
return false ;
196+
190197

191-
return false ;
198+
// if ( (icelement_a->SW_X + icelement_a->Length)
199+
// <= icelement_b->SW_X
200+
// || icelement_a->SW_X
201+
// >= (icelement_b->SW_X + icelement_b->Length))
192202

193-
if ( (icelement_a->SW_Y + icelement_a->Width)
194-
<= icelement_b->SW_Y
195-
|| icelement_a->SW_Y
196-
>= (icelement_b->SW_Y + icelement_b->Width))
203+
// return false ;
197204

198-
return false ;
205+
// if ( (icelement_a->SW_Y + icelement_a->Width)
206+
// <= icelement_b->SW_Y
207+
// || icelement_a->SW_Y
208+
// >= (icelement_b->SW_Y + icelement_b->Width))
209+
210+
// return false ;
211+
212+
// return true ;
199213

200-
return true ;
201214
}
202215

203216
/******************************************************************************/

sources/thermal_data.c

+63-57
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ void get_connections_in_layer
686686
// first compute the Minkowski difference
687687
get_minkowski_difference(minkowski_diff, position_info_ptr, i_x, i_y);
688688
// if two rectangles interconnect with each other, Minkowski difference should contain the origin point (0, 0)
689-
if (minkowski_diff[0] == 0 || minkowski_diff[1] == 0 || minkowski_diff[2] == 0 || minkowski_diff[3] == 0)
689+
if (fabs(minkowski_diff[0]) < EPSILON || fabs(minkowski_diff[1]) < EPSILON || fabs(minkowski_diff[2]) < EPSILON || fabs(minkowski_diff[3]) < EPSILON)
690690
{
691691
// furthermore, it should cross the origin point
692692
if (minkowski_diff[0] * minkowski_diff[2] + minkowski_diff[1] * minkowski_diff[3] < 0)
@@ -698,14 +698,14 @@ void get_connections_in_layer
698698
new_connection.node1_layer = layer_index;
699699
new_connection.node2_layer = layer_index;
700700
// Find the interconnect length
701-
if (minkowski_diff[0] * minkowski_diff[2] == 0)
701+
if (fabs(minkowski_diff[0] * minkowski_diff[2]) < EPSILON)
702702
{
703703
if (layer_type == 1 || layer_type == 2 || layer_type == 3)
704704
continue;
705705
new_connection.value = (fabs(minkowski_diff[1])<=fabs(minkowski_diff[3])) ? fabs(minkowski_diff[1]) : fabs(minkowski_diff[3]);
706706
new_connection.direction = 1; //two nodes interconect in direction x
707707
}
708-
else if (minkowski_diff[1] * minkowski_diff[3] == 0)
708+
else if (fabs(minkowski_diff[1] * minkowski_diff[3]) < EPSILON)
709709
{
710710
if (layer_type == 1 || layer_type == 3)
711711
continue;
@@ -770,24 +770,26 @@ void get_connections_between_layer
770770
// first compute Minkowski difference
771771
get_minkowski_difference(minkowski_diff, position_info_ptr, i_x, i_y);
772772
// Minkowski difference should contain the origin point (0, 0) if two cells have overlap area
773-
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
774-
{
775-
// add the connection information to the connections variable
776-
Connection_t new_connection;
777-
connection_init(&new_connection);
778-
new_connection.node1 = i_x;
779-
new_connection.node2 = i_y;
780-
new_connection.node1_layer = layer_index-1;
781-
new_connection.node2_layer = layer_index;
782-
783-
// overlap area is the minum area
784-
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
785-
786-
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
787-
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
788-
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
789-
// add the connection information to the connections variable
790-
connection_list_insert_end(connections_list, &new_connection);
773+
if (fabs(minkowski_diff[0] * minkowski_diff[2]) > EPSILON && fabs(minkowski_diff[1] * minkowski_diff[3]) > EPSILON ){
774+
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
775+
{
776+
// add the connection information to the connections variable
777+
Connection_t new_connection;
778+
connection_init(&new_connection);
779+
new_connection.node1 = i_x;
780+
new_connection.node2 = i_y;
781+
new_connection.node1_layer = layer_index-1;
782+
new_connection.node2_layer = layer_index;
783+
784+
// overlap area is the minum area
785+
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
786+
787+
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
788+
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
789+
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
790+
// add the connection information to the connections variable
791+
connection_list_insert_end(connections_list, &new_connection);
792+
}
791793
}
792794
}
793795
}
@@ -806,24 +808,26 @@ void get_connections_between_layer
806808
// first compute Minkowski difference
807809
get_minkowski_difference(minkowski_diff, position_info_ptr, i_x, i_y);
808810
// Minkowski difference should contain the origin point (0, 0) if two cells have overlap area
809-
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
810-
{
811-
// add the connection information to the connections variable
812-
Connection_t new_connection;
813-
connection_init(&new_connection);
814-
new_connection.node1 = i_x;
815-
new_connection.node2 = i_y;
816-
new_connection.node1_layer = layer_index-1;
817-
new_connection.node2_layer = layer_index;
818-
819-
// overlap area is the minum area
820-
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
821-
822-
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
823-
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
824-
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
825-
// add the connection information to the connections variable
826-
connection_list_insert_end(connections_list, &new_connection);
811+
if (fabs(minkowski_diff[0] * minkowski_diff[2]) > EPSILON && fabs(minkowski_diff[1] * minkowski_diff[3]) > EPSILON ){
812+
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
813+
{
814+
// add the connection information to the connections variable
815+
Connection_t new_connection;
816+
connection_init(&new_connection);
817+
new_connection.node1 = i_x;
818+
new_connection.node2 = i_y;
819+
new_connection.node1_layer = layer_index-1;
820+
new_connection.node2_layer = layer_index;
821+
822+
// overlap area is the minum area
823+
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
824+
825+
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
826+
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
827+
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
828+
// add the connection information to the connections variable
829+
connection_list_insert_end(connections_list, &new_connection);
830+
}
827831
}
828832
}
829833
}
@@ -844,24 +848,26 @@ void get_connections_between_layer
844848
// first compute Minkowski difference
845849
get_minkowski_difference(minkowski_diff, position_info_ptr, i_x, i_y);
846850
// Minkowski difference should contain the origin point (0, 0) if two cells have overlap area
847-
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
848-
{
849-
// add the connection information to the connections variable
850-
Connection_t new_connection;
851-
connection_init(&new_connection);
852-
new_connection.node1 = i_x;
853-
new_connection.node2 = i_y;
854-
new_connection.node1_layer = layer_index-1;
855-
new_connection.node2_layer = layer_index;
856-
857-
// overlap area is the minum area
858-
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
859-
860-
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
861-
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
862-
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
863-
// add the connection information to the connections variable
864-
connection_list_insert_end(connections_list, &new_connection);
851+
if (fabs(minkowski_diff[0] * minkowski_diff[2]) > EPSILON && fabs(minkowski_diff[1] * minkowski_diff[3]) > EPSILON ){
852+
if (minkowski_diff[0] * minkowski_diff[2] < 0 && minkowski_diff[1] * minkowski_diff[3] < 0)
853+
{
854+
// add the connection information to the connections variable
855+
Connection_t new_connection;
856+
connection_init(&new_connection);
857+
new_connection.node1 = i_x;
858+
new_connection.node2 = i_y;
859+
new_connection.node1_layer = layer_index-1;
860+
new_connection.node2_layer = layer_index;
861+
862+
// overlap area is the minum area
863+
new_connection.value = get_overlap_area(minkowski_diff, position_info_ptr, i_x, i_y);
864+
865+
new_connection.direction = 0; //connect direction is Z(=0) for two nodes in different layers;
866+
// printf("Node%d in layer %d <-> Node%d in layer %d\n", new_connection.node1, new_connection.node1_layer, new_connection.node2, new_connection.node2_layer) ;
867+
// printf("Direction %d, Value %f\n", new_connection.direction, new_connection.value) ;
868+
// add the connection information to the connections variable
869+
connection_list_insert_end(connections_list, &new_connection);
870+
}
865871
}
866872
}
867873
}

0 commit comments

Comments
 (0)