From 9408c3e155c46c47dba47c5af2dd4dfb09421bfb Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Mon, 10 Jun 2024 16:38:46 +0800 Subject: [PATCH] support 'sub' in native/eda module --- native/eda/scf_eda.c | 1 - native/eda/scf_eda_inst.c | 80 +++++++++++++++++++++++++++++++++++++-- native/eda/scf_eda_pack.c | 6 +-- native/eda/scf_eda_pack.h | 15 +++++--- 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/native/eda/scf_eda.c b/native/eda/scf_eda.c index e45b696..c9aedb1 100644 --- a/native/eda/scf_eda.c +++ b/native/eda/scf_eda.c @@ -182,4 +182,3 @@ scf_native_ops_t native_ops_eda = { .select_inst = scf_eda_select_inst, }; - diff --git a/native/eda/scf_eda_inst.c b/native/eda/scf_eda_inst.c index 3f757b5..3b19870 100644 --- a/native/eda/scf_eda_inst.c +++ b/native/eda/scf_eda_inst.c @@ -59,7 +59,7 @@ if ((_in)->n_pins != _N) \ return -EINVAL; \ \ - for (i = 0; i < N; i++) { \ + for (i = 0; i < _N; i++) { \ if (!(_in)->pins[i]) \ return -EINVAL; \ } \ @@ -414,6 +414,7 @@ static int _eda_inst_bit_not_handler(scf_native_t* ctx, scf_3ac_code_t* c) EDA_PIN_ADD_INPUT(in, i, f->ef, pi); out->pins[i] = po; + in ->pins[i]->flags |= SCF_EDA_PIN_IN0; } return 0; @@ -451,6 +452,7 @@ static int _eda_inst_bit_and_handler(scf_native_t* ctx, scf_3ac_code_t* c) EDA_PIN_ADD_INPUT(in1, i, f->ef, p1); out->pins[i] = po; + in0->pins[i]->flags |= SCF_EDA_PIN_IN0; } return 0; @@ -488,6 +490,7 @@ static int _eda_inst_bit_or_handler(scf_native_t* ctx, scf_3ac_code_t* c) EDA_PIN_ADD_INPUT(in1, i, f->ef, p1); out->pins[i] = po; + in0->pins[i]->flags |= SCF_EDA_PIN_IN0; } return 0; @@ -501,8 +504,8 @@ static int _eda_inst_add_handler(scf_native_t* ctx, scf_3ac_code_t* c) scf_dag_node_t* in1 = src1->dag_node; scf_dag_node_t* out = dst ->dag_node; - ScfEpin* pc = NULL; ScfEcomponent* B = f->ef->components[0]; + ScfEpin* pc = NULL; int i; int N = eda_variable_size(in0->var); @@ -545,9 +548,77 @@ static int _eda_inst_add_handler(scf_native_t* ctx, scf_3ac_code_t* c) scf_loge("in0->pins[%d]: %ld, in1->pins[%d]: %ld\n", i, in0->pins[i]->cid, i, in1->pins[i]->cid); } - pc = cf; // carry flag + pc = cf; // carry flag + cf->flags |= SCF_EDA_PIN_CF; + out->pins[i] = res; // result - cf->flags |= SCF_EDA_PIN_CF; + in0->pins[i]->flags |= SCF_EDA_PIN_IN0; + } + + return 0; +} + +static int _eda_inst_sub_handler(scf_native_t* ctx, scf_3ac_code_t* c) +{ + EDA_INST_OP3_CHECK() + + scf_dag_node_t* in0 = src0->dag_node; + scf_dag_node_t* in1 = src1->dag_node; + scf_dag_node_t* out = dst ->dag_node; + + ScfEcomponent* B = f->ef->components[0]; + ScfEcomponent* Rp = NULL; + ScfEpin* Bp = B->pins[SCF_EDA_Battery_POS]; + ScfEpin* pc = NULL; + + int i; + int N = eda_variable_size(in0->var); + + EDA_INST_IN_CHECK(in0, N); + EDA_INST_IN_CHECK(in1, N); + + in0->n_pins = N; + in1->n_pins = N; + out->n_pins = N; + + EDA_INST_ADD_COMPONENT(f->ef, Rp, SCF_EDA_Resistor); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, Rp, 1); + + for (i = 0; i < N; i++) { + + ScfEpin* p0 = NULL; + ScfEpin* p1 = NULL; + ScfEpin* p2 = NULL; + ScfEpin* not = NULL; + ScfEpin* cf = NULL; + ScfEpin* res = NULL; + + int ret = __eda_bit_not(f, &p1, ¬); + if (ret < 0) + return ret; + + ret = __eda_bit_adc(f, &p0, &p2, &pc, &res, &cf); + if (ret < 0) + return ret; + + EDA_PIN_ADD_INPUT(in0, i, f->ef, p0); + EDA_PIN_ADD_INPUT(in1, i, f->ef, p1); + + EDA_PIN_ADD_PIN_EF(f->ef, p2, not); + + if (i > 0) + EDA_PIN_ADD_PIN_EF(f->ef, pc, cf); + else { + EDA_PIN_ADD_PIN_EF(f->ef, pc, Rp->pins[0]); + pc->flags |= SCF_EDA_PIN_CONST; + } + + pc = cf; + cf->flags |= SCF_EDA_PIN_CF; + + out->pins[i] = res; + in0->pins[i]->flags |= SCF_EDA_PIN_IN0; } return 0; @@ -919,6 +990,7 @@ static eda_inst_handler_t eda_inst_handlers[] = {SCF_OP_BIT_OR, _eda_inst_bit_or_handler}, {SCF_OP_ADD, _eda_inst_add_handler}, + {SCF_OP_SUB, _eda_inst_sub_handler}, {SCF_OP_3AC_TEQ, _eda_inst_teq_handler}, {SCF_OP_3AC_CMP, _eda_inst_cmp_handler}, diff --git a/native/eda/scf_eda_pack.c b/native/eda/scf_eda_pack.c index c837e73..cd251bf 100644 --- a/native/eda/scf_eda_pack.c +++ b/native/eda/scf_eda_pack.c @@ -21,7 +21,7 @@ static scf_edata_t component_datas[] = {SCF_EDA_Resistor, 0, 0, 0, 0, 1e4, 0, 0, 0}, {SCF_EDA_Capacitor, 0, 0, 0, 0, 10, 0.1, 0, 0}, - {SCF_EDA_Inductor, 0, 0, 0, 0, 0, 0, 1e3, 0}, + {SCF_EDA_Inductor, 0, 0, 0, 0, 10, 0, 1e3, 0}, }; static scf_edata_t pin_datas[] = @@ -31,10 +31,10 @@ static scf_edata_t pin_datas[] = {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0}, {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0}, - {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 10, 0, 0, 150}, + {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 3, 0, 0, 250}, {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0}, - {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 10, 0, 0, 150}, + {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 3, 0, 0, 250}, }; static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid) diff --git a/native/eda/scf_eda_pack.h b/native/eda/scf_eda_pack.h index 1f48b4c..cf2a246 100644 --- a/native/eda/scf_eda_pack.h +++ b/native/eda/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 @@ -36,6 +38,9 @@ enum { #define SCF_EDA_V_NPN_ON 0.70 #define SCF_EDA_V_NPN_OFF 0.61 +#define SCF_EDA_V_PNP_ON SCF_EDA_V_NPN_ON +#define SCF_EDA_V_PNP_OFF SCF_EDA_V_NPN_OFF + enum { SCF_EDA_Battery_NEG, SCF_EDA_Battery_POS, @@ -63,10 +68,10 @@ enum { }; enum { - SCF_EDA_PNP_B, - SCF_EDA_PNP_E, - SCF_EDA_PNP_C, - SCF_EDA_PNP_NB, + SCF_EDA_PNP_B = SCF_EDA_NPN_B, + SCF_EDA_PNP_E = SCF_EDA_NPN_E, + SCF_EDA_PNP_C = SCF_EDA_NPN_C, + SCF_EDA_PNP_NB = SCF_EDA_NPN_NB, }; typedef struct { @@ -301,7 +306,7 @@ SCF_PACK_INFO_OBJS(ScfEboard, functions, ScfEfunction), SCF_PACK_END(ScfEboard) -ScfEconn* scf_econn__alloc(); +ScfEconn* scf_econn__alloc(); int scf_econn__add_cid(ScfEconn* ec, uint64_t cid); int scf_econn__del_cid(ScfEconn* ec, uint64_t cid); -- 2.25.1