From eba374b8d933b45fdf16680ac8eb45702f4fd1e4 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 5 Nov 2023 16:05:12 +0800 Subject: [PATCH] tmp --- ses_layout.c | 297 +++++++++++++++++++++------------------------------ 1 file changed, 123 insertions(+), 174 deletions(-) diff --git a/ses_layout.c b/ses_layout.c index f42d81c..572488f 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -20,6 +20,23 @@ int epin_cmp(const void* v0, const void* v1) return 0; } +int epin_cmp_color(const void* v0, const void* v1, void* arg) +{ + const uint64_t* t0 = v0; + const uint64_t* t1 = v1; + + ScfEfunction* f = arg; + ScfEcomponent* c0 = f->components[t0[0]]; + ScfEcomponent* c1 = f->components[t1[0]]; + + if (c0->color < c1->color) + return -1; + + if (c0->color > c1->color) + return 1; + return 0; +} + int epin_cmp_cx(const void* v0, const void* v1, void* arg) { const uint64_t* t0 = v0; @@ -396,7 +413,7 @@ int ses_lines_diff_components(ScfEfunction* f, ses_graph_t* graph) scf_vector_qsort(graph, ses_vertex_cmp_edges); -#if 1 +#if 0 for (i = 0; i < graph->size; i++) { v0 = graph->data[i]; @@ -428,7 +445,6 @@ static int __ses_layout_lines3(ScfEfunction* f) intptr_t j; intptr_t k; - scf_loge("\n"); ses_lines_diff_components(f, graph); if (0 < graph->size) { @@ -902,123 +918,125 @@ next: return 0; } -static void __ses_de_cross(ScfEfunction* f, int d) +static int __ses_de_cross(ScfEfunction* f, int d) { - ScfEcomponent* c0; - ScfEcomponent* c1; - ScfEpin* p0; - ScfEpin* p1; - ScfEpin* p2; - ScfEpin* p3; - - size_t i; - size_t j; - size_t k; - size_t m; - size_t n; - size_t q; - - for (i = 0; i < f->n_components - 1; i++) { - c0 = f->components[i]; - - for (j = 0; j < c0->n_pins - 1; j++) { - p0 = c0->pins[j]; + ScfEcomponent* c; + ScfEline* el; + ScfEpin* p; + ScfLine* l0; + ScfLine* l; - for (k = j + 1; k < c0->n_pins; k++) { - p1 = c0->pins[k]; + ses_vertex_t* v; + scf_vector_t* graph; + scf_vector_t* colors; - if (p0->y - p1->y <= d && p0->y - p1->y >= -d) - continue; + graph = scf_vector_alloc(); + if (!graph) + return -ENOMEM; - int y0 = p0->y < p1->y ? p0->y : p1->y; - int y1 = p0->y < p1->y ? p1->y : p0->y; + colors = scf_vector_alloc(); + if (!colors) { + scf_vector_free(graph); + return -ENOMEM; + } - for (m = i + 1; m < f->n_components; m++) { - c1 = f->components[m]; + intptr_t N = 2; + intptr_t i; + intptr_t j; - for (n = 0; n < c1->n_pins - 1; n++) { - p2 = c1->pins[n]; + int ret = __ses_get_crosses(f, d, graph); + if (ret < 0) + return ret; - for (q = n + 1; q < c1->n_pins; q++) { - p3 = c1->pins[q]; + if (0 < graph->size) { + v = graph->data[0]; - if (p2->y - p3->y <= d && p2->y - p3->y >= -d) - continue; + N = v->edges->size; + } - int y2 = p2->y < p3->y ? p2->y : p3->y; - int y3 = p2->y < p3->y ? p3->y : p2->y; + for (j = N; j >= 1; j--) { - if (y0 < y2 && y2 < y1 && y1 < y3) { + for (i = 1; i <= j; i++) + scf_vector_add(colors, (void*)i); - if (p2->x > 0) - __ses_flip_neg(c0); + int ret = ses_graph_kcolor(graph, j, colors); + if (ret < 0) { + scf_loge("**********\n"); + } - } else if (y2 < y0 && y0 < y3 && y3 < y1) { + for (i = 0; i < graph->size; i++) { + v = graph->data[i]; - if (p0->x > 0) - __ses_flip_neg(c1); - } - } - } - } + if (v->color < 0) { + c = v->data; + scf_loge("j: %ld, i: %ld, c%ld->color: %ld\n", j, i, c->id, v->color); + break; } } - } - for (i = 0; i < f->n_components; i++) { - c0 = f->components[i]; + if (i < graph->size) + break; - for (j = 0; j < c0->n_pins - 1; j++) { - p0 = c0->pins[j]; + for (i = 0; i < graph->size; i++) { + v = graph->data[i]; - if (p0->x > 0) - continue; + c = v->data; + c->color = v->color; + v->color = 0; + } - for (k = j + 1; k < c0->n_pins; k++) { - p1 = c0->pins[k]; + scf_vector_clear(colors, NULL); + } - if (p1->x > 0) - continue; + scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free); + scf_vector_free(graph); + scf_vector_free(colors); + colors = NULL; + graph = NULL; - int y0 = p0->y < p1->y ? p0->y : p1->y; - int y1 = p0->y < p1->y ? p1->y : p0->y; + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; - for (m = 0; m < f->n_components; m++) { - c1 = f->components[m]; + qsort_r(el->pins, el->n_pins / 2, sizeof(uint64_t) * 2, epin_cmp_color, f); - if (c0 == c1) - continue; + for (j = 0; j + 1 < el->n_pins; j += 2) { - for (n = 0; n < c1->n_pins - 1; n++) { - p2 = c1->pins[n]; + c = f->components[el->pins[j]]; + p = c->pins [el->pins[j + 1]]; - if (p2->x < 0) - continue; + intptr_t k = (c->color - 1) / 2; + intptr_t m = (c->color - 1) % 2; - for (q = n + 1; q < c1->n_pins; q++) { - p3 = c1->pins[q]; + while (el->n_lines <= k) { - if (p3->x < 0) - continue; + l0 = el->lines[el->n_lines - 1]; - if (p2->y - p3->y <= d && p2->y - p3->y >= -d) - continue; + l = malloc(sizeof(ScfLine)); + if (!l) + return -ENOMEM; - int y2 = p2->y < p3->y ? p2->y : p3->y; - int y3 = p2->y < p3->y ? p3->y : p2->y; + l->x0 = l0->x1 + d; + l->x1 = l->x0; + l->y0 = l0->y0; + l->y1 = l0->y1; - if ((y0 < y2 && y2 < y1 && y1 < y3) || (y2 < y0 && y0 < y3 && y3 < y1)) - goto next; - } - } + if (scf_eline__add_line(el, l) < 0) { + free(l); + return -ENOMEM; } } - } - __ses_flip_pos(c0); -next: - c0 = NULL; + l = el->lines[k]; + + if (0 == m) + p->x = l->x0 + d; + else + p->x = l->x1 + d; + l->x1 = p->x; + } } + + return 0; } static void __ses_setc_xy(ScfEfunction* f, int d) @@ -1286,75 +1304,6 @@ static void __ses_mov_pos(ScfEfunction* f, int d) } } -int ses_cross(ScfEfunction* f, int d) -{ - ScfEcomponent* c; - - ses_vertex_t* vc; - - scf_vector_t* graph = scf_vector_alloc(); - scf_vector_t* colors = scf_vector_alloc(); - - intptr_t N = 2; - intptr_t i; - intptr_t j; - - scf_loge("\n"); - __ses_get_crosses(f, d, graph); - - if (0 < graph->size) { - vc = graph->data[0]; - - N = vc->edges->size; - } - - for (j = N; j >= 0; j--) { - - for (i = 1; i <= j; i++) - scf_vector_add(colors, (void*)i); - - int ret = ses_graph_kcolor(graph, j, colors); - if (ret < 0) { - scf_loge("**********\n"); - } - - for (i = 0; i < graph->size; i++) { - vc = graph->data[i]; - - if (vc->color < 0) { - c = vc->data; - scf_loge("j: %ld, i: %ld, c%ld->color: %ld\n", j, i, c->id, vc->color); - break; - } - } - - if (i < graph->size) - break; - - for (i = 0; i < graph->size; i++) { - vc = graph->data[i]; - - c = vc->data; - c->color = vc->color; - vc->color = 0; - } - - scf_vector_clear(colors, NULL); - printf("\n"); - } - - for (i = 0; i < graph->size; i++) { - vc = graph->data[i]; - - c = vc->data; - scf_logi("i: %ld, c%ld->color: %ld\n", i, c->id, c->color); - } - - scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free); - scf_vector_free(graph); - scf_vector_free(colors); -} - int ses_layout_function(ScfEfunction* f, int d) { ScfEcomponent* c; @@ -1384,15 +1333,15 @@ int ses_layout_function(ScfEfunction* f, int d) qsort(f->elines, f->n_elines, sizeof(ScfEline*), eline_cmp_id); -// ses_cross(f, d); - - __ses_de_cross(f, d); + ret = __ses_de_cross(f, d); + if (ret < 0) + return ret; __ses_setc_xy(f, d); - __ses_xchg_cx(f, d); - __ses_xchg_ce(f, d); +// __ses_xchg_cx(f, d); +// __ses_xchg_ce(f, d); - __ses_mov_pos(f, d); +// __ses_mov_pos(f, d); __ses_layout_cx(f, d); int tx0 = INT_MAX; @@ -1401,29 +1350,29 @@ int ses_layout_function(ScfEfunction* f, int d) for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; - int x0 = INT_MAX; - int x1 = 0; - for (j = 0; j < el->n_pins; j += 2) { c = f->components[el->pins[j]]; p0 = c->pins [el->pins[j + 1]]; - if (x0 > p0->x) - x0 = p0->x; + if (tx0 > p0->x) + tx0 = p0->x; - if (x1 < p0->x) - x1 = p0->x; - } + if (tx1 < p0->x) + tx1 = p0->x; - el->lines[0]->x0 = x0; - el->lines[0]->x1 = x1; + intptr_t k = (c->color - 1) / 2; - if (tx0 > x0) - tx0 = x0; + if (el->lines[k]->x0 > p0->x) + el->lines[k]->x0 = p0->x; - if (tx1 < x1) - tx1 = x1; + if (el->lines[k]->x1 < p0->x) + el->lines[k]->x1 = p0->x; + } + + for (j = 0; j < el->n_lines; j++) + scf_logi("l%ld->lines[%ld]: x0: %d, x1: %d\n", el->id, j, el->lines[j]->x0, el->lines[j]->x1); + printf("\n"); } f->w = tx1 + d; -- 2.25.1