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)
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];
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;
+ }
}
}