#include"ses_core.h"
+int _ses_path_cmp(const void* v0, const void* v1);
+
int __ses_path_jr(ses_path_t* path)
{
if (!path)
return -EINVAL;
+ if (path->pins->size < 2) {
+ scf_loge("\n");
+ return -EINVAL;
+ }
+
ses_path_t* child;
ScfEpin* p;
+ ScfEpin* p0;
+ ScfEpin* p1;
+ ScfEpin* cp0;
+ ScfEpin* cp1;
+
+ double R;
+ double r;
+ double jr;
- int i;
+ int i;
+ int j;
- path->r0 = 0;
- path->jr0 = 0;
+ r = 0;
+ jr = 0;
for (i = 0; i < path->pins->size; i++) {
p = path->pins->data[i];
- path->r0 += p->r;
- path->jr0 += p->jr;
+ r += p->r;
+ jr += p->jr;
+
+ p->tr = r;
+ p->jtr = jr;
}
- double R = path->r0 * path->r0 + path->jr0 * path->jr0;
- double r = path->r0 / R;
- double jr = -path->jr0 / R;
+ if (path->childs) {
- scf_loge("path: %d, r0: %lg, jr0: %lg, r: %lg, jr: %lg\n", path->index, path->r0, path->jr0, r, jr);
+ scf_vector_qsort(path->childs, _ses_path_cmp);
- if (path->childs) {
- for (i = 0; i < path->childs->size; i++) {
- child = path->childs->data[i];
+ for (i = path->childs->size - 1; i >= 0; i--) {
+ child = path->childs->data[i];
+
+ if (child->pins->size < 2) {
+ scf_loge("\n");
+ return -EINVAL;
+ }
int ret = __ses_path_jr(child);
if (ret < 0)
return ret;
+ cp0 = child->pins->data[0];
+ cp1 = child->pins->data[child->pins->size - 1];
+ p0 = NULL;
+ p1 = NULL;
+
+ for (j = 0; j < path->pins->size; j++) {
+ p = path->pins->data[j];
+
+ if (p->lid == cp0->lid) {
+ p0 = p;
+ break;
+ }
+ }
+
+ if (!p0)
+ return -EINVAL;
+
+ for ( ; j < path->pins->size; j++) {
+ p = path->pins->data[j];
+
+ if (p->lid == cp1->lid) {
+ p1 = p;
+ break;
+ }
+ }
+
+ if (!p1)
+ return -EINVAL;
+
R = child->r * child->r + child->jr * child->jr;
double _r = child->r / R;
double _jr = -child->jr / R;
+ r = p1->tr - p0->tr;
+ jr = p1->jtr - p0->jtr;
+
+ R = r * r + jr * jr;
+ r = r / R;
+ jr = -jr / R;
+
r += _r;
jr += _jr;
- scf_loge("child: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg, _r: %lg, _jr: %lg\n\n",
- child->index, child->r, child->jr, child->r0, child->jr0, _r, _jr);
+ R = r * r + jr * jr;
+ r = r / R;
+ jr = -jr / R;
+
+ double dr = p1->tr - (p0->tr + r);
+ double jdr = p1->jtr - (p0->jtr + jr);
+
+ for ( ; j < path->pins->size; j++) {
+ p = path->pins->data[j];
+
+ if (p == p1)
+ scf_loge("p == p1: %d\n", j);
+
+ p->tr -= dr;
+ p->jtr -= jdr;
+ }
+
+ scf_loge("child: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg, _r: %lg, _jr: %lg, dr: %lg, jdr: %lg\n\n",
+ child->index, child->r, child->jr, child->r0, child->jr0, _r, _jr, dr, jdr);
}
}
- R = r * r + jr * jr;
- r = r / R;
- jr = -jr / R;
+ p = path->pins->data[path->pins->size - 1];
- path->r = r;
- path->jr = jr;
+ path->r = p->tr;
+ path->jr = p->jtr;
scf_loge("path: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg\n",
path->index, path->r, path->jr, path->r0, path->jr0);