From 81de4bb0984c5957255b12c9fe24b0f57994bc9c Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Mon, 10 Jun 2024 16:12:01 +0800 Subject: [PATCH] examples/sub.cpk test ok for one-bit sub --- Makefile | 2 - examples/add.cpk | Bin 1321 -> 1322 bytes examples/add2.cpk | Bin 3295 -> 3297 bytes examples/and.cpk | Bin 722 -> 720 bytes examples/or.cpk | Bin 725 -> 723 bytes examples/sub.cpk | Bin 0 -> 2331 bytes main.c | 2 +- scf_eda_pack.h | 2 + ses_core.h | 9 +- ses_flow.c | 414 -------------------------------------------- ses_layout.c | 119 ++----------- ses_layout_topo.c | 400 ------------------------------------------ ses_node_analysis.c | 2 +- ses_path.c | 13 ++ ses_step_simplify.c | 33 ++-- ses_step_topo.c | 53 ++++-- 16 files changed, 76 insertions(+), 973 deletions(-) create mode 100644 examples/sub.cpk delete mode 100644 ses_flow.c delete mode 100644 ses_layout_topo.c diff --git a/Makefile b/Makefile index 7060b71..952b8f2 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,10 @@ CFILES += scf_eda_pack.c CFILES += pack/scf_pack.c CFILES += ses_layout.c -CFILES += ses_layout_topo.c CFILES += ses_graph.c CFILES += ses_utils.c CFILES += ses_path.c -CFILES += ses_flow.c CFILES += ses_node_analysis.c CFILES += ses_steps.c diff --git a/examples/add.cpk b/examples/add.cpk index 81750b927a09a87201365ecb5486c0f6ce55611c..f549b6accb3faa6f52e312a195ed74332f03dc08 100644 GIT binary patch delta 21 dcmZ3zZzKI9LC!c2&n0%YX4**p>2ekkI delta 20 ccmZ3*wUTSYW)?=4i3i0epJx=9e22vk08aS_aR2}S diff --git a/examples/add2.cpk b/examples/add2.cpk index 69646a7fc070240c9f952c96502cd8fb0265ab07..30cbeebf6375b4c7a8c0f63e539d5a95c86ef01d 100644 GIT binary patch delta 38 lcmcaF`A~AhSr#TMzR8Nr;*&S932gq#Qo@eJpFEMr4*>ji3;O^7 delta 32 icmaDTd0%qFS(eF{7{w=VU=!T@jirPg#+f{s#}5GJRSe1i diff --git a/examples/and.cpk b/examples/and.cpk index 0907c7d00b42148cc7020f99dad9c5fea8eb3c34..4cfa6984d812c7c5ee6c0ebc5cb4129c5aa310b4 100644 GIT binary patch delta 70 zcmcb_dVzJqGEQ*@1_nMphkS>L8>J?m@<8EFHe-B%DqzK=#AL-caijR;{fq*WTbTR+ DqC*oS delta 67 ycmcb>dWm(yGOo#t3=9l>ddx&c;ljmnaP=J=`G({N@fYN0*1Mm-KK{PCdH*H7zJGc7ddi~)HIS@4#ZFI3gs`{L^v82J1B|I)JxeS< z3%@=>Dn40~OM;)+k^D4${2pEtO%FmGY7_xu|XNQy+c&nbw07lqW)O&xIsvBwH;l$@5Wh(rml*{-!n zRaj-UwGzCfiXG8SD_BDT0-P+g3usig z1Z%x?x}l7BD#mWV{Y15N-GVR{>W-bL@0tk2B3*CkdW)MJZ09A^?SJ?V^c_GLzYDH! zqGMHbc)s{iGl)g{-cf1?%AOQgiYUR0Wklko_G}Skiq3i)NWNSOJbJtxy>}oipMRp4 zDu@^nh()%kr&JHh^7$v~OA(2e8Yne@QZk!65u&~nk$9;CCvpH~tZJT75Ar#k2mig# Y{|p?N>4;2;N6_QajYWNLuk1+w3y?f&egFUf literal 0 HcmV?d00001 diff --git a/main.c b/main.c index 8db995f..1a848f5 100644 --- a/main.c +++ b/main.c @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) printf("f: %s\n", f->name); - ses_steps_analyse(f, 100, 5); + ses_steps_analyse(f, 100, 3); } #endif diff --git a/scf_eda_pack.h b/scf_eda_pack.h index b955ef5..cf2a246 100644 --- a/scf_eda_pack.h +++ b/scf_eda_pack.h @@ -25,6 +25,8 @@ enum { #define SCF_EDA_PIN_NEG 8 #define SCF_EDA_PIN_CF 16 #define SCF_EDA_PIN_BORDER 32 +#define SCF_EDA_PIN_CONST 64 +#define SCF_EDA_PIN_IN0 128 #define SCF_EDA_V_INIT -10001001.0 #define SCF_EDA_V_MIN -10000000.0 diff --git a/ses_core.h b/ses_core.h index 7940bd0..94724c0 100644 --- a/ses_core.h +++ b/ses_core.h @@ -176,14 +176,7 @@ void ses_node_print(ses_node_t* node); void ses_nodes_free (scf_vector_t* nodes); void ses_nodes_print(scf_vector_t* nodes); - -ses_flow_t* ses_flow_alloc(); -void ses_flow_free (ses_flow_t* flow); -void ses_flow_print(ses_flow_t* flow); - -void ses_flow_v_pos(ses_flow_t* flow, double a, double ja); -void ses_flow_v_neg(ses_flow_t* flow, double a, double ja); -void ses_flow_jr (ses_flow_t* flow, ScfEfunction* f); +void ses_paths_print(scf_vector_t* paths); ses_ctx_t* ses_ctx_alloc(); void ses_ctx_free (ses_ctx_t* ctx); diff --git a/ses_flow.c b/ses_flow.c deleted file mode 100644 index fc559a7..0000000 --- a/ses_flow.c +++ /dev/null @@ -1,414 +0,0 @@ -#include"ses_core.h" - -ses_flow_t* ses_flow_alloc() -{ - ses_flow_t* flow = calloc(1, sizeof(ses_flow_t)); - if (!flow) - return NULL; - - flow->paths = scf_vector_alloc(); - if (!flow->paths) { - ses_flow_free(flow); - return NULL; - } - - return flow; -} - -void ses_flow_free(ses_flow_t* flow) -{ - if (flow) { - if (flow->paths) - scf_vector_free(flow->paths); - - free(flow); - } -} - -int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge) -{ - ses_path_t* path; - ScfEpin* p; - - int i; - int j; - - for (i = 0; i < paths->size; i++) { - path = paths->data[i]; - - if (path == bridge) - continue; - - for (j = 0; j < path->pins->size; j++) { - p = path->pins->data[j]; - - if (vip->lid == p->lid) { - - if (j + 1 >= path->pins->size) - break; - - if (scf_vector_add(flow->paths, path) < 0) - return -1; - - flow->vip = p; - flow->vip_i = j; - flow->vip_m = 0; - flow->vip_n = path->pins->size - 1; - return 1; - } - } - - if (path->childs) { - int ret = ses_paths_find_flow(flow, path->childs, vip, bridge); - if (ret < 0) - return ret; - - if (1 == ret) { - if (scf_vector_add(flow->paths, path) < 0) - return -ENOMEM; - return 1; - } - } - - if (path->bridges) { - int ret = ses_paths_find_flow(flow, path->bridges, vip, bridge); - if (ret < 0) - return ret; - - if (1 == ret) { - if (scf_vector_add(flow->paths, path) < 0) - return -ENOMEM; - return 1; - } - } - } - - return 0; -} - -int ses_flow_find_neg(ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f) -{ - if (flow->paths->size <= 0) - return 0; - - ses_path_t* path = flow->paths->data[flow->paths->size - 1]; - ScfEpin* vp = flow->vip; - ScfEpin* p = path->pins->data[path->pins->size - 1]; - - ScfEcomponent* B = f->components[0]; - ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG]; - - while (p->lid != Bn->lid) { - int ret = ses_paths_find_flow(flow, paths, p, path); - if (ret < 0) - return ret; - - path = flow->paths->data[flow->paths->size - 1]; - p = path->pins ->data[path->pins->size - 1]; - } - - flow->vip = vp; - return 0; -} - -int ses_flow_find_pos(ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f) -{ - if (flow->paths->size <= 0) - return 0; - - ses_path_t* path = flow->paths->data[flow->paths->size - 1]; - ScfEpin* vp = flow->vip; - ScfEpin* p = path->pins->data[0]; - - ScfEcomponent* B = f->components[0]; - ScfEpin* Bp = B->pins[SCF_EDA_Battery_POS]; - - while (p->lid != Bp->lid) { - int ret = ses_paths_find_flow(flow, paths, p, path); - if (ret < 0) - return ret; - - path = flow->paths->data[flow->paths->size - 1]; - p = path->pins ->data[0]; - } - - flow->vip = vp; - return 0; -} - -void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) -{ - if (!flow) - return; - - flow->pos_pins = 0; - flow->neg_pins = 0; - - flow->pos_r = 0; - flow->neg_r = 0; - - flow->pos_cv = 0; - flow->neg_cv = 0; - - if (!flow->paths || !flow->vip) - return; - - ses_path_t* path; - ses_path_t* child; - ScfEcomponent* c; - ScfEpin* p; - ScfEpin* p0; - ScfEpin* vip = flow->vip; - - int i; - int j; - int m; - int n; - - for (i = 0; i < flow->paths->size; i++) { - path = flow->paths->data[i]; - - if (0 == i) { - m = flow->vip_m; - n = flow->vip_n; - } else { - m = 0; - n = path->pins->size - 1; - } - - for (j = m; j <= n; j++) { - p = path->pins->data[j]; - - ++flow->pos_pins; - - c = f->components[p->cid]; - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id) - flow->pos_NPNs++; - else if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == p->id) - flow->pos_diodes++; - - else if (SCF_EDA_Capacitor == c->type && (j & 0x1)) { - int sign = !p->id - p->id; - - flow->pos_cv += c->v * sign; - } - - if (p->lid == vip->lid) { - vip = path->pins->data[0]; - - child = ses_path_find_child(path, 0, j); - if (!child) - child = ses_path_find_bridge(path, 0, j); - - if (child) { - flow->pos_r += child->parent_pr; - - } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) { - p = path->pins->data[j - 1]; - - flow->pos_r += p->pr + p->r + p->dr; - } else - flow->pos_r += p->pr; - - scf_logd("flow->pos_r: %lg, c%ldp%ld->pr: %lg, vip c%ldp%ld->pr: %lg\n", - flow->pos_r, p->cid, p->id, p->pr, vip->cid, vip->id, vip->pr); - break; - } - } - } - - vip = flow->vip; - - for (i = 0; i < flow->paths->size; i++) { - path = flow->paths->data[i]; - - if (0 == i) { - m = flow->vip_m; - n = flow->vip_n; - } else { - m = 0; - n = path->pins->size - 1; - } - - int parallel = 0; - int j0; - - p0 = NULL; - for (j = m; j <= n; j++) { - p = path->pins->data[j]; - - if (!p0) { - if (!(j & 0x1) && p->lid == vip->lid) { - p0 = p; - j0 = j; - - child = ses_path_find_child(path, j0, n); - if (child) - parallel = 1; - } else - continue; - } - - ++flow->neg_pins; - - c = f->components[p->cid]; - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id) - flow->neg_NPNs++; - else if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == p->id) - flow->neg_diodes++; - - else if (SCF_EDA_Capacitor == c->type && (j & 0x1)) { - int sign = !p->id - p->id; - - flow->neg_cv += c->v * sign; - } - - if (parallel) - continue; - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) { - p = path->pins->data[j - 1]; - - if (p->lid == p0->lid) - flow->neg_r += p->r + p->dr; - else - flow->neg_r += p->pr - p0->pr; - - scf_logd("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n", - flow->neg_r, p->cid, p->id, p->sr, p0->cid, p0->id, p0->pr); - - if (j + 1 <= n) { - p0 = path->pins->data[j + 1]; - j0 = j + 1; - } else { - p0 = path->pins->data[j]; - j0 = j; - } - - } else if (p->sr != p->pr) { - - child = ses_path_find_child(path, j0, j); - if (!child) - child = ses_path_find_bridge(path, j0, j); - - if (child) - flow->neg_r += child->parent_pr - p0->pr; - else - flow->neg_r += p->sr - p0->pr; - - scf_logd("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p->pr: %lg, p0 c%ldp%ld->pr: %lg\n", - flow->neg_r, p->cid, p->id, p->sr, p->pr, p0->cid, p0->id, p0->pr); - - p0 = p; - j0 = j; - } - } - - if (p0) { - vip = path->pins->data[j - 1]; - c = f->components[vip->cid]; - - if (vip != p0) { - child = ses_path_find_child(path, j0, j - 1); - if (child) - flow->neg_r += child->parent_pr - p0->pr; - else - flow->neg_r += vip->sr - p0->pr; - } - - scf_logd("flow->neg_r: %lg, vip c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n", - flow->neg_r, vip->cid, vip->id, vip->sr, p0->cid, p0->id, p0->pr); - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == vip->id) - vip->pr = path->parent_pr; - } - - scf_logd("flow->neg_r: %lg, vip c%ldp%ld->sr: %lg\n", flow->neg_r, vip->cid, vip->id, vip->sr); - } - - scf_loge("flow pos_r: %lg, neg_r: %lg, pos_cv: %lg, neg_cv: %lg, vip: c%ldp%ld, pos_diodes: %d, pos_NPNs: %d, neg_diodes: %d, neg_NPNs: %d\n", - flow->pos_r, flow->neg_r, flow->pos_cv, flow->neg_cv, flow->vip->cid, flow->vip->id, flow->pos_diodes, flow->pos_NPNs, flow->neg_diodes, flow->neg_NPNs); -} - -void ses_flow_print(ses_flow_t* flow) -{ - if (!flow || !flow->paths || !flow->vip) - return; - - ses_path_t* path; - ScfEpin* p; - ScfEpin* vip = flow->vip; - - int i; - int j; - int m; - int n; - - for (i = flow->paths->size - 1; i >= 0; i--) { - - if (i > 0) { - path = flow->paths->data[i - 1]; - - vip = path->pins->data[0]; - m = 0; - n = path->pins->size - 1; - } else { - vip = flow->vip; - m = flow->vip_m; - n = flow->vip_n; - } - - path = flow->paths->data[i]; - - for (j = m; j <= n; j++) { - p = path->pins->data[j]; - - printf("c%ldp%ld ", p->cid, p->id); - - if (p->lid == vip->lid) - break; - } - - if (i > 0) - printf(", "); - } - - printf(";\n"); - - vip = flow->vip; - - for (i = 0; i < flow->paths->size; i++) { - path = flow->paths->data[i]; - - if (i > 0) { - m = 0; - n = path->pins->size - 1; - } else { - m = flow->vip_m; - n = flow->vip_n; - } - - int flag = 0; - - for (j = m; j <= n; j++) { - p = path->pins->data[j]; - - if (!flag) { - if (p->lid == vip->lid) - flag = 1; - continue; - } - - printf("c%ldp%ld ", p->cid, p->id); - } - - if (flag) - printf(", "); - - vip = path->pins->data[j - 1]; - } - - printf(".\n"); -} diff --git a/ses_layout.c b/ses_layout.c index 104f998..b9d3542 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -23,38 +23,6 @@ int epin_cmp(const void* v0, const void* v1) return 0; } -int epin_cmp_npn_c(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]]; - ScfEpin* p0 = c0->pins[t0[1]]; - ScfEpin* p1 = c1->pins[t1[1]]; - - if (SCF_EDA_NPN != c0->type) - return 1; - if (SCF_EDA_NPN != c1->type) - return -1; - - if (SCF_EDA_NPN_E != p0->id) - return 1; - if (SCF_EDA_NPN_E != p1->id) - return -1; - - ScfEpin* pb0 = c0->pins[SCF_EDA_NPN_B]; - ScfEpin* pb1 = c1->pins[SCF_EDA_NPN_B]; - - if (pb0->y < pb1->y) - return -1; - if (pb0->y > pb1->y) - return 1; - - return 0; -} - int epin_cmp_color(const void* v0, const void* v1, void* arg) { const uint64_t* t0 = v0; @@ -561,32 +529,8 @@ static void __ses_layout_path2(ScfEfunction* f, ses_path_t* path, ses_path_t* ba f->elines[n]->vflag = 1; eline_mov_before(f, __n, n); -#if 1 - c = f->components[p->cid]; - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_C == p->id) { - pe = c->pins[SCF_EDA_NPN_E]; - pb = c->pins[SCF_EDA_NPN_B]; - - intptr_t ie = __ses_find_eline_index(f, pe->lid); - intptr_t ib = __ses_find_eline_index(f, pb->lid); - - if (!f->elines[ib]->vflag) { - f->elines[ib]->vflag = 1; - - eline_mov_after(f, __n, ib); - - ie = __ses_find_eline_index(f, pe->lid); - ib = __ses_find_eline_index(f, pb->lid); - n = __ses_find_eline_index(f, p->lid); - - scf_logw("**************** c%ldp%ld, ic: %ld, ib: %ld, ie: %ld\n", p->cid, p->id, n, ib, ie); - } - } -#endif } } -// printf("\n"); } static void __ses_layout_path(ScfEfunction* f, ses_path_t* path, ses_path_t* base) @@ -642,7 +586,7 @@ static int __ses_layout_lines4(ScfEfunction* f) scf_vector_qsort(paths, epath_cmp_pins); - _topo_print(paths); + ses_paths_print(paths); B = f->components[0]; Bp = B->pins[SCF_EDA_Battery_POS]; @@ -691,53 +635,6 @@ end: return ret; } -static void __ses_layout_npn(ScfEfunction* f) -{ - ScfEline* el0; - ScfEline* el1; - - size_t i; - size_t j; - - for (i = 0; i < f->n_elines; i++) { - el0 = f->elines[i]; - - if (el0->n_pins != 4) - continue; - - intptr_t cflag = 0; - intptr_t ib = INT_MAX; - - for (j = 0; j + 1 < el0->n_pins; j += 2) { - - ScfEcomponent* c = f->components[el0->pins[j]]; - ScfEpin* p = c->pins [el0->pins[j + 1]]; - - if (c->color > 2) - continue; - - if (SCF_EDA_NPN != c->type) - continue; - - if (SCF_EDA_NPN_C == p->id) - cflag = 1; - - intptr_t m = __ses_find_eline_index(f, c->pins[SCF_EDA_NPN_B]->lid); - - if (ib > m) - ib = m; - } - - if (cflag && ib < f->n_elines) { - el1 = f->elines[ib]; - - eline_mov_after(f, ib, i); - - scf_logi("mov el%ld [%ld] <--> [%ld] el%ld\n", el0->id, i, ib, el1->id); - } - } -} - static int __ses_layout_lines2(ScfEfunction* f) { ScfEline* tmp; @@ -754,8 +651,6 @@ static int __ses_layout_lines2(ScfEfunction* f) __ses_layout_lines4(f); - __ses_layout_npn(f); - #if 1 for (i = 0; i < f->n_elines; i++) { el0 = f->elines[i]; @@ -1785,20 +1680,26 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_ else if (SCF_EDA_PIN_NEG & el->flags) cairo_set_source_rgb(cr, 0, 0, 1); + else if (SCF_EDA_PIN_IN0 & el->flags) + cairo_set_source_rgb(cr, 0.8, 0, 0); + else if (SCF_EDA_PIN_IN & el->flags) - cairo_set_source_rgb(cr, 0, 1, 0); + cairo_set_source_rgb(cr, 0, 0, 0.8); + + else if (SCF_EDA_PIN_CONST & el->flags) + cairo_set_source_rgb(cr, 0, 0.6, 0); else if (SCF_EDA_PIN_OUT & el->flags) cairo_set_source_rgb(cr, 1, 0, 1); else if (SCF_EDA_PIN_CF & el->flags) - cairo_set_source_rgb(cr, 0.8, 0, 1.0); + cairo_set_source_rgb(cr, 0.8, 0, 0.8); else cairo_set_source_rgb(cr, 1, 0.5, 0.1); uint8_t text[64]; - cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); + cairo_select_font_face(cr, "Calibri", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 28); ScfLine* prev = NULL; diff --git a/ses_layout_topo.c b/ses_layout_topo.c deleted file mode 100644 index 79d7a19..0000000 --- a/ses_layout_topo.c +++ /dev/null @@ -1,400 +0,0 @@ -#include"ses_core.h" - -static int __ses_dfs_add_path(scf_vector_t* paths, ses_path_t* path) -{ - ScfEpin* p; - int j; - - if (scf_vector_add(paths, path) < 0) - return -ENOMEM; - - for (j = 0; j < path->pins->size; j++) { - p = path->pins->data[j]; - p->pflag = 1; - p->path = (uintptr_t)path; - } - - return 0; -} - -static int __layout_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, ses_path_t** ppath) -{ - ScfEcomponent* c; - ScfEline* el; - ScfEpin* np; - ScfEpin* p; - - int64_t i; - int64_t j; - - if (SCF_EDA_Status_OFF == rc->status) - return SCF_EDA_Status_OFF; - - if (SCF_EDA_Diode == rc->type && SCF_EDA_Diode_NEG == rp->id) - return SCF_EDA_Path_OFF; - - if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id) - return SCF_EDA_Path_OFF; - - if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E != rp->id) - return SCF_EDA_Path_OFF; - - if (!*ppath) { - *ppath = ses_path_alloc(); - if (!*ppath) - return -ENOMEM; - } - - if (scf_vector_add((*ppath)->pins, rp) < 0) - return -ENOMEM; - - if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id) - || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == rp->id))) - rp->vflag = 1; - - scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", rp->cid, rp->id, rp->lid, rp->vflag, rp->pflag); - - int ret = 0; - - for (i = 0; i < rc->n_pins; i++) { - np = rc->pins[i]; - - if (np->vflag) - continue; - - if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E != np->id) - continue; - if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id) - continue; - - scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", np->cid, np->id, np->lid, np->vflag, np->pflag); - - el = f->elines[np->lid]; - - if (SCF_EDA_PIN_POS & el->flags) { - scf_logd("pos l%ld\n\n", el->id); - - ret = SCF_EDA_Path_OFF; - continue; - } - - if (!*ppath) { - *ppath = ses_path_alloc(); - if (!*ppath) - return -ENOMEM; - } - - if (SCF_EDA_PNP == rc->type && 0 == (*ppath)->pins->size) { - - if (scf_vector_add((*ppath)->pins, rp) < 0) - return -ENOMEM; - } - - if (scf_vector_add((*ppath)->pins, np) < 0) - return -ENOMEM; - - if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == np->id) - || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id))) - np->vflag = 1; - - if (SCF_EDA_PIN_NEG & el->flags) { - scf_logd("neg l%ld\n\n", el->id); - - ret = __ses_dfs_add_path(__paths, *ppath); - if (ret < 0) - return ret; - - *ppath = NULL; - return 0; - } - - ret = 0; - - for (j = 0; j + 1 < el->n_pins; j += 2) { - - c = f->components[el->pins[j]]; - p = c->pins [el->pins[j + 1]]; - - if (p->pflag) { - if (p != np && *ppath) { - scf_logd("branch: c%ld_p%ld, l%ld\n\n", c->id, p->id, el->id); - - if ((*ppath)->pins->size > 0) { - - ret = __ses_dfs_add_path(__paths, *ppath); - if (ret < 0) - return ret; - } else - ses_path_free(*ppath); - - *ppath = NULL; - } - continue; - } - - if (p->vflag) - continue; - - if (!((SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) - || (SCF_EDA_PNP == c->type && SCF_EDA_PNP_E == p->id))) - p->vflag = 1; - - ret = __layout_dfs_path(f, c, p, __paths, ppath); - if (ret < 0) - return ret; - - if (SCF_EDA_Path_OFF == ret) - p->vflag = 0; - } - - if (*ppath) { - scf_vector_del((*ppath)->pins, np); - - if (SCF_EDA_Status_OFF != ret) - ret = SCF_EDA_Path_OFF; - } - - if (SCF_EDA_Path_OFF == ret) - np->vflag = 0; - } - - if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) { - if (*ppath) - scf_vector_del((*ppath)->pins, rp); - - if (SCF_EDA_Path_OFF == ret) { - rp->vflag = 0; - - scf_logd("off: c%ld_p%ld, l%ld\n\n", rp->cid, rp->id, rp->lid); - - } else if (SCF_EDA_Status_OFF == ret) - scf_logd("off: c%ld_p%ld, l%ld\n\n", rp->cid, rp->id, rp->lid); - } - - return ret; -} - -static int __layout_add_path(ses_path_t* parent, ses_path_t* child) -{ - ses_path_t* path; - ScfEpin* cp0 = child->pins->data[0]; - ScfEpin* cp1 = child->pins->data[child->pins->size - 1]; - ScfEpin* p0; - ScfEpin* p1; - - int i; - int j; - - if (!parent->childs) { - parent->childs = scf_vector_alloc(); - if (!parent->childs) - return -ENOMEM; - } - - for (i = 0; i < parent->childs->size; i++) { - path = parent->childs->data[i]; - - p0 = path->pins->data[0]; - p1 = path->pins->data[path->pins->size - 1]; - - if (p0->lid == cp0->lid && p1->lid == cp1->lid) - return __layout_add_path(path, child); - } - - child->parent_p0 = -1; - child->parent_p1 = -1; - - for (j = 0; j < parent->pins->size; j++) { - p0 = parent->pins->data[j]; - - if (p0->lid == cp0->lid) - child->parent_p0 = (j + 1) & ~0x1; - - else if (p0->lid == cp1->lid) - child->parent_p1 = j; - - if (child->parent_p0 >= 0 && child->parent_p1 >= 0) - break; - } - - child->parent = parent; - return scf_vector_add(parent->childs, child); -} - -static int _layout_layers(ScfEfunction* f, scf_vector_t* paths) -{ - ScfEcomponent* B; - ses_path_t* child; - ses_path_t* parent; - ScfEpin* Bp; - ScfEpin* Bn; - ScfEpin* p0; - ScfEpin* p1; - ScfEpin* p2; - ScfEpin* p3; - ScfEpin* p; - - int i; - int j; - int k; - - B = f->components[0]; - Bp = B->pins[SCF_EDA_Battery_POS]; - Bn = B->pins[SCF_EDA_Battery_NEG]; - - for (i = paths->size - 1; i >= 0; i--) { - child = paths->data[i]; - - assert(child->pins->size >= 2); - - p0 = child->pins->data[0]; - p1 = child->pins->data[child->pins->size - 1]; - - if (p0->lid == Bp->lid && p1->lid == Bn->lid) - continue; - - for (j = paths->size - 1; j >= 0; j--) { - parent = paths->data[j]; - - if (parent == child) - continue; - - int n = 0; - - for (k = 0; k < parent->pins->size; k++) { - p = parent->pins->data[k]; - - if (p->lid == p0->lid) - n |= 0x1; - - if (p->lid == p1->lid) - n |= 0x2; - - if (0x3 == n) - goto branch; - } - } - - continue; - -branch: - if (scf_vector_del(paths, child) < 0) - return -1; - - if (__layout_add_path(parent, child) < 0) { - ses_path_free(child); - return -ENOMEM; - } - } - - return 0; -} - -static int ses_layout_layers(ScfEfunction* f, scf_vector_t* paths) -{ - ses_path_t* path; - - int size; - - do { - size = paths->size; - - int ret = _layout_layers(f, paths); - if (ret < 0) - return ret; - - } while (size > paths->size); - - return 0; -} - -static int _layout_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths) -{ - if (!f || !el || !paths) - return -EINVAL; - - ses_path_t* path; - ScfEcomponent* c; - ScfEcomponent* B; - ScfEpin* p; - - size_t i; - - B = f->components[0]; - path = NULL; - - for (i = 0; i + 1 < el->n_pins; i += 2) { - - c = f->components[el->pins[i]]; - p = c->pins [el->pins[i + 1]]; - - if (c == B) - continue; - - int ret = __layout_dfs_path(f, c, p, paths, &path); - if (ret < 0) - return ret; - - if (!path) - continue; - - if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) { - ses_path_free(path); - path = NULL; - continue; - } - - if (scf_vector_add(paths, path) < 0) { - ses_path_free(path); - return -ENOMEM; - } - - path = NULL; - } - - if (path) { - ses_path_free(path); - path = NULL; - } - - for (i = 0; i < paths->size; i++) { - path = paths->data[i]; - - path->index = i; - } - - return 0; -} - -int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths) -{ - if (!f || !paths) - return -EINVAL; - - ses_path_t* path; - ScfEcomponent* B; - ScfEline* el; - - scf_vector_clear(paths, ( void (*)(void*) )ses_path_free); - - B = f->components[0]; - el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid]; - - int ret = _layout_paths(f, el, paths); - if (ret < 0) - return ret; - - int i; - for (i = 0; i < f->n_elines; i++) { - el = f->elines[i]; - - if (el->flags & SCF_EDA_PIN_IN) { - - ret = _layout_paths(f, el, paths); - if (ret < 0) - return ret; - } - } - - return ses_layout_layers(f, paths); -} diff --git a/ses_node_analysis.c b/ses_node_analysis.c index 26de84b..8516e65 100644 --- a/ses_node_analysis.c +++ b/ses_node_analysis.c @@ -524,7 +524,7 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A c->lock = 1; (*n_offs)++; - scf_loge("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index); + scf_logd("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index); } } else if (edge->edge_b) { diff --git a/ses_path.c b/ses_path.c index f8ad589..0a1fdbd 100644 --- a/ses_path.c +++ b/ses_path.c @@ -130,6 +130,19 @@ void ses_path_print(ses_path_t* path) } } +void ses_paths_print(scf_vector_t* paths) +{ + ses_path_t* path; + + int i; + for (i = 0; i < paths->size; i++) { + path = paths->data[i]; + + ses_path_print(path); + printf("\n"); + } +} + int ses_path_is_child(ses_path_t* parent, ses_path_t* child) { ScfEpin* cp0 = child->pins->data[0]; diff --git a/ses_step_simplify.c b/ses_step_simplify.c index ed11373..e3a2cce 100644 --- a/ses_step_simplify.c +++ b/ses_step_simplify.c @@ -534,17 +534,17 @@ int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t b else if (SCF_EDA_PIN_OUT & el->flags) cairo_set_source_rgb(cr, 1, 0, 1); - else if (el->v == B->pins[SCF_EDA_Battery_POS]->v) + else if (SCF_EDA_PIN_IN0 & el->flags) cairo_set_source_rgb(cr, 0.8, 0, 0); - else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v) + else if (SCF_EDA_PIN_IN & el->flags) cairo_set_source_rgb(cr, 0, 0, 0.8); - else if (SCF_EDA_PIN_IN & el->flags) - cairo_set_source_rgb(cr, 0, 1, 0); + else if (SCF_EDA_PIN_CONST & el->flags) + cairo_set_source_rgb(cr, 0, 0.6, 0); else if (SCF_EDA_PIN_CF & el->flags) - cairo_set_source_rgb(cr, 0.8, 0, 1.0); + cairo_set_source_rgb(cr, 0.8, 0, 0.8); else cairo_set_source_rgb(cr, 1, 0.5, 0.1); @@ -581,25 +581,14 @@ int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t b n = snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(el->v * 1000.0 * SHOW_BITS) / SHOW_BITS); else n = snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(el->v * 1000000.0 * SHOW_BITS) / SHOW_BITS); -#if 0 - // A of line - if (el->aout > 1e-1 || el->aout < -1e-1) - n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgA", (int64_t)(el->aout * SHOW_BITS) / SHOW_BITS); - else if (el->aout > 1e-5 || el->aout < -1e-5) - n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgmA", (int64_t)(el->aout * 1000.0 * SHOW_BITS) / SHOW_BITS); - else - n += snprintf(text + n, sizeof(text) - 1 - n, ", %lguA", (int64_t)(el->aout * 1000000.0 * SHOW_BITS) / SHOW_BITS); + cairo_set_font_size(cr, 20); - if (el->ain > 1e-1 || el->ain < -1e-1) - n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgA", (int64_t)(el->ain * SHOW_BITS) / SHOW_BITS); + if (el->v == B->pins[SCF_EDA_Battery_POS]->v) + cairo_set_source_rgb(cr, 1, 0, 0); - else if (el->ain > 1e-5 || el->ain < -1e-5) - n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgmA", (int64_t)(el->ain * 1000.0 * SHOW_BITS) / SHOW_BITS); - else - n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lguA", (int64_t)(el->ain * 1000000.0 * SHOW_BITS) / SHOW_BITS); -#endif - cairo_set_font_size(cr, 20); + else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v) + cairo_set_source_rgb(cr, 0, 0, 1); cairo_move_to (cr, l->x0 + 10, l->y0 - 8); cairo_show_text(cr, text); @@ -613,7 +602,7 @@ int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t b if (prev) { if (!(el->flags & SCF_EDA_PIN_BORDER)) - cairo_set_line_width(cr, 1); + cairo_set_line_width(cr, 1.5); cairo_move_to(cr, prev->x0, prev->y0); cairo_line_to(cr, l->x0, l->y0); diff --git a/ses_step_topo.c b/ses_step_topo.c index 2110857..23a6380 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -1157,20 +1157,6 @@ static void _topo_key_components(ScfEfunction* f, ses_path_t* path) } } -int _topo_print(scf_vector_t* paths) -{ - ses_path_t* path; - - int i; - for (i = 0; i < paths->size; i++) { - path = paths->data[i]; - - ses_path_print(path); - - printf("\n"); - } -} - static void _topo_clear(ScfEfunction* f) { if (!f) @@ -1526,7 +1512,7 @@ static int _topo_path_parallel(ScfEfunction* f, scf_vector_t* paths) return 0; } -static int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths) +int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths) { ses_path_t* path; @@ -1560,6 +1546,41 @@ static int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths) return _topo_bridge_piers(f, paths); } +int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths) +{ + if (!f || !paths) + return -EINVAL; + + ses_path_t* path; + ScfEcomponent* B; + ScfEline* el; + + scf_vector_clear(paths, ( void (*)(void*) )ses_path_free); + + B = f->components[0]; + el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid]; + + int ret = _topo_paths(f, el, paths); + if (ret < 0) + return ret; + + int i; + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; + + if (el->flags & SCF_EDA_PIN_IN) { + + ret = _topo_paths(f, el, paths); + if (ret < 0) + return ret; + } + } + + ses_paths_print(paths); + + return __ses_topo_layers(f, paths); +} + static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ses_path_t* path; @@ -1601,7 +1622,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* return ret; } - _topo_print(ctx->paths); + ses_paths_print(ctx->paths); return 0; } -- 2.25.1