提交 15e40781 编写于 作者: 饶先宏's avatar 饶先宏

202108111906

......@@ -99,6 +99,12 @@ typedef struct _sGeneralModule {
#define USEBIGINT 0
enum varupdatefunc {
VUF_UPDATED,
VUF_WAITUPDATE,
VUF_UPDATING,
};
typedef struct sModuleVariable {
struct sModuleVariable * pNext, *pLast;
int index;
......@@ -145,6 +151,7 @@ typedef struct sModuleFunction {
void* pobj;
MODULE_FUNC func;
MODULE_FUNC cur_func;
int callit;
PointerArray variables; /* 影响的variables */
}ModuleFunction;
......@@ -239,7 +246,16 @@ int hdl4seCheckVariableArray(PointerArray* array);
ModuleFunction* functionCreateFunc(MODULE_FUNC func, void * pobj);
ModuleFunction* functionCreateGetValue(ModuleVariable * var);
int functionDestroy(ModuleFunction* func);
int functionCallAndSetNone(ModuleFunction* func);
//int functionCallAndSetNone(ModuleFunction* func);
#define functionCallAndSetNone(obj) \
do { \
ModuleFunction * func = (ModuleFunction *)obj; \
int callit = LOCKED_SWAP(func->callit, 0); \
if (callit) { \
func->func(func->pobj, func->var); \
} \
} while (0)
int hdl4se_split_string(const char* string, char** substr, int substrcount, int gap);
unsigned int hdl4seGetParamUint32(const char* param);
......
......@@ -59,6 +59,7 @@ ModuleFunction* functionCreateFunc(MODULE_FUNC func, void* pobj)
function->func = function->cur_func = func;
function->pobj = pobj;
function->var = NULL;
function->callit = 1;
pointerarrayInit(&function->variables);
return function;
}
......@@ -77,12 +78,14 @@ static int gen_none(void* p, void* v)
return 0;
}
/*
int functionCallAndSetNone(ModuleFunction* func)
{
MODULE_FUNC genfunc;
genfunc = LOCKED_SWAP_POINTER(func->cur_func, gen_none);
return genfunc(func->pobj, func->var);
}
*/
int functionDestroy(ModuleFunction* func)
{
......
......@@ -71,18 +71,14 @@ inline static void hdl4seUpdateVariableNone(ModuleVariable* var)
inline static void hdl4seUpdateVariableGenFunc(ModuleVariable* var)
{
//var->func_UpdateVariable = hdl4seUpdateVariableNone;
var->updatefunc = 0;
functionCallAndSetNone(var->moduledata->funcs.array[var->genfuncindex]);
var->updatefunc = 0;
}
inline static void hdl4seUpdateVariableGetValue(ModuleVariable* var)
{
int updatefunc = var->updatefunc;
// var->func_UpdateVariable = hdl4seUpdateVariableNone;
//functionCallAndSetNone(var->moduledata->funcs.array[var->genfuncindex]);
hdl4se_module_GetValue(&var->module->data, var->moduleportindex, var->width, var);
var->updatefunc = 0;
hdl4se_module_GetValue(&var->module->data, var->moduleportindex, var->width, var);// (var->type == VTYPE_REG) ? var->data_reg : var->data);
}
......@@ -110,16 +106,22 @@ do { \
#define UpdateVariable(v) \
do { \
if (v->type != VTYPE_REG) { \
threadlockLock(v->lock); \
if (v->updatefunc != 0) { \
if (v->updatefunc == 1) { \
hdl4seUpdateVariableGenFunc(v); \
} \
else { \
hdl4seUpdateVariableGetValue(v); \
int updatefunc; \
updatefunc = LOCKED_COMP_SWAP(v->updatefunc, VUF_UPDATING, VUF_WAITUPDATE); \
if (updatefunc != VUF_UPDATED) { \
threadlockLock(v->lock); \
if (updatefunc == VUF_WAITUPDATE) { \
if (v->genfuncindex >= 0) { \
functionCallAndSetNone(v->moduledata->funcs.array[v->genfuncindex]); \
LOCKED_SWAP(v->updatefunc, VUF_UPDATED); \
} \
else if (v->module != NULL) { \
hdl4se_module_GetValue(&v->module->data, v->moduleportindex, v->width, v); \
LOCKED_SWAP(v->updatefunc, VUF_UPDATED); \
} \
} \
threadlockUnlock(v->lock); \
} \
threadlockUnlock(v->lock); \
} \
} while (0)
#endif
......@@ -662,26 +664,27 @@ int hdl4se_module_Setup(sGeneralModule* pobj)
var->data = var->data_reg;
#endif
//var->func_UpdateVariable = hdl4seUpdateVariableNone;
var->updatefunc = 0;
var->updatefunc = VUF_UPDATED;
}
else if (var->genfuncindex >= 0) {
//var->func_UpdateVariable = hdl4seUpdateVariableGenFunc;
var->updatefunc = 1;
var->updatefunc = VUF_WAITUPDATE;
}
else if (var->module != NULL) {
//var->func_UpdateVariable = hdl4seUpdateVariableGetValue;
var->updatefunc = 2;
var->updatefunc = VUF_WAITUPDATE;
}
else {
//var->func_UpdateVariable = hdl4seUpdateVariableNone;
var->updatefunc = 0;
var->updatefunc = VUF_UPDATED;
}
}
for (i = 0; i < pobj->funcs.itemcount; i++) {
ModuleFunction* function = (ModuleFunction *)pobj->funcs.array[i];
function->cur_func = function->func;
//function->cur_func = function->func;
function->callit = 1;
}
return 0;
......
......@@ -79,7 +79,7 @@ ModuleVariable* variableCreate(int type, int width, int portdirect, int isunsign
var->data_reg = bigintegerCreate2(width, isunsigned);
}
#endif
var->updatefunc = 0;
var->updatefunc = VUF_WAITUPDATE;
var->lock = threadlockCreate();
return var;
}
......
......@@ -231,7 +231,7 @@ static int hdl4sesim_hdl4se_simulator_SetReset(HOBJECT object, int reset)
return 0;
}
#define THREADCOUNT 9
#define THREADCOUNT 3
static int hdl4sesim_hdl4se_simulator_ClkTick(HOBJECT object)
{
......@@ -297,6 +297,24 @@ softmax_168 complete
0.0356 n04505470 typewriter keyboard
clocks: 1884160, TSPD=1359.422799cps, LSPD=1170.285714cps
clocks: 1802240, TSPD=4681.142857cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0438 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=4687.175258cps, LSPD=5461.333333cps
clocks: 1802240, TSPD=3935.021834cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=3944.954447cps, LSPD=5461.333333cps
threadcount=3
clocks : 1867776, TSPD = 1552.598504cps, LSPD = 2048.000000cps
softmax_168 complete
......@@ -317,6 +335,23 @@ softmax_168 complete
0.0356 n04505470 typewriter keyboard
clocks: 1884160, TSPD=1312.089136cps, LSPD=1260.307692cps
clocks: 1802240, TSPD=4767.830688cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=4760.795812cps, LSPD=4096.000000cps
clocks: 1802240, TSPD=4353.236715cps, LSPD=5461.333333cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=4350.775120cps, LSPD=4096.000000cps
threadcount=2
clocks: 1867776, TSPD=1562.992469cps, LSPD=1365.333333cps
......@@ -338,6 +373,34 @@ softmax_168 complete
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=1752.046243cps, LSPD=1820.444444cps
usebigint == 0
clocks: 1802240, TSPD=3746.860707cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=3749.740206cps, LSPD=4096.000000cps
clocks: 1802240, TSPD=4114.703196cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=4114.533937cps, LSPD=4096.000000cps
clocks: 1802240, TSPD=3859.186296cps, LSPD=4096.000000cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=3861.197452cps, LSPD=4096.000000cps
threadcount=1
clocks: 1867776, TSPD=993.497872cps, LSPD=963.764706cps
softmax_168 complete
......@@ -348,6 +411,25 @@ softmax_168 complete
0.0356 n04505470 typewriter keyboard
clocks: 1884160, TSPD=993.755274cps, LSPD=1024.000000cps
usebitint == 0
clocks: 1802240, TSPD=2549.137199cps, LSPD=2730.666667cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=2547.092437cps, LSPD=2340.571429cps
clocks: 1802240, TSPD=2802.861586cps, LSPD=2730.666667cps
softmax_168 complete
0.4901 n03085013 computer keyboard, keypad
0.1591 n04264628 space bar
0.0543 n04074963 remote control, remote
0.0439 n03832673 notebook, notebook computer
0.0356 n04505470 typewriter keyboard
clocks: 1818624, TSPD=2802.194145cps, LSPD=2730.666667cps
i9 10900 32G
threadcount=32
clocks: 1867776, TSPD=8768.901408cps, LSPD=8192.000000cps
......
......@@ -61,7 +61,8 @@ void mt_free(void*);
#define LOCKED_INCREMENT(p) InterlockedIncrement(&p)
#define LOCKED_DECREMENT(p) InterlockedDecrement(&p)
#define LOCKED_SWAP_POINTER(p, v) InterlockedExchangePointer(&p, v)
#define LOCKED_SWAP(p, v) InterlockedExchange(&p, v)
#define LOCKED_COMP_SWAP(p, v, c) InterlockedCompareExchange(&p, v, c)
#define STRDUP _strdup
#endif
......@@ -69,7 +70,8 @@ void mt_free(void*);
#define LOCKED_INCREMENT(p) __sync_fetch_and_add(&p, 1);
#define LOCKED_DECREMENT(p) __sync_fetch_and_sub(&p, 1);
#define LOCKED_SWAP_POINTER(p, v) __sync_val_compare_and_swap(&p, p, v)
#define LOCKED_SWAP(p, v) __sync_val_compare_and_swap(&p, p, v)
#define LOCKED_COMP_SWAP(p, v, c) __sync_val_compare_and_swap(&p, c, v)
#define STRDUP strdup
#endif
......@@ -78,7 +80,14 @@ void mt_free(void*);
#define LOCKED_DECREMENT(p) p--
static void* locked_swap_pointer(void** p, void* v)
{
void* ret = v;
void* ret = *p;
*p = v;
return ret;
}
#define LOCKED_SWAP_POINTER(p, v) locked_swap_pointer(&p, v)
static long locked_swap(long * p, long v)
{
long ret = *p;
*p = v;
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册