_topo_path_completes()
authoryu.dongliang <18588496441@163.com>
Sun, 12 Nov 2023 09:03:53 +0000 (17:03 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 12 Nov 2023 09:03:53 +0000 (17:03 +0800)
ses_step_topo.c
ses_steps.c

index 75ea62bb84d2245417cff266f8cc51cda4e08873..58f0da359bec8fe9a9cdd91fcef0f85a739cf2f2 100644 (file)
@@ -291,6 +291,38 @@ static int _topo_path_bridges(ScfEfunction* f, ses_path_t* path)
        return __topo_path_bridges(f, path);
 }
 
+static int __topo_path_xchg(ses_path_t* path0, int k0, ses_path_t* path1, int k1)
+{
+       ScfEpin* p;
+
+       int i;
+
+       for (i = 0; i + k0 < path0->pins->size && i + k1 < path1->pins->size; i++)
+               SCF_XCHG(path0->pins->data[i + k0], path1->pins->data[i + k1]);
+
+       while (i + k0 < path0->pins->size) {
+               p         = path0->pins->data[i + k0];
+
+               if (scf_vector_del(path0->pins, p) < 0)
+                       return -1;
+
+               if (scf_vector_add(path1->pins, p) < 0)
+                       return -ENOMEM;
+       }
+
+       while (i + k1 < path1->pins->size) {
+               p         = path1->pins->data[i + k1];
+
+               if (scf_vector_del(path1->pins, p) < 0)
+                       return -1;
+
+               if (scf_vector_add(path0->pins, p) < 0)
+                       return -ENOMEM;
+       }
+
+       return 0;
+}
+
 static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
 {
        if (!f || !paths)
@@ -306,9 +338,11 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
        ScfEpin*         p1;
        ScfEpin*         p2;
        ScfEpin*         p3;
+       ScfEpin*         p;
 
        int i;
        int j;
+       int k;
 
        for (i    = paths->size - 1; i >= 1; i--) {
                path0 = paths->data[i];
@@ -334,27 +368,56 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
                        if (p2->lid != Bp->lid)
                                continue;
 
-                       if (p3->lid == p0->lid)
-                               break;
-               }
+                       if (p3->lid == Bn->lid)
+                               continue;
 
-               if (j > 0) {
-                       scf_loge("merge path: c%ldp%ld-c%ldp%ld ... c%ldp%ld-c%ldp%ld\n",
-                                       p2->cid, p2->id, p3->cid, p3->id,
-                                       p0->cid, p0->id, p1->cid, p1->id);
+                       for (k = path1->pins->size - 1; k >= 0; k -= 2) {
+                               p  = path1->pins->data[k];
 
-                       for (j = 0; j < path0->pins->size; j++) {
-                               p0 =        path0->pins->data[j];
+                               if (p->lid == p1->lid)
+                                       break;
+                       }
 
-                               if (scf_vector_add(path1->pins, p0) < 0)
-                                       return -ENOMEM;
+                       if (k > 0) {
+                               scf_loge("merge path: c%ldp%ld-c%ldp%ld ... c%ldp%ld-c%ldp%ld\n",
+                                               p2->cid, p2->id, p->cid,  p->id,
+                                               p0->cid, p0->id, p1->cid, p1->id);
+
+                               int ret = __topo_path_xchg(path0, 0, path1, k + 1);
+                               if (ret < 0)
+                                       return ret;
+
+                               if (path0->pins->size <= 0) {
+                                       scf_loge("free path0: %d\n", path0->index);
+                                       ses_path_free(path0);
+                                       path0 = NULL;
+                               }
+                               break;
+                       }
+
+                       for (k = 0; k < path0->pins->size; k += 2) {
+                               p  =        path0->pins->data[k];
+
+                               if (p->lid == p3->lid)
+                                       break;
                        }
 
-                       if (scf_vector_del(paths, path0) < 0)
-                               return -1;
+                       if (k < path0->pins->size) {
+                               scf_loge("merge path: c%ldp%ld-c%ldp%ld ... c%ldp%ld-c%ldp%ld\n",
+                                               p2->cid, p2->id, p3->cid, p3->id,
+                                               p ->cid, p ->id, p1->cid, p1->id);
 
-                       ses_path_free(path0);
-                       path0 = NULL;
+                               int ret = __topo_path_xchg(path0, k, path1, path1->pins->size);
+                               if (ret < 0)
+                                       return ret;
+
+                               if (path0->pins->size <= 0) {
+                                       scf_loge("free path0: %d\n", path0->index);
+                                       ses_path_free(path0);
+                                       path0 = NULL;
+                               }
+                               break;
+                       }
                }
        }
 
index 204bbab7b4fa979f9735dc2d6e97ebde6dd05495..3797568666d14d8940978386b1344aa9f029ca43 100644 (file)
@@ -39,11 +39,11 @@ static ses_step_t*  ses_steps_1[] =
 //     &ses_step_simplify,
        &ses_step_topo,
 
+#if 0
        &ses_step_jr,
 
        &ses_step_va_diode,
        &ses_step_va_transistor,
-#if 1
        &ses_step_jr,
        &ses_step_va,
        &ses_step_va_bridge,