support 'sub' in native/eda module
authoryu.dongliang <18588496441@163.com>
Mon, 10 Jun 2024 08:38:46 +0000 (16:38 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 10 Jun 2024 08:38:46 +0000 (16:38 +0800)
native/eda/scf_eda.c
native/eda/scf_eda_inst.c
native/eda/scf_eda_pack.c
native/eda/scf_eda_pack.h

index e45b6962aef6f9d1261f85bab56181acf17198f4..c9aedb1817d8591d9edb5c5b5fb89d20cda37d50 100644 (file)
@@ -182,4 +182,3 @@ scf_native_ops_t    native_ops_eda = {
 
        .select_inst     = scf_eda_select_inst,
 };
-
index 3f757b59c3ba8dcc4e9439f41563fcdb61ae67f5..3b19870a5d42b4ebae962874f5a33e7781f96c93 100644 (file)
@@ -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, &not);
+               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},
index c837e73ea6eef4f4a91304d96a02833643aaf3bc..cd251bf89978bb3e5331f6ba7e62167fd4846df4 100644 (file)
@@ -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)
index 1f48b4cfd256374096f68a4d9ec0bbb75d1b9387..cf2a246d8e8efaa52cc58a3b22563fb163eee763 100644 (file)
@@ -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);