From 871dd921416e63e0452ebb86092d9438ab894d36 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 7 Nov 2023 23:42:50 +0800 Subject: [PATCH] ses_layout.c --- ses_layout.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/ses_layout.c b/ses_layout.c index e48fbd3..b891df0 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -453,11 +453,6 @@ static int __ses_layout_lines3(ScfEfunction* f) N = v->edges->size; } - scf_vector_t* paths = scf_vector_alloc(); - int ret = __ses_topo_paths(f, paths); - if (ret < 0) - return ret; - for (j = N; j >= 1; j--) { for (i = 1; i <= j; i++) @@ -529,6 +524,76 @@ static int __ses_layout_lines3(ScfEfunction* f) scf_vector_free(colors); } +int epath_cmp_pins(const void* v0, const void* v1) +{ + const ses_path_t* p0 = *(const ses_path_t**)v0; + const ses_path_t* p1 = *(const ses_path_t**)v1; + + if (p0->pins->size > p1->pins->size) + return -1; + + if (p0->pins->size < p1->pins->size) + return 1; + return 0; +} + +static int __ses_layout_lines4(ScfEfunction* f) +{ + scf_vector_t* paths; + ses_path_t* Bpath; + ses_path_t* path; + + ScfEcomponent* B; + ScfEline* el; + ScfEpin* Bp; + ScfEpin* p; + + intptr_t i; + intptr_t j; + intptr_t k; + + paths = scf_vector_alloc(); + if (!paths) + return -ENOMEM; + + int ret = __ses_topo_paths(f, paths); + if (ret < 0) + goto end; + + scf_vector_qsort(paths, epath_cmp_pins); + + B = f->components[0]; + Bp = B->pins[SCF_EDA_Battery_POS]; + + for (i = 0; i < paths->size; i++) { + Bpath = paths->data[i]; + + p = Bpath->pins->data[0]; + if (p->lid == Bp->lid) + break; + } + + if (i >= paths->size) + goto end; + + for (j = 0; j < Bpath->pins->size; j += 2) { + p = Bpath->pins->data[j]; + + k = __ses_find_eline_index(f, p->lid); + SCF_XCHG(f->elines[k], f->elines[j / 2]); + } + + p = Bpath->pins->data[j - 1]; + k = __ses_find_eline_index(f, p->lid); + SCF_XCHG(f->elines[k], f->elines[j / 2 + 1]); + + ret = 0; +end: + scf_vector_clear(paths, ( void (*)(void*) )ses_path_free); + scf_vector_free(paths); + return ret; +} + static int __ses_layout_lines2(ScfEfunction* f) { ScfEline* tmp; @@ -543,7 +608,7 @@ static int __ses_layout_lines2(ScfEfunction* f) if (f->n_elines <= 2) return 0; - __ses_layout_lines3(f); + __ses_layout_lines4(f); #if 1 for (i = 0; i < f->n_elines; i++) { @@ -1341,7 +1406,7 @@ int ses_layout_function(ScfEfunction* f, int d) f->w = 0; f->h = 0; - qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp); +// qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp); int ret = __ses_layout_lines(f, d); if (ret < 0) -- 2.25.1