tmp
authoryu.dongliang <18588496441@163.com>
Mon, 30 Oct 2023 09:40:44 +0000 (17:40 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 30 Oct 2023 09:40:44 +0000 (17:40 +0800)
ses_layout.c

index 32d7939c81ac6035d6853dab1870cd178a2afb9a..635e659affd3d7794239c74927a41f50e5200c80 100644 (file)
@@ -687,6 +687,33 @@ static void __ses_xchg_components(ScfEfunction* f, int d)
        }
 }
 
+static inline void __ses_flip_neg(ScfEcomponent* c)
+{
+       ScfEpin* p;
+       size_t   i;
+
+       for (i = 0; i < c->n_pins; i++) {
+               p  =        c->pins[i];
+
+               if (p->x > 0)
+                       p->x = -p->x;
+       }
+}
+
+static inline void __ses_flip_pos(ScfEcomponent* c)
+{
+       ScfEpin* p;
+       size_t   i;
+
+       for (i = 0; i < c->n_pins; i++) {
+               p  =        c->pins[i];
+
+               if (p->x < 0)
+                       p->x = -p->x;
+       }
+}
+
+
 static void __ses_de_cross(ScfEfunction* f, int d)
 {
        ScfEcomponent* c0;
@@ -735,23 +762,13 @@ static void __ses_de_cross(ScfEfunction* f, int d)
 
                                                        if (y0 < y2 && y2 < y1 && y1 < y3) {
 
-                                                               if (p2->x > 0) {
-                                                                       if (p0->x > 0)
-                                                                               p0->x = -p0->x;
-
-                                                                       if (p1->x > 0)
-                                                                               p1->x = -p1->x;
-                                                               }
+                                                               if (p2->x > 0)
+                                                                       __ses_flip_neg(c0);
 
                                                        } else if (y2 < y0 && y0 < y3 && y3 < y1) {
 
-                                                               if (p0->x > 0) {
-                                                                       if (p2->x > 0)
-                                                                               p2->x = -p2->x;
-
-                                                                       if (p3->x > 0)
-                                                                               p3->x = -p3->x;
-                                                               }
+                                                               if (p0->x > 0)
+                                                                       __ses_flip_neg(c1);
                                                        }
                                                }
                                        }
@@ -809,17 +826,93 @@ static void __ses_de_cross(ScfEfunction* f, int d)
                                }
                        }
 
-                       if (p0->x < 0)
-                               p0->x = -p0->x;
-
-                       if (p1->x < 0)
-                               p1->x = -p1->x;
+                       __ses_flip_pos(c0);
                }
 next:
                c0 = NULL;
        }
 }
 
+static inline void __ses_xchg_cx2(ScfEcomponent* c0, ScfEcomponent* c1)
+{
+       ScfEpin* p;
+       size_t   i;
+
+       int      cx0 = c0->x;
+       int      cx1 = c1->x;
+
+       SCF_XCHG(c0->x, c1->x);
+
+       for (i = 0; i < c0->n_pins; i++) {
+               p         = c0->pins[i];
+
+               if (i < 2)
+                       p->x = c0->x;
+               else
+                       p->x = c0->x - cx0;
+       }
+
+       for (i = 0; i < c1->n_pins; i++) {
+               p         = c1->pins[i];
+
+               if (i < 2)
+                       p->x = c1->x;
+               else
+                       p->x = c1->x - cx1;
+       }
+}
+
+static inline void __ses_xchg_cx(ScfEfunction* f, int d)
+{
+       ScfEcomponent* c0;
+       ScfEcomponent* c1;
+       ScfEpin*       p0;
+       ScfEpin*       p1;
+       ScfEpin*       p2;
+       ScfEpin*       p3;
+
+       size_t i;
+       size_t j;
+
+       for (i = 0; i < f->n_components - 1; i++) {
+               c0 =        f->components[i];
+
+               p0 =  c0->pins[0];
+               p1 =  c0->pins[1];
+
+               if (p0->y - p1->y <= d && p0->y - p1->y >= -d)
+                       continue;
+
+               int y0 = p0->y < p1->y ? p0->y : p1->y;
+               int y1 = p0->y < p1->y ? p1->y : p0->y;
+
+               for (j = i + 1; j < f->n_components; j++) {
+                       c1 =            f->components[j];
+
+                       if ((c0->x < 0 && c1->x > 0) || (c0->x > 0 && c1->x < 0))
+                               continue;
+
+                       p2 =  c1->pins[0];
+                       p3 =  c1->pins[1];
+
+                       if (p2->y - p3->y <= d && p2->y - p3->y >= -d)
+                               continue;
+
+                       int y2 = p2->y < p3->y ? p2->y : p3->y;
+                       int y3 = p2->y < p3->y ? p3->y : p2->y;
+
+                       if (y0 < y2 && y3 < y1) {
+                               if ((c0->x < 0 && c0->x > c1->x) || (c0->x > 0 && c0->x < c1->x))
+                                       __ses_xchg_cx2(c0, c1);
+
+                       } else if (y2 < y0 && y1 < y3) {
+                               if ((c0->x < 0 && c0->x < c1->x) || (c0->x > 0 && c0->x > c1->x))
+                                       __ses_xchg_cx2(c0, c1);
+                       }
+               }
+       }
+}
+
 int ses_layout_function(ScfEfunction* f, int d)
 {
        ScfEcomponent* c;