__ses_xchg_cx()
authoryu.dongliang <18588496441@163.com>
Mon, 6 Nov 2023 07:50:03 +0000 (15:50 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 6 Nov 2023 07:50:03 +0000 (15:50 +0800)
ses_layout.c

index 20db5a56f4a4ed8adc8ee6bfd5ef3a7b87fc70c1..0042dd26af7f18bbf05048f83087e6a619488aca 100644 (file)
@@ -1094,10 +1094,9 @@ static inline void __ses_xchg_cx2(ScfEcomponent* c0, ScfEcomponent* c1)
        int      cx0 = c0->x;
        int      cx1 = c1->x;
 
-       scf_logw("c%ld <--> c%ld, color: %ld, %ld, cx: %d, %d\n", c0->id, c1->id, c0->color, c1->color, c0->x, c1->x);
        SCF_XCHG(c0->x, c1->x);
 
-       scf_loge("c%ld <--> c%ld, color: %ld, %ld, cx: %d, %d\n", c0->id, c1->id, c0->color, c1->color, c0->x, c1->x);
+       scf_logw("c%ld <--> c%ld, color: %ld, %ld, cx: %d, %d\n", c0->id, c1->id, c0->color, c1->color, c0->x, c1->x);
 
        for (i = 0; i < c0->n_pins; i++) {
                p         = c0->pins[i];
@@ -1121,66 +1120,106 @@ static void __ses_xchg_cx(ScfEfunction* f, int d)
        size_t k;
        size_t n;
 
-       do {
-               n = 0;
+       k = 0;
 
-               for (i = 0; i < f->n_components - 1; i++) {
-                       c0 =        f->components[i];
+       for (i = 0; i < f->n_components - 1; i++) {
+               c0 =        f->components[i];
 
-                       int y0 = INT_MAX;
-                       int y1 = INT_MIN;
+               int m0 = 0;
+               int n0 = 0;
 
-                       int m  = (c0->color - 1) % 2;
+               if (c0->color > 0) {
+                       m0 = (c0->color - 1) / 2;
+                       n0 = (c0->color - 1) % 2;
+               }
 
-                       for (k = 0; k < c0->n_pins; k++) {
-                               p  =        c0->pins[k];
+               for (j = i + 1; j < f->n_components; j++) {
+                       c1 =            f->components[j];
 
-                               if (y0 > p->y)
-                                       y0 = p->y;
+                       int y2 = INT_MAX;
+                       int y3 = INT_MIN;
+                       int m1 = 0;
+                       int n1 = 0;
 
-                               if (y1 < p->y)
-                                       y1 = p->y;
+                       if (c1->color > 0) {
+                               m1 = (c1->color - 1) / 2;
+                               n1 = (c1->color - 1) % 2;
                        }
 
-                       if (y1 - y0 <= d)
+                       if (m0 != m1)
                                continue;
 
-                       for (j = i + 1; j < f->n_components; j++) {
-                               c1 =            f->components[j];
+                       if ((n0 < n1 && c0->x > c1->x) || (n0 > n1 && c0->x < c1->x))
+                               __ses_xchg_cx2(c0, c1);
+               }
+       }
 
-                               if ((c0->color != c1->color) && (0 != c1->color || c0->color > 2))
-                                       continue;
+       for (i = 0; i < f->n_components - 1; i++) {
+               c0 =        f->components[i];
 
-                               int y2 = INT_MAX;
-                               int y3 = INT_MIN;
+               int y0 = INT_MAX;
+               int y1 = INT_MIN;
+               int m0 = 0;
+               int n0 = 0;
 
-                               for (k = 0; k < c1->n_pins; k++) {
-                                       p  =        c1->pins[k];
+               if (c0->color > 0) {
+                       m0 = (c0->color - 1) / 2;
+                       n0 = (c0->color - 1) % 2;
+               }
 
-                                       if (y2 > p->y)
-                                               y2 = p->y;
+               for (k = 0; k < c0->n_pins; k++) {
+                       p  =        c0->pins[k];
 
-                                       if (y3 < p->y)
-                                               y3 = p->y;
-                               }
+                       if (y0 > p->y)
+                               y0 = p->y;
 
-                               if ((y0 <= y2 && y3 < y1) || (y0 < y2 && y3 <= y1)) {
+                       if (y1 < p->y)
+                               y1 = p->y;
+               }
 
-                                       if ((0 == m && c0->x > c1->x) || (1 == m && c0->x < c1->x)) {
-                                               __ses_xchg_cx2(c0, c1);
-                                               n++;
-                                       }
+               if (y1 - y0 <= d)
+                       continue;
 
-                               } else if ((y2 <= y0 && y1 < y3) || (y2 < y0 && y1 <= y3)) {
+               for (j = i + 1; j < f->n_components; j++) {
+                       c1 =            f->components[j];
 
-                                       if ((0 == m && c0->x < c1->x) || (1 == m && c0->x > c1->x)) {
-                                               __ses_xchg_cx2(c0, c1);
-                                               n++;
-                                       }
-                               }
+                       int y2 = INT_MAX;
+                       int y3 = INT_MIN;
+                       int m1 = 0;
+                       int n1 = 0;
+
+                       if (c1->color > 0) {
+                               m1 = (c1->color - 1) / 2;
+                               n1 = (c1->color - 1) % 2;
+                       }
+
+                       if (m0 != m1 || n0 != n1)
+                               continue;
+
+                       scf_logi("c%ld <--> c%ld, color: %ld, %ld, cx: %d, %d\n", c0->id, c1->id, c0->color, c1->color, c0->x, c1->x);
+
+                       for (k = 0; k < c1->n_pins; k++) {
+                               p  =        c1->pins[k];
+
+                               if (y2 > p->y)
+                                       y2 = p->y;
+
+                               if (y3 < p->y)
+                                       y3 = p->y;
+                       }
+
+                       if ((y0 <= y2 && y3 < y1) || (y0 < y2 && y3 <= y1)) {
+
+                               if ((0 == n0 && c0->x > c1->x) || (1 == n0 && c0->x < c1->x))
+                                       __ses_xchg_cx2(c0, c1);
+
+                       } else if ((y2 <= y0 && y1 < y3) || (y2 < y0 && y1 <= y3)) {
+
+                               if ((0 == n0 && c0->x < c1->x) || (1 == n0 && c0->x > c1->x))
+                                       __ses_xchg_cx2(c0, c1);
                        }
                }
-       } while (n > 0);
+       }
 }
 
 static void __ses_layout_cx(ScfEfunction* f, int d)