// print_board(b);
#if 1
- ses_layout_board(b);
+ ses_layout_board(b, 100);
size_t i;
printf("f: %s\n", f->name);
- ses_steps_analyse(f, 100, 3);
+ ses_steps_analyse(f, 100, 5);
}
#endif
typedef struct ses_node_s ses_node_t;
typedef struct ses_info_s ses_info_t;
-typedef struct ses_data_s ses_data_t;
typedef struct ses_ctx_s ses_ctx_t;
struct ses_flow_s
int n_capacitors;
};
-typedef struct __ses_data_s
-{
- uint64_t id;
-
- double dr;
- double v;
- double a;
- int n_pins;
-} __ses_data_t;
-
-struct ses_data_s
-{
- uint64_t id;
-
- double dr;
- double v;
- double a;
-
- int n_pins;
- __ses_data_t pins[0];
-};
-
struct ses_path_s
{
int refs;
void ses_path_free (ses_path_t* path);
void ses_path_print(ses_path_t* path);
ses_path_t* ses_path_ref (ses_path_t* src);
-int ses_path_add (ses_path_t* path, ses_path_t* child, ScfEfunction* f);
+int ses_path_add (ses_path_t* path, ses_path_t* child);
int ses_path_xchg (ses_path_t* path0, int k0, ses_path_t* path1, int k1);
-int ses_path_save (ScfEfunction* f, ses_path_t* path, scf_vector_t** data);
-int ses_path_load (ScfEfunction* f, ses_path_t* path, scf_vector_t* data);
-
ses_path_t* ses_path_same_net(ses_path_t* path0, ses_path_t* path1);
int ses_path_is_child(ses_path_t* parent, ses_path_t* child);
ses_path_t* ses_path_find_child(ses_path_t* path, int m, int n);
void ses_components_print(ScfEfunction* f);
void ses_elines_print (ScfEfunction* f);
+int ses_layout_board (ScfEboard* b, int d);
int ses_layout_paths (ScfEfunction* f, scf_vector_t* paths);
-int ses_layout_board (ScfEboard* b);
int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count);
int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh, int64_t ns, int64_t count);
-int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge);
-int ses_flow_find_pos (ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f);
-int ses_flow_find_neg (ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f);
-
int __ses_path_va_diode (ScfEfunction* f, ses_path_t* path);
-int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* changed, scf_vector_t* paths, int64_t ns, int64_t count);
int __ses_path_va_branch(ScfEfunction* f, ses_path_t* path, int m, int n, double pr, int* changed, int64_t ns, int64_t count);
void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double* a);
int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, int vinit);
-void __ses_status_check_line(ScfEfunction* f, ScfEline* el, int* changed);
-
int __ses_nodes_path (ScfEfunction* f, ses_path_t* path, int vip_m, int vip_n, scf_vector_t** pnodes, scf_vector_t** pedges);
int __ses_nodes_path_solve(ScfEfunction* f, ses_path_t* path, int vip_m, int vip_n, int* changed, int64_t ns, int64_t count);
int __ses_path_va3(ScfEfunction* f, ses_path_t* path, int m, int n, double pr, int* changed, int64_t ns, int64_t count);
int __ses_path_va2(ScfEfunction* f, ses_path_t* path, int m, int n, double pr, int* changed, int64_t ns, int64_t count);
int __ses_path_va (ScfEfunction* f, ses_path_t* path, int *changed, int64_t ns, int64_t count);
-int __ses_flow_va (ScfEfunction* f, ses_flow_t* flow, double* rp, double* rn, int* changed, int64_t ns, int64_t count);
int __ses_path_pos(ScfEfunction* f, ScfEline* el);
int __ses_path_neg(ScfEfunction* f, ScfEline* el);
return 0;
}
-static void __ses_setc_xy(ScfEfunction* f, int d)
+static void __ses_set_xy(ScfEfunction* f, int d)
{
ScfEcomponent* c;
ScfEpin* p0;
} while (n > 0);
}
-static void __ses_layout_cx(ScfEfunction* f, int d)
+static void __ses_set_cx(ScfEfunction* f, int d)
{
ScfEcomponent* c;
ScfEcomponent* c2;
int tmp = c->x;
- for (j = 0; j < c->n_pins; j++) {
- p = c->pins[j];
+ c->x = c2->x + d;
+
+ for (k = 0; k < c->n_pins; k++) {
+ p = c->pins[k];
+ p->x += c->x - tmp;
+ }
+ }
+ qsort(f->components, f->n_components, sizeof(ScfEcomponent*), ecomponent_cmp_id);
+}
+
+static void __ses_min_cx(ScfEfunction* f, int d)
+{
+ ScfEcomponent* c;
+ ScfEcomponent* c2;
+ ScfEpin* p;
+ ScfEpin* p2;
+
+ long i;
+ long j;
+ long k;
+ long m;
+
+ qsort(f->components, f->n_components, sizeof(ScfEcomponent*), ecomponent_cmp_cx);
+
+ for (i = 1; i < f->n_components; i++) {
+ c = f->components[i];
+
+ int tmp = c->x;
+ int max = 0;
+ int m0 = 0;
+
+ if (c->color > 0)
+ m0 = (c->color - 1) / 2;
+
+ for (j = i - 1; j >= 0; j--) {
+ c2 = f->components[j];
+
+ int m1 = 0;
+
+ if (c2->color > 0)
+ m1 = (c2->color - 1) / 2;
+
+ if (m0 != m1)
+ continue;
+
+ for (k = 0; k < c->n_pins; k++) {
+ p = c->pins[k];
- for (k = 0; k < c2->n_pins; k++) {
- p2 = c2->pins[k];
+ for (m = 0; m < c2->n_pins; m++) {
+ p2 = c2->pins[m];
- if (p->lid == p2->lid) {
- c->x = c2->x + d;
- goto _set_px;
+ if (p->y == p2->y) {
+ if ((c->y >= p->y && c2->y >= p->y) || (c->y <= p->y && c2->y <= p->y)) {
+
+ if (max < c2->x) {
+ max = c2->x;
+ scf_logd("c%ld->x: %d, c%ld->x: %d\n", c->id, c->x, c2->id, c2->x);
+ }
+ }
+ } else if (p->y > p2->y) {
+ if ((c->y < p->y && c2->y > c->y) || (c->y >= p->y && c2->y > p->y)) {
+ if (max < c2->x)
+ max = c2->x;
+ }
+ } else {
+ if ((c->y < p->y && c2->y < p->y) || (c->y >= p->y && c2->y < c->y)) {
+ if (max < c2->x)
+ max = c2->x;
+ }
+ }
}
}
}
- c->x = c2->x + d;
-
+ if (0 == max)
+ continue;
+ c->x = max + d;
_set_px:
for (k = 0; k < c->n_pins; k++) {
p = c->pins[k];
p->x += c->x - tmp;
}
+ }
+
+ qsort(f->components, f->n_components, sizeof(ScfEcomponent*), ecomponent_cmp_cx);
+
+ for (i = 1; i < f->n_components; i++) {
+ c = f->components[i];
+ c2 = f->components[i - 1];
- scf_logd("c%ld->x: %d\n", c->id, c->x);
+ int tmp = c->x;
+
+ if (c->x - c2->x > d) {
+ c->x = c2->x + d;
+
+ for (k = 0; k < c->n_pins; k++) {
+ p = c->pins[k];
+ p->x += c->x - tmp;
+ }
+ }
}
+
qsort(f->components, f->n_components, sizeof(ScfEcomponent*), ecomponent_cmp_id);
}
if (ret < 0)
return ret;
- __ses_setc_xy(f, d);
- __ses_layout_cx(f, d);
-
+ __ses_set_xy(f, d);
+ __ses_set_cx(f, d);
__ses_xchg_cx(f, d);
+ __ses_min_cx(f, d);
__ses_xchg_ce(f, d);
int tx0 = INT_MAX;
// printf("\n");
}
- f->w = tx1 + d * 3;
+ f->w = tx1 + d * 2;
f->h += d;
scf_loge("f->x: %d, y: %d, w: %d, h: %d, tx0: %d, tx1: %d\n", f->x, f->y, f->w, f->h, tx0, tx1);
return 0;
}
-int ses_layout_board(ScfEboard* b)
+int ses_layout_board(ScfEboard* b, int d)
{
ScfEfunction* f;
scf_vector_t* loops;
ses_lines_same_components(f);
- int ret = ses_layout_function(f, 90);
+ int ret = ses_layout_function(f, d);
if (ret < 0) {
scf_loge("\n");
return ret;
}
}
-ses_path_t* ses_path_ref(ses_path_t* src)
-{
- if (!src)
- return NULL;
-
- ses_path_t* dst = ses_path_alloc();
- if (!dst)
- return NULL;
-
- dst->pins = scf_vector_clone(src->pins);
- if (!dst->pins) {
- ses_path_free(dst);
- return NULL;
- }
-
- if (src->childs) {
- dst->childs = scf_vector_clone(src->childs);
-
- if (!dst->childs) {
- ses_path_free(dst);
- return NULL;
- }
-
- ses_path_t* child;
- int i;
-
- for (i = 0; i < dst->childs->size; i++) {
- child = dst->childs->data[i];
- child->refs++;
- }
- }
-
- dst->index = src->index;
- return dst;
-}
-
ses_path_t* ses_path_same_net(ses_path_t* path0, ses_path_t* path1)
{
while (path0->parent)
return 0;
}
-int ses_path_add(ses_path_t* parent, ses_path_t* child, ScfEfunction* f)
+int ses_path_add(ses_path_t* parent, ses_path_t* child)
{
if (!parent || !child)
return -EINVAL;
return -ENOMEM;
}
- ses_path_t* path;
- ScfEpin* p0;
- ScfEpin* p1;
- ScfEpin* cp0 = child->pins->data[0];
- ScfEpin* cp1 = child->pins->data[child->pins->size - 1];
-
- int j;
+ ScfEpin* p0;
+ ScfEpin* p1;
+ ScfEpin* cp0 = child->pins->data[0];
+ ScfEpin* cp1 = child->pins->data[child->pins->size - 1];
if (scf_vector_add(parent->childs, child) < 0)
return -ENOMEM;
+ child->parent_p0 = -1;
+ child->parent_p1 = -1;
+
+ int j;
for (j = 0; j < parent->pins->size; j++) {
p0 = parent->pins->data[j];
- if (p0->lid == cp0->lid) {
+ if (p0->lid == cp0->lid)
child->parent_p0 = (j + 1) & ~0x1;
- break;
- }
- }
- assert(j < parent->pins->size);
-
- int n_transistors = 0;
- int n_capacitors = 0;
- int n_diodes = 0;
- int n_NPNs = 0;
-
- for ( ; j < parent->pins->size; j++) {
- p0 = parent->pins->data[j];
-
- if (!(j & 0x1)) {
- ScfEcomponent* c = f->components[p0->cid];
- if (SCF_EDA_Capacitor == c->type)
- n_capacitors++;
-
- else if (SCF_EDA_Diode == c->type)
- n_diodes++;
-
- else if (SCF_EDA_NPN == c->type) {
- if (SCF_EDA_NPN_B == p0->id)
- n_NPNs++;
- else if (SCF_EDA_NPN_C == p0->id)
- n_transistors++;
- }
- }
-
- if (p0->lid == cp1->lid) {
+ else if (p0->lid == cp1->lid)
child->parent_p1 = j;
+
+ if (child->parent_p0 >= 0 && child->parent_p1 >= 0)
break;
- }
}
- assert(j < parent->pins->size);
p0 = parent->pins->data[0];
p1 = parent->pins->data[parent->pins->size - 1];
parent->index, p0->cid, p0->id, p1->cid, p1->id,
child->index, cp0->cid, cp0->id, cp1->cid, cp1->id);
- if (0 == n_transistors
- && (n_diodes + n_NPNs < child->n_diodes + child->n_NPNs
- || (n_diodes + n_NPNs == child->n_diodes + child->n_NPNs && n_capacitors < child->n_capacitors))) {
-
- int ret = ses_path_xchg(parent, child->parent_p0, child, 0);
- if (ret < 0)
- return ret;
-
- int old_parent_p1 = child->parent_p1;
- j = child->parent_p1 - child->parent_p0 + 1;
- child->parent_p1 = parent->pins->size - 1;
-
- while (j < child->pins->size) {
- p0 = child->pins->data[j];
-
- assert(0 == scf_vector_del(child->pins, p0));
-
- ret = scf_vector_add(parent->pins, p0);
- if (ret < 0)
- return ret;
- }
-
- parent->n_NPNs += child->n_NPNs - n_NPNs;
- child ->n_NPNs = n_NPNs;
-
- parent->n_diodes += child->n_diodes - n_diodes;
- child ->n_diodes = n_diodes;
-
- parent->n_capacitors += child->n_capacitors - n_capacitors;
- child ->n_capacitors = n_capacitors;
-
- for (j = 0; j < parent->childs->size; ) {
- path = parent->childs->data[j];
-
- if (path == child) {
- j++;
- continue;
- }
-
- if (path->parent_p1 <= child->parent_p0) {
- j++;
- continue;
- }
-
- if (path->parent_p0 >= child->parent_p1) {
- path->parent_p0 += child->parent_p1 - old_parent_p1;
- path->parent_p1 += child->parent_p1 - old_parent_p1;
- j++;
- continue;
- }
-
- if (path->parent_p0 == child->parent_p0 && path->parent_p1 == old_parent_p1)
- continue;
-
- cp0 = path->pins->data[0];
- cp1 = path->pins->data[path->pins->size - 1];
-
- path->parent_p0 = -1;
- path->parent_p1 = -1;
-
- int k;
- for (k = 0; k < parent->pins->size; k++) {
- p0 = parent->pins->data[k];
-
- if (p0->lid == cp0->lid) {
- path->parent_p0 = k;
- continue;
- }
-
- if (p0->lid == cp1->lid) {
- path->parent_p1 = k;
- break;
- }
- }
-
- if (-1 == path->parent_p0 || -1 == path->parent_p1) {
- assert(0 == scf_vector_del(parent->childs, path));
-
- if (!parent->bridges) {
- parent->bridges = scf_vector_alloc();
- if (!parent->bridges)
- return -ENOMEM;
- }
-
- ret = scf_vector_add(parent->bridges, path);
- if (ret < 0)
- return ret;
- } else
- j++;
- }
-
- if (child->childs) {
- for (j = 0; j < child->childs->size; ) {
- path = child->childs->data[j];
-
- cp0 = path->pins->data[0];
- cp1 = path->pins->data[path->pins->size - 1];
-
- path->parent_p0 = -1;
- path->parent_p1 = -1;
-
- int k;
- for (k = 0; k < child->pins->size; k++) {
- p0 = child->pins->data[k];
-
- if (p0->lid == cp0->lid) {
- path->parent_p0 = k;
- continue;
- }
-
- if (p0->lid == cp1->lid) {
- path->parent_p1 = k;
- break;
- }
- }
-
- if (-1 == path->parent_p0 || -1 == path->parent_p1) {
- assert(0 == scf_vector_del(child->childs, path));
-
- ret = ses_path_add(parent, path, f);
- if (ret < 0)
- return ret;
- } else
- j++;
- }
- }
- }
-
child->parent = parent;
child->type = SES_PATH_BRANCH;
return 0;
}
-
-static int __ses_path_save(ScfEfunction* f, ses_path_t* path, scf_vector_t* vec)
-{
- ses_path_t* child;
- ses_data_t* d;
-
- ScfEcomponent* c;
- ScfEpin* p;
-
- int i;
- int j;
-
- for (i = 0; i < path->pins->size; i += 2) {
- p = path->pins->data[i];
-
- c = f->components[p->cid];
- d = NULL;
-
- if (SCF_EDA_NPN == c->type) {
- for (j = vec->size - 1; j >= 0; j--) {
- d = vec->data[j];
-
- if (d->id == c->id)
- goto save_pins;
- }
- }
-
- d = malloc(sizeof(ses_data_t) * (1 + c->n_pins));
- if (!d)
- return -ENOMEM;
-
- int ret = scf_vector_add(vec, d);
- if (ret < 0) {
- free(d);
- return ret;
- }
-
- d->id = c->id;
- d->dr = c->dr;
- d->v = c->v;
- d->a = c->a;
- d->n_pins = c->n_pins;
-
-save_pins:
- for (j = 0; j < c->n_pins; j++) {
- p = c->pins[j];
-
- d->pins[j].id = p->id;
- d->pins[j].dr = p->dr;
- d->pins[j].v = p->v;
- d->pins[j].a = p->a;
- d->pins[j].n_pins = 0;
- }
- }
-
- if (path->childs) {
- for (i = 0; i < path->childs->size; i++) {
- child = path->childs->data[i];
-
- int ret = __ses_path_save(f, child, vec);
- if (ret < 0)
- return ret;
- }
- }
-
- return 0;
-}
-
-int ses_path_save(ScfEfunction* f, ses_path_t* path, scf_vector_t** data)
-{
- if (!f || !path || !data)
- return -EINVAL;
-
- scf_vector_t* vec = scf_vector_alloc();
- if (!vec)
- return -ENOMEM;
-
- int ret = __ses_path_save(f, path, vec);
- if (ret < 0) {
- scf_vector_clear(vec, (void (*)(void*) )free);
- scf_vector_free(vec);
- return ret;
- }
-
- *data = vec;
- return 0;
-}
-
-void ses_data_free(scf_vector_t* vec)
-{
- if (vec) {
- scf_vector_clear(vec, (void (*)(void*) )free);
- scf_vector_free(vec);
- }
-}
-
-void ses_data_print(scf_vector_t* vec)
-{
- __ses_data_t* p;
- ses_data_t* c;
- int i;
- int j;
-
- if (vec) {
- for (i = 0; i < vec->size; i++) {
- c = vec->data[i];
-
- printf("c%ld->v: %lg, a: %lg, dr: %lg\n", c->id, c->v, c->a, c->dr);
-
- for (j = 0; j < c->n_pins; j++) {
- p = &c->pins[j];
-
- printf("c%ldp%ld->v: %lg, a: %lg, dr: %lg\n", c->id, p->id, p->v, p->a, p->dr);
- }
- printf("\n");
- }
- }
-}
-
-int ses_path_load(ScfEfunction* f, ses_path_t* path, scf_vector_t* data)
-{
- if (!f || !path || !data)
- return -EINVAL;
-
- ses_data_t* d;
- ScfEcomponent* c;
- ScfEpin* p;
-
- int i;
- int j;
-
- for (i = 0; i < data->size; i++) {
- d = data->data[i];
-
- c = f->components[d->id];
- c->v = d->v;
- c->a = d->a;
- c->dr = d->dr;
-
- assert(d->n_pins == c->n_pins);
-
- for (j = 0; j < c->n_pins; j++) {
- p = c->pins[j];
-
- p->v = d->pins[j].v;
- p->a = d->pins[j].a;
- p->dr = d->pins[j].dr;
- }
- }
-
- return 0;
-}
continue;
if (!prev) {
- if (el->vconst)
- cairo_select_font_face(cr, "Calibri", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
- else
- 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);
else
n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lguA", (int64_t)(el->ain * 1000000.0 * SHOW_BITS) / SHOW_BITS);
#endif
- int cx = INT_MAX;
- int cy = l->y0;
-
- for (i = 0; i < el->n_pins; i += 2) {
- c = f->components[el->pins[i]];
-
- if (c->x > l->x0 && c->x < cx) {
- cx = c->x;
- cy = c->y;
- }
- }
-
- if (INT_MAX == cx)
- cx = l->x0;
-
cairo_set_font_size(cr, 20);
- if (cy > l->y0) {
- cairo_move_to (cr, cx - 40, l->y0 - 8);
- cairo_show_text(cr, text);
- cairo_stroke(cr);
- } else {
- cairo_move_to (cr, cx - 40, l->y0 + 24);
- cairo_show_text(cr, text);
- cairo_stroke(cr);
- }
+ cairo_move_to (cr, l->x0 + 10, l->y0 - 8);
+ cairo_show_text(cr, text);
+ cairo_stroke(cr);
}
cairo_set_line_width(cr, 4);
return __ses_dfs_add_ppath(__paths, ppath);
}
- if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_C == rp->id) {
- scf_logd("NPN C, c%ldp%ld\n\n", rp->cid, rp->id);
-
- return __ses_dfs_add_ppath(__paths, ppath);
- }
-
ses_path_t* off = NULL;
if (SCF_EDA_Status_OFF == rc->status) {
for (i = 0; i < paths->size; ) {
path0 = paths->data[i];
- if (path0->n_transistors > 0) {
- i++;
- continue;
- }
-
p0 = path0->pins->data[0];
p1 = path0->pins->data[path0->pins->size - 1];
if (path1 == path0)
continue;
- if (path1->n_transistors > 0)
- continue;
-
p2 = path1->pins->data[0];
p3 = path1->pins->data[path1->pins->size - 1];
if (scf_vector_del(paths, child) < 0)
return -1;
- if (ses_path_add(parent, child, f) < 0) {
+ if (ses_path_add(parent, child) < 0) {
ses_path_free(child);
return -ENOMEM;
}
if (p0->lid == p2->lid && p1->lid == p3->lid) {
- int ret = ses_path_add(parent, child, f);
+ int ret = ses_path_add(parent, child);
if (ret < 0)
return ret;
if (ret < 0)
return ret;
-// _topo_print(ctx->paths);
-// scf_logi("----\n");
-
ret = __ses_topo_layers(f, ctx->paths);
if (ret < 0)
return ret;
extern ses_step_t ses_step_open;
extern ses_step_t ses_step_va_nodes;
-extern ses_step_t ses_step_a_stat;
-
extern ses_step_t ses_step_output;
extern ses_step_t ses_step_simplify;
-extern ses_step_t ses_step_simplify2;
static ses_step_t* ses_steps_0[] =
&ses_step_open,
&ses_step_va_nodes,
-// &ses_step_a_stat,
-
&ses_step_output,
&ses_step_simplify,
};