__ses_de_cross()
authoryu.dongliang <18588496441@163.com>
Sat, 11 Nov 2023 08:49:06 +0000 (16:49 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 11 Nov 2023 08:49:06 +0000 (16:49 +0800)
ses_layout.c

index 4c17f1f863e144bdfa9a39684243d5c7ee6cf966..c279985819cf98bf68a4c19d3607d2cef92886d8 100644 (file)
@@ -1133,6 +1133,46 @@ next:
        return 0;
 }
 
+static void decross_mov_before(ScfEfunction* f, int d, intptr_t dst, intptr_t src)
+{
+       ScfEcomponent* c;
+       ScfEline*      el;
+       ScfEpin*       p;
+       ScfLine*       l;
+
+       intptr_t i;
+       intptr_t j;
+       intptr_t k;
+
+       intptr_t min = dst < src ? dst : src;
+       intptr_t max = dst > src ? dst : src;
+
+       int y0 = f->elines[min]->lines[0]->y0;
+
+       eline_mov_before(f, dst, src);
+
+       for (i = min; i <= max; i++) {
+               el = f->elines[i];
+
+               int y = y0 + (i - min) * d;
+
+               for (j = 0; j < el->n_lines; j++) {
+                       l  =        el->lines[j];
+
+                       l->y0 = y;
+                       l->y1 = y;
+               }
+
+               for (j = 0; j + 1 < el->n_pins; j += 2) {
+
+                       c  = f->components[el->pins[j]];
+                       p  = c->pins      [el->pins[j + 1]];
+
+                       p->y = y;
+               }
+       }
+}
+
 static int __ses_de_cross(ScfEfunction* f, int d)
 {
        ScfEcomponent* c;
@@ -1173,7 +1213,8 @@ static int __ses_de_cross(ScfEfunction* f, int d)
        for (j = 1; j <= N; j++)
                scf_vector_add(colors, (void*)j);
 
-       for (j = N; j >= 2; j--) {
+       int try = 0;
+       for (j = N; j >= 2; ) {
 
                int ret = ses_graph_kcolor(graph, j, colors);
                if (ret < 0) {
@@ -1191,8 +1232,41 @@ static int __ses_de_cross(ScfEfunction* f, int d)
                        }
                }
 
-               if (n > 0)
-                       break;
+               if (n > 0) {
+                       if (try > 0)
+                               break;
+
+                       ScfEcomponent* max = NULL;
+
+                       for (i = 0; i < graph->size; i++) {
+                               v         = graph->data[i];
+
+                               c = v->data;
+                               if (v->color < 0 && SCF_EDA_NPN == c->type) {
+
+                                       if (!max || max->color < c->color)
+                                               max = c;
+                               }
+
+                               v->color = 0;
+                       }
+
+                       i = __ses_find_eline_index(f, max->pins[SCF_EDA_NPN_B]->lid);
+                       k = __ses_find_eline_index(f, max->pins[SCF_EDA_NPN_C]->lid);
+
+                       scf_logw("mov c%ld: el%ld [%ld] --> [%ld] el%ld\n\n", max->id, f->elines[k]->id, k, i, f->elines[i]->id);
+
+                       decross_mov_before(f, d, i, k);
+
+                       scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free);
+
+                       ret = __ses_get_crosses(f, d, graph);
+                       if (ret < 0)
+                               return ret;
+
+                       try++;
+                       continue;
+               }
 
                for (i = 0; i < graph->size; i++) {
                        v         = graph->data[i];
@@ -1203,6 +1277,7 @@ static int __ses_de_cross(ScfEfunction* f, int d)
                }
 
                scf_vector_del(colors, (void*)j);
+               j--;
        }
 
        scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free);
@@ -1606,12 +1681,12 @@ int ses_layout_function(ScfEfunction* f, int d)
        __ses_layout_components(f, d);
        __ses_xchg_components(f, d);
 
-       qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp_id);
-
        ret = __ses_de_cross(f, d);
        if (ret < 0)
                return ret;
 
+       qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp_id);
+
        __ses_setc_xy(f, d);
        __ses_layout_cx(f, d);