tmp
authoryu.dongliang <18588496441@163.com>
Fri, 7 Jul 2023 08:32:03 +0000 (16:32 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 7 Jul 2023 08:32:03 +0000 (16:32 +0800)
ses_layout.c
ses_layout.h

index 630972280fd7db1aa77fc60ec4e872421b6247cd..58f4164fc22fb0ef732bec08589d564bdffec2db 100644 (file)
@@ -20,14 +20,33 @@ int epin_cmp(const void* v0, const void* v1)
        return 0;
 }
 
+int line_pair_cmp(const void* v0, const void* v1)
+{
+       const ses_line_pair_t* lp0 = v0;
+       const ses_line_pair_t* lp1 = v1;
+
+       if (lp0->n_components < lp1->n_components)
+               return 1;
+
+       if (lp0->n_components > lp1->n_components)
+               return -1;
+
+       if (lp0 < lp1)
+               return -1;
+
+       if (lp0 > lp1)
+               return 1;
+
+       return 0;
+}
+
 int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
 {
        ScfEcomponent* c;
-       ScfEline*      l;
        ScfEpin*       p;
        ScfEpin*       p2;
 
-       scf_vector_t*  vec;
+       scf_vector_t*  lv;
 
        size_t i;
        size_t j;
@@ -44,10 +63,10 @@ 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++) {
-                               vec       = lines->data[k];
+                               lv        = lines->data[k];
 
-                               for (m = 0; m < vec->size; m++) {
-                                       p2 =        vec->data[m];
+                               for (m = 0; m < lv->size; m++) {
+                                       p2 =        lv->data[m];
 
                                        if (p2->cid == p->cid && p2->id == p->id) {
                                                assert(p2 == p);
@@ -57,8 +76,8 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
 
                                m = 0;
                                n = 0;
-                               while (m < vec->size && n + 1 < p->n_tos) {
-                                       p2   = vec->data[m];
+                               while (m < lv->size && n + 1 < p->n_tos) {
+                                       p2   = lv->data[m];
 
                                        if (p2->cid < p->tos[n])
                                                m++;
@@ -70,7 +89,7 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
                                                n += 2;
 
                                        else {
-                                               if (scf_vector_add(vec, p) < 0)
+                                               if (scf_vector_add(lv, p) < 0)
                                                        return -ENOMEM;
 
                                                goto next;
@@ -78,16 +97,16 @@ int ses_pins_same_line(ScfEfunction* f, scf_vector_t* lines)
                                }
                        }
 
-                       vec = scf_vector_alloc();
-                       if (!vec)
+                       lv = scf_vector_alloc();
+                       if (!lv)
                                return -ENOMEM;
 
-                       if (scf_vector_add(lines, vec) < 0) {
-                               scf_vector_free(vec);
+                       if (scf_vector_add(lines, lv) < 0) {
+                               scf_vector_free(lv);
                                return -ENOMEM;
                        }
 
-                       if (scf_vector_add(vec, p) < 0)
+                       if (scf_vector_add(lv, p) < 0)
                                return -ENOMEM;
 next:
                        p = NULL;
@@ -96,12 +115,12 @@ next:
 
 #if 1
        for (i = 0; i < lines->size; i++) {
-               vec       = lines->data[i];
+               lv        = lines->data[i];
 
-               scf_logw("line i: %ld\n", i);
+               scf_logw("line i: %ld, %p\n", i, lv);
 
-               for (j = 0; j < vec->size; j++) {
-                       p  =        vec->data[j];
+               for (j = 0; j < lv->size; j++) {
+                       p  =        lv->data[j];
 
                        scf_logi("pin j: %ld, cid: %ld, pid: %ld\n", j, p->cid, p->id);
                }
@@ -112,6 +131,76 @@ next:
        return 0;
 }
 
+int ses_lines_same_components(scf_vector_t* lines, scf_vector_t* pairs)
+{
+       ses_line_pair_t* lp;
+       scf_vector_t*    lv0;
+       scf_vector_t*    lv1;
+
+       ScfEpin*         p0;
+       ScfEpin*         p1;
+
+       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];
+
+               for (j = i + 1; j < lines->size; j++) {
+                       lv1           = lines->data[j];
+
+                       n  = 0;
+                       k0 = 0;
+                       k1 = 0;
+
+                       while (k0 < lv0->size && k1 < lv1->size) {
+                               p0    = lv0->data[k0];
+                               p1    = lv1->data[k1];
+
+                               if (p0->cid < p1->cid)
+                                       k0++;
+                               else if (p0->cid > p1->cid)
+                                       k1++;
+                               else {
+                                       k0++;
+                                       k1++;
+                                       n++;
+                               }
+                       }
+
+                       if (0 == n)
+                               continue;
+
+                       lp = malloc(sizeof(ses_line_pair_t));
+                       if (!lp)
+                               return -ENOMEM;
+
+                       if (scf_vector_add(pairs, lp) < 0) {
+                               free(lp);
+                               return -ENOMEM;
+                       }
+
+                       lp->lines[0]     = lv0;
+                       lp->lines[1]     = lv1;
+                       lp->n_components = n;
+               }
+       }
+
+       scf_vector_qsort(pairs, line_pair_cmp);
+
+#if 1
+       for (i = 0; i < pairs->size; i++) {
+               lp        = pairs->data[i];
+
+               scf_logi("i: %ld, lv0: %p, lv1: %p, n_components: %ld\n",
+                               i, lp->lines[0], lp->lines[1], lp->n_components);
+       }
+#endif
+}
+
 int ses_layout_board(ScfEboard* b, int x, int y, int w, int h)
 {
        ScfEcomponent* c;
@@ -120,6 +209,7 @@ int ses_layout_board(ScfEboard* b, int x, int y, int w, int h)
        ScfEpin*       p;
 
        scf_vector_t*  lines;
+       scf_vector_t*  pairs;
 
        size_t i;
        size_t j;
@@ -135,7 +225,15 @@ int ses_layout_board(ScfEboard* b, int x, int y, int w, int h)
                if (!lines)
                        return -ENOMEM;
 
+               pairs = scf_vector_alloc();
+               if (!pairs) {
+                       scf_vector_free(lines);
+                       return -ENOMEM;
+               }
+
                ses_pins_same_line(f, lines);
+
+               ses_lines_same_components(lines, pairs);
        }
 
        return 0;
index e8cbad875f68e0b715fc03ce29f50085753765e4..e5a0d4898d57df88c89fe33926f6b959652c1b31 100644 (file)
@@ -4,6 +4,12 @@
 #include"scf_eda_pb.h"
 #include"scf_vector.h"
 
+typedef struct
+{
+       scf_vector_t* lines[2];
+       size_t        n_components;
+} ses_line_pair_t;
+
 int ses_layout_board(ScfEboard* b, int x, int y, int w, int h);
 
 #endif