From 932f75775798d2318755173f62f65d2f18ceeb5f Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sat, 8 Jul 2023 21:25:55 +0800 Subject: [PATCH] tmp --- scf_eda.pb-c.c | 19 ++++- scf_eda.pb-c.h | 4 +- scf_eda.proto | 1 + scf_eda_pb.c | 46 +++++++++++- scf_eda_pb.h | 5 +- ses_layout.c | 186 ++++++++++++++++++++++++------------------------- 6 files changed, 161 insertions(+), 100 deletions(-) diff --git a/scf_eda.pb-c.c b/scf_eda.pb-c.c index 977f9f4..5008b01 100644 --- a/scf_eda.pb-c.c +++ b/scf_eda.pb-c.c @@ -732,7 +732,7 @@ const ProtobufCMessageDescriptor scf_ecomponent__descriptor = (ProtobufCMessageInit) scf_ecomponent__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[2] = +static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[3] = { { "name", @@ -758,15 +758,28 @@ static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[2] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "elines", + 3, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(ScfEfunction, n_elines), + offsetof(ScfEfunction, elines), + &scf_eline__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned scf_efunction__field_indices_by_name[] = { 1, /* field[1] = components */ + 2, /* field[2] = elines */ 0, /* field[0] = name */ }; static const ProtobufCIntRange scf_efunction__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 2 } + { 0, 3 } }; const ProtobufCMessageDescriptor scf_efunction__descriptor = { @@ -776,7 +789,7 @@ const ProtobufCMessageDescriptor scf_efunction__descriptor = "ScfEfunction", "", sizeof(ScfEfunction), - 2, + 3, scf_efunction__field_descriptors, scf_efunction__field_indices_by_name, 1, scf_efunction__number_ranges, diff --git a/scf_eda.pb-c.h b/scf_eda.pb-c.h index a3170ab..fc07cde 100644 --- a/scf_eda.pb-c.h +++ b/scf_eda.pb-c.h @@ -109,10 +109,12 @@ struct _ScfEfunction char *name; size_t n_components; ScfEcomponent **components; + size_t n_elines; + ScfEline **elines; }; #define SCF_EFUNCTION__INIT \ { PROTOBUF_C_MESSAGE_INIT (&scf_efunction__descriptor) \ - , NULL, 0,NULL } + , NULL, 0,NULL, 0,NULL } struct _ScfEboard diff --git a/scf_eda.proto b/scf_eda.proto index 1edf3a2..6d7b803 100644 --- a/scf_eda.proto +++ b/scf_eda.proto @@ -49,6 +49,7 @@ message scf_efunction { required string name = 1; repeated scf_ecomponent components = 2; + repeated scf_eline elines = 3; } message scf_eboard diff --git a/scf_eda_pb.c b/scf_eda_pb.c index 87a6774..044cfde 100644 --- a/scf_eda_pb.c +++ b/scf_eda_pb.c @@ -469,7 +469,7 @@ int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c) int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c) { - if (!f) + if (!f || !c) return -EINVAL; size_t i; @@ -485,7 +485,7 @@ int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c) f->n_components--; - p = realloc(f->components, sizeof(ScfEfunction*) * f->n_components); + p = realloc(f->components, sizeof(ScfEcomponent*) * f->n_components); if (p) f->components = p; return 0; @@ -495,6 +495,48 @@ int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c) return -EINVAL; } +int scf_efunction__add_eline(ScfEfunction* f, ScfEline* el) +{ + if (!f || !el) + return -EINVAL; + + void* p = realloc(f->elines, sizeof(ScfEline*) * (f->n_elines + 1)); + if (!p) + return -ENOMEM; + + f->elines = p; + f->elines[f->n_elines++] = el; + return 0; +} + +int scf_efunction__del_eline(ScfEfunction* f, ScfEline* el) +{ + if (!f || !el) + return -EINVAL; + + size_t i; + size_t j; + void* p; + + for (i = 0; i < f->n_elines; i++) { + + if (f->elines[i] == el) { + + for (j = i + 1; j < f->n_elines; j++) + f->elines[j - 1] = f->elines[j]; + + f->n_elines--; + + p = realloc(f->elines, sizeof(ScfEline*) * f->n_elines); + if (p) + f->elines = p; + return 0; + } + } + + return -EINVAL; +} + void scf_efunction__free(ScfEfunction* f) { if (f) { diff --git a/scf_eda_pb.h b/scf_eda_pb.h index ca5eb65..44de155 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -61,7 +61,7 @@ int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid) int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid); void scf_epin__free (ScfEpin* pin); -ScfEcomponent* scf_ecomponent__alloc(uint64_t type); +ScfEcomponent* scf_ecomponent__alloc (uint64_t type); int scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin); int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin); void scf_ecomponent__free (ScfEcomponent* c); @@ -69,6 +69,9 @@ void scf_ecomponent__free (ScfEcomponent* c); ScfEfunction* scf_efunction__alloc (const char* name); int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c); int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c); + +int scf_efunction__add_eline (ScfEfunction* f, ScfEline* el); +int scf_efunction__del_eline (ScfEfunction* f, ScfEline* el); void scf_efunction__free (ScfEfunction* f); ScfEboard* scf_eboard__alloc(); diff --git a/ses_layout.c b/ses_layout.c index 58f4164..df5ae4d 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -20,34 +20,33 @@ int epin_cmp(const void* v0, const void* v1) return 0; } -int line_pair_cmp(const void* v0, const void* v1) +int eline_cmp(const void* v0, const void* v1) { - const ses_line_pair_t* lp0 = v0; - const ses_line_pair_t* lp1 = v1; + const ScfEline* el0 = v0; + const ScfEline* el1 = v1; - if (lp0->n_components < lp1->n_components) + if (el0->n_conns < el1->n_conns) return 1; - if (lp0->n_components > lp1->n_components) + if (el0->n_conns > el1->n_conns) return -1; - if (lp0 < lp1) - return -1; - - if (lp0 > lp1) + if (el0->n_pins < el1->n_pins) return 1; + if (el0->n_pins > el1->n_pins) + return -1; + return 0; } -int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines) +int ses_pins_same_line(ScfEfunction* f) { ScfEcomponent* c; + ScfEline* el; ScfEpin* p; ScfEpin* p2; - scf_vector_t* lv; - size_t i; size_t j; size_t k; @@ -62,34 +61,31 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines) qsort(p->tos, p->n_tos / 2, sizeof(uint64_t) * 2, epin_cmp); - for (k = 0; k < lines->size; k++) { - lv = lines->data[k]; + for (k = 0; k < f->n_elines; k++) { + el = f->elines[k]; - for (m = 0; m < lv->size; m++) { - p2 = lv->data[m]; + for (m = 0; m + 1 < el->n_pins; m += 2) { - if (p2->cid == p->cid && p2->id == p->id) { - assert(p2 == p); + if (el->pins[m] == p->cid && el->pins[m + 1] == p->id) goto next; - } } m = 0; n = 0; - while (m < lv->size && n + 1 < p->n_tos) { - p2 = lv->data[m]; + while (m + 1 < el->n_pins && n + 1 < p->n_tos) { - if (p2->cid < p->tos[n]) - m++; - else if (p2->cid > p->tos[n]) + if (el->pins[m] < p->tos[n]) + m += 2; + else if (el->pins[m] > p->tos[n]) n += 2; - else if (p2->id < p->tos[n + 1]) - m++; - else if (p2->id > p->tos[n + 1]) + + else if (el->pins[m + 1] < p->tos[n + 1]) + m += 2; + else if (el->pins[m + 1] > p->tos[n + 1]) n += 2; else { - if (scf_vector_add(lv, p) < 0) + if (scf_eline__add_pin(el, p->cid, p->id) < 0) return -ENOMEM; goto next; @@ -97,16 +93,17 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines) } } - lv = scf_vector_alloc(); - if (!lv) + el = scf_eline__alloc(); + if (!el) return -ENOMEM; + el->id = f->n_elines; - if (scf_vector_add(lines, lv) < 0) { - scf_vector_free(lv); + if (scf_efunction__add_eline(f, el) < 0) { + scf_eline__free(el); return -ENOMEM; } - if (scf_vector_add(lv, p) < 0) + if (scf_eline__add_pin(el, p->cid, p->id) < 0) return -ENOMEM; next: p = NULL; @@ -114,16 +111,14 @@ next: } #if 1 - for (i = 0; i < lines->size; i++) { - lv = lines->data[i]; + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; - scf_logw("line i: %ld, %p\n", i, lv); + scf_logw("line i: %ld, %p\n", i, el); - for (j = 0; j < lv->size; j++) { - p = lv->data[j]; + for (j = 0; j + 1 < el->n_pins; j += 2) - scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, p->cid, p->id); - } + scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, el->pins[j], el->pins[j + 1]); printf("\n"); } @@ -131,74 +126,92 @@ next: return 0; } -int ses_lines_same_components(scf_vector_t* lines, scf_vector_t* pairs) +int ses_lines_same_components(ScfEfunction* f) { - ses_line_pair_t* lp; - scf_vector_t* lv0; - scf_vector_t* lv1; - - ScfEpin* p0; - ScfEpin* p1; + ScfEline* el0; + ScfEline* el1; + ScfEconn* ec; size_t i; size_t j; size_t k0; size_t k1; - size_t n; - for (i = 0; i < lines->size - 1; i++) { - lv0 = lines->data[i]; + ec = NULL; - for (j = i + 1; j < lines->size; j++) { - lv1 = lines->data[j]; + for (i = 0; i < f->n_elines - 1; i++) { + el0 = f->elines[i]; + + for (j = i + 1; j < f->n_elines; j++) { + el1 = f->elines[j]; - n = 0; k0 = 0; k1 = 0; - while (k0 < lv0->size && k1 < lv1->size) { - p0 = lv0->data[k0]; - p1 = lv1->data[k1]; + if (!ec) { + ec = scf_econn__alloc(); + if (!ec) + return -ENOMEM; + } + + assert(0 == ec->n_cids); + + while (k0 + 1 < el0->n_pins && k1 + 1 < el1->n_pins) { - if (p0->cid < p1->cid) - k0++; - else if (p0->cid > p1->cid) - k1++; + uint64_t c0 = el0->pins[k0]; + uint64_t c1 = el1->pins[k1]; + + if (c0 < c1) + k0 += 2; + else if (c0 > c1) + k1 += 2; else { - k0++; - k1++; - n++; + k0 += 2; + k1 += 2; + + if (scf_econn__add_cid(ec, c0) < 0) { + scf_econn__free(ec); + return -ENOMEM; + } } } - if (0 == n) + if (0 == ec->n_cids) continue; - lp = malloc(sizeof(ses_line_pair_t)); - if (!lp) - return -ENOMEM; + ec->lid = el1->id; - if (scf_vector_add(pairs, lp) < 0) { - free(lp); + if (scf_eline__add_conn(el0, ec) < 0) { + scf_econn__free(ec); return -ENOMEM; } - - lp->lines[0] = lv0; - lp->lines[1] = lv1; - lp->n_components = n; } } - scf_vector_qsort(pairs, line_pair_cmp); + if (ec) { + scf_econn__free(ec); + ec = NULL; + } + + qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp); #if 1 - for (i = 0; i < pairs->size; i++) { - lp = pairs->data[i]; + for (i = 0; i < f->n_elines; i++) { + el0 = f->elines[i]; + + scf_logi("i: %ld, el0: %ld, n_pins: %ld\n", i, el0->id, el0->n_pins); + + for (j = 0; j < el0->n_conns; j++) { + ec = el0->conns[j]; + + scf_logi("j: %ld, lid: %ld, n_cids: %ld\n", j, ec->lid, ec->n_cids); + } - scf_logi("i: %ld, lv0: %p, lv1: %p, n_components: %ld\n", - i, lp->lines[0], lp->lines[1], lp->n_components); + printf("\n"); } #endif + + return 0; } int ses_layout_board(ScfEboard* b, int x, int y, int w, int h) @@ -208,9 +221,6 @@ int ses_layout_board(ScfEboard* b, int x, int y, int w, int h) ScfEline* l; ScfEpin* p; - scf_vector_t* lines; - scf_vector_t* pairs; - size_t i; size_t j; size_t k; @@ -221,19 +231,9 @@ int ses_layout_board(ScfEboard* b, int x, int y, int w, int h) printf("f: %s\n", f->name); - lines = scf_vector_alloc(); - if (!lines) - return -ENOMEM; - - pairs = scf_vector_alloc(); - if (!pairs) { - scf_vector_free(lines); - return -ENOMEM; - } - - ses_pins_same_line(f, lines); + ses_pins_same_line(f); - ses_lines_same_components(lines, pairs); + ses_lines_same_components(f); } return 0; -- 2.25.1