From 859b16f15966229a6ccead162a83056b64cfa4dc Mon Sep 17 00:00:00 2001 From: "raoxianhong@jingjiamicro.com" Date: Wed, 11 Aug 2021 06:29:05 +0800 Subject: [PATCH] 202108110628 --- bignumber/CMakeLists.txt | 2 + examples/hdl4secnn/googlenet/verilog/main.c | 2 +- hdl4secell/include/hdl4secell.h | 1 + hdl4secell/src/hdl4se_variable.c | 36 +++++++++++++++++ hdl4sesim/CMakeLists.txt | 2 + hdl4sesim/src/hdl4sesim.c | 12 +++++- hdl4sesim/src/hdl4sevcdfile.c | 45 +++++++++++++++------ 7 files changed, 86 insertions(+), 14 deletions(-) diff --git a/bignumber/CMakeLists.txt b/bignumber/CMakeLists.txt index 26bd034..5b4cbca 100644 --- a/bignumber/CMakeLists.txt +++ b/bignumber/CMakeLists.txt @@ -8,6 +8,8 @@ add_library (bignumber STATIC "src/bignumber.c" ) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + include_directories("../../lcom/include") include_directories("../bignumber/include") include_directories("../hdl4seutils/include") diff --git a/examples/hdl4secnn/googlenet/verilog/main.c b/examples/hdl4secnn/googlenet/verilog/main.c index d797472..2612418 100644 --- a/examples/hdl4secnn/googlenet/verilog/main.c +++ b/examples/hdl4secnn/googlenet/verilog/main.c @@ -49,7 +49,7 @@ unsigned long long clocks = 0; static int running = 1; -#define VCDOUTPUT 0 +#define VCDOUTPUT 1 int cnnInit(); diff --git a/hdl4secell/include/hdl4secell.h b/hdl4secell/include/hdl4secell.h index fba5aae..8c44f0a 100644 --- a/hdl4secell/include/hdl4secell.h +++ b/hdl4secell/include/hdl4secell.h @@ -230,6 +230,7 @@ int varGet_S32(ModuleVariable * a); unsigned int varGet_U32(ModuleVariable * a); long long varGet_S64(ModuleVariable * a); unsigned long long varGet_U64(ModuleVariable * a); +int varGetStr(ModuleVariable* a, int base, char* str, int buflen); ModuleVariable* variableCreate(int type, int width, int portdirect, int isunsigned, const char* name); int variableDestroy(ModuleVariable* var); diff --git a/hdl4secell/src/hdl4se_variable.c b/hdl4secell/src/hdl4se_variable.c index bb4ec66..72e8448 100644 --- a/hdl4secell/src/hdl4se_variable.c +++ b/hdl4secell/src/hdl4se_variable.c @@ -325,6 +325,42 @@ ModuleVariable* varConstStr(const char* str) return temp; } +int varGetStr(ModuleVariable* pobj, int base, char* str, int buflen) +{ + int i; + int bc; + str[0] = 0; + bc = pobj->width; + if (bc == 0) { + strcpy(str, "0"); + return 0; + } + if (base == 2) { + if (pobj->width < buflen - 1) { + buflen = pobj->width; + } + for (i = 0; i < buflen; i++) { + str[buflen - 1 - i] = (pobj->data & (1llu << i)) ? '1' : '0'; + } + str[buflen] = '\0'; + + } + else if (base == 10) { + if (pobj->isunsigned) + sprintf(str, "%llu", pobj->data); + else + sprintf(str, "%lld", pobj->int64); + } + else { + if (pobj->isunsigned) + sprintf(str, "%d'h%llx", bc, pobj->data); + else + sprintf(str, "%d'sh%llx", bc, pobj->data); + } + return 0; +} + + ModuleVariable* varConst(int width, unsigned long long v) { ModuleVariable* temp = varTemp(width, 1); diff --git a/hdl4sesim/CMakeLists.txt b/hdl4sesim/CMakeLists.txt index a3d43ab..3b11fc7 100644 --- a/hdl4sesim/CMakeLists.txt +++ b/hdl4sesim/CMakeLists.txt @@ -10,6 +10,8 @@ add_library (hdl4sesim STATIC "src/hdl4sevcdfile.c" ) +add_definitions(-D_CRT_SECURE_NO_WARNINGS) + FIND_PACKAGE( OpenMP REQUIRED) if(OPENMP_FOUND) message("OPENMP FOUND") diff --git a/hdl4sesim/src/hdl4sesim.c b/hdl4sesim/src/hdl4sesim.c index dacf021..cc41eb2 100644 --- a/hdl4sesim/src/hdl4sesim.c +++ b/hdl4sesim/src/hdl4sesim.c @@ -231,7 +231,7 @@ static int hdl4sesim_hdl4se_simulator_SetReset(HOBJECT object, int reset) return 0; } -#define THREADCOUNT 10 +#define THREADCOUNT 9 static int hdl4sesim_hdl4se_simulator_ClkTick(HOBJECT object) { @@ -509,6 +509,16 @@ softmax_168 complete 0.0356 n04505470 typewriter keyboard clocks: 1818624, TSPD=9571.705263cps, LSPD=8192.000000cps +usebitint==0 +clocks: 1802240, TSPD=14080.000000cps, LSPD=8192.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=14097.860465cps, LSPD=16384.000000cps + threadcount=8 clocks: 1867776, TSPD=9529.469388cps, LSPD=16384.000000cps softmax_168 complete diff --git a/hdl4sesim/src/hdl4sevcdfile.c b/hdl4sesim/src/hdl4sevcdfile.c index 2807c85..eaa0c6d 100644 --- a/hdl4sesim/src/hdl4sevcdfile.c +++ b/hdl4sesim/src/hdl4sevcdfile.c @@ -57,9 +57,9 @@ const char* signal_code_char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV typedef struct _signalitem { IHDL4SEModuleVar* detector; - IBigNumber** lastvalue; - const char* unitname; - const char* signalname; + ModuleVariable* lastvalue; + char* unitname; + char* signalname; int index; int width; char vcdname[VCDNAMELEN + 1]; @@ -71,10 +71,11 @@ typedef struct _sHDL4SEVcdFile { HDL4SEWAVEOUTPUT_VARDECLARE IHDL4SEModuleVar* recordmodule; - const char* filename; + char* filename; FILE* pFile; - - IBigNumber** tempvar; + + ModuleVariable *tempvar; + char* tempbuf; IDListVar signallist; @@ -112,11 +113,15 @@ static int hdl4sevcdfileCreate(const PARAMITEM* pParams, int paramcount, HOBJECT if (pParams[i].name == PARAMID_HDL4SEVCDFILE_FILENAME) { if (pobj->filename != NULL) mt_free(pobj->filename); - pobj->filename = strdup((const char *)pParams[i].pvalue); + pobj->filename = STRDUP((const char *)pParams[i].pvalue); } } dlistInit(&pobj->signallist); +#if USEBIGINT pobj->tempvar = bigintegerCreate(32); +#else + pobj->tempvar = variableCreate(VTYPE_TEMP, 64, 0, 1, ""); +#endif pobj->tempbuf = mt_malloc(MAXWIDTH); /* 返回生成的对象 */ OBJECT_RETURN_GEN(hdl4sevcdfile, pobj, pObject, CLSID_HDL4SEVCDFILE); @@ -177,8 +182,8 @@ static int hdl4sevcdfile_hdl4se_waveoutput_AddSignal(HOBJECT object, const char pitem = (signalitem*)mt_malloc(sizeof(signalitem)); if (pitem == NULL) return -1; - pitem->unitname = strdup(unitname); - pitem->signalname = strdup(signalname); + pitem->unitname = STRDUP(unitname); + pitem->signalname = STRDUP(signalname); pitem->detector = NULL; pitem->lastvalue = NULL; item = hdl4seCreatePtrListItem(hdl4seCreateConstString(signalname), pitem); @@ -209,6 +214,7 @@ static int hdl4sevcdfile_output_item_data(IDListVarPtr item, sHDL4SEVcdFile* pob if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (const void**)&itemobj)) { objectCall1(itemobj, GetData, &pitem); if (pitem->detector != NULL) { +#if USEBIGINT objectCall1(pobj->tempvar, SetWidth, pitem->width); hdl4se_module_GetValue(&pitem->detector->data, pitem->index, pitem->width, pobj->tempvar); if (!objectCall1(pobj->tempvar, IsEQ, pitem->lastvalue)) { @@ -216,6 +222,15 @@ static int hdl4sevcdfile_output_item_data(IDListVarPtr item, sHDL4SEVcdFile* pob objectCall3(pitem->lastvalue, GetStr, 2, pobj->tempbuf, MAXWIDTH); fprintf(pobj->pFile, "b%s %s\n", pobj->tempbuf, pitem->vcdname); } +#else + pobj->tempvar->width = pitem->width; + hdl4se_module_GetValue(&pitem->detector->data, pitem->index, pitem->width, pobj->tempvar); + if (pobj->tempvar->data != pitem->lastvalue->data) { + pitem->lastvalue->data = pobj->tempvar->data; + varGetStr(pitem->lastvalue, 2, pobj->tempbuf, MAXWIDTH); + fprintf(pobj->pFile, "b%s %s\n", pobj->tempbuf, pitem->vcdname); + } +#endif } objectRelease(itemobj); } @@ -229,7 +244,11 @@ static int hdl4sevcdfile_output_item_data_init(IDListVarPtr item, sHDL4SEVcdFile if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (const void**)&itemobj)) { objectCall1(itemobj, GetData, &pitem); if (pitem->detector != NULL) { +#if USEBIGINT objectCall3(pitem->lastvalue, GetStr, 2, pobj->tempbuf, MAXWIDTH); +#else + varGetStr(pitem->lastvalue, 2, pobj->tempbuf, MAXWIDTH); +#endif fprintf(pobj->pFile, "b%s %s\n", pobj->tempbuf, pitem->vcdname); } objectRelease(itemobj); @@ -263,9 +282,7 @@ static int hdl4sevcdfile_init_signal_item(IDListVarPtr item, init_signal_list_pa { signalitem* pitem; IMapStr2PtrItem** itemobj; - const char* pname; if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (const void**)&itemobj)) { - objectCall1(itemobj, GetName, &pname); objectCall1(itemobj, GetData, &pitem); if (strcmp(param->pathname, pitem->unitname) == 0) { int count, i; @@ -281,7 +298,11 @@ static int hdl4sevcdfile_init_signal_item(IDListVarPtr item, init_signal_list_pa int j; int codeindex = param->pobj->signalindex++; pitem->detector = param->detector; +#if USEBIGINT pitem->lastvalue = bigintegerCreate2(var->width, var->isunsigned); +#else + pitem->lastvalue = variableCreate(VTYPE_TEMP, var->width, 0, var->isunsigned, ""); +#endif pitem->index = i; pitem->width = var->width; for (j = 0; j < VCDNAMELEN; j++) { @@ -373,7 +394,7 @@ IHDL4SEWaveOutput** hdl4sesimCreateVCDFile(const char* filename) PARAMITEM param; IHDL4SEWaveOutput** vcdfile; param.name = PARAMID_HDL4SEVCDFILE_FILENAME; - param.pvalue = filename; + param.pvalue = (void *)filename; A_u_t_o_registor_hdl4sevcdfile(); ret = objectCreateEx(CLSID_HDL4SEVCDFILE, ¶m, 1, IID_HDL4SEWAVEOUTPUT, (const void**)&vcdfile); return vcdfile; -- GitLab