提交 99847b3b 编写于 作者: 饶先宏's avatar 饶先宏

202105232112

上级 a61219fa
...@@ -158,7 +158,7 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand) ...@@ -158,7 +158,7 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand)
sign = 0; sign = 0;
if (signexpand) { if (signexpand) {
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH-1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH-1)));
} }
blen = (width + CELL_WIDTH - 1) / CELL_WIDTH; blen = (width + CELL_WIDTH - 1) / CELL_WIDTH;
...@@ -375,6 +375,7 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst ...@@ -375,6 +375,7 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
lastnum: lastnum:
if (nstr != NULL) if (nstr != NULL)
*nstr = strt; *nstr = strt;
bigint_bn_SetWidth(object, pobj->width, 1);
return 0; return 0;
} }
...@@ -691,7 +692,7 @@ static int bigint_bn_SAR(HOBJECT object, int bits) ...@@ -691,7 +692,7 @@ static int bigint_bn_SAR(HOBJECT object, int bits)
if (bits < 0) if (bits < 0)
return bigint_bn_SHL(object, -bits); return bigint_bn_SHL(object, -bits);
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
ito = 0; ito = 0;
ifrom = bits / CELL_WIDTH; ifrom = bits / CELL_WIDTH;
if (ifrom >= pobj->buflen) { if (ifrom >= pobj->buflen) {
...@@ -828,7 +829,7 @@ static int bigint_bn_IsNeg(HOBJECT object) ...@@ -828,7 +829,7 @@ static int bigint_bn_IsNeg(HOBJECT object)
int bc, sign; int bc, sign;
pobj = (sBigInteger*)objectThis(object); pobj = (sBigInteger*)objectThis(object);
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
return sign?1:0; return sign?1:0;
} }
...@@ -843,11 +844,10 @@ static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src) ...@@ -843,11 +844,10 @@ static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src)
return 0; return 0;
} }
psrc = (sBigInteger*)objectThis(src); psrc = (sBigInteger*)objectThis(src);
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH; bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
if (sign != signsrc) { if (sign != signsrc) {
return 0; return 0;
} }
...@@ -883,9 +883,9 @@ static int bigint_bn_IsLE(HOBJECT object, HOBJECT src) ...@@ -883,9 +883,9 @@ static int bigint_bn_IsLE(HOBJECT object, HOBJECT src)
} }
psrc = (sBigInteger*)objectThis(src); psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH; bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) { if (sign == 0 && signsrc != 0) {
return 0; return 0;
} }
...@@ -946,9 +946,9 @@ static int bigint_bn_IsLT(HOBJECT object, HOBJECT src) ...@@ -946,9 +946,9 @@ static int bigint_bn_IsLT(HOBJECT object, HOBJECT src)
} }
psrc = (sBigInteger*)objectThis(src); psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH; bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH; bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) { if (sign == 0 && signsrc != 0) {
return 0; return 0;
} }
......
此差异已折叠。
...@@ -58,7 +58,7 @@ int StopRunning() ...@@ -58,7 +58,7 @@ int StopRunning()
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
sim = hdl4sesimCreateSimulator(); sim = hdl4sesimCreateSimulator();
topmodule = hdl4seCreateMain2(NULL, "", "main"); topmodule = hdl4seCreateMain(NULL, "", "main");
gui = guiCreate(0xf0000000, "digitled"); gui = guiCreate(0xf0000000, "digitled");
objectCall1(sim, SetTopModule, topmodule); objectCall1(sim, SetTopModule, topmodule);
objectCall2(sim, AddDevice, gui, 0xf0000000); objectCall2(sim, AddDevice, gui, 0xf0000000);
......
...@@ -67,6 +67,7 @@ typedef struct _sDigitLed { ...@@ -67,6 +67,7 @@ typedef struct _sDigitLed {
GLFWwindow* window; GLFWwindow* window;
int width; int width;
int height; int height;
int count;
unsigned int baseaddr; unsigned int baseaddr;
...@@ -172,6 +173,7 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb ...@@ -172,6 +173,7 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb
pobj->width = WIDTH; pobj->width = WIDTH;
pobj->height = HEIGHT; pobj->height = HEIGHT;
pobj->wRead = 0; pobj->wRead = 0;
pobj->count = 0;
pobj->wRead_cur = 0; pobj->wRead_cur = 0;
pobj->window = glfwCreateWindow(WIDTH, HEIGHT, "DIGIT LED", NULL, NULL); pobj->window = glfwCreateWindow(WIDTH, HEIGHT, "DIGIT LED", NULL, NULL);
if (!pobj->window) if (!pobj->window)
...@@ -184,12 +186,6 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb ...@@ -184,12 +186,6 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb
glfwSetWindowAspectRatio(pobj->window, 3, 1); glfwSetWindowAspectRatio(pobj->window, 3, 1);
glfwSetKeyCallback(pobj->window, key_callback); glfwSetKeyCallback(pobj->window, key_callback);
/*
glfwSetFramebufferSizeCallback(window, reshape);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
*/
glfwMakeContextCurrent(pobj->window); glfwMakeContextCurrent(pobj->window);
gladLoadGL(glfwGetProcAddress); gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(1); glfwSwapInterval(1);
...@@ -374,42 +370,44 @@ static int digitled_hdl4se_unit_ClkTick(HOBJECT object) ...@@ -374,42 +370,44 @@ static int digitled_hdl4se_unit_ClkTick(HOBJECT object)
#define LEDTHINY 0.04f #define LEDTHINY 0.04f
#define LEDANGLEY 0.06f #define LEDANGLEY 0.06f
#define LEDOFFS 0.00f
static int digitled_DrawDigit(sDigitLed* pobj, int ind) static int digitled_DrawDigit(sDigitLed* pobj, int ind)
{ {
float xoffs = -0.9f + ind * (LEDWIDTH + LEDTHINX * 5); float xoffs = -0.9f + (9-ind) * (LEDWIDTH + LEDTHINX * 5);
float yoffs = -LEDHEIGHT / 2.0f + 0.2f; float yoffs = -LEDHEIGHT / 2.0f + 0.2f;
/* seg a */ /* seg a */
glColor3f(pobj->ledcolor[ind][0][0], pobj->ledcolor[ind][0][1], pobj->ledcolor[ind][0][2]); glColor3f(pobj->ledcolor[ind][0][0], pobj->ledcolor[ind][0][1], pobj->ledcolor[ind][0][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs + LEDGAPX, yoffs + LEDHEIGHT); glVertex2f(xoffs + LEDOFFS + LEDGAPX, yoffs + LEDHEIGHT);
glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); glVertex2f(xoffs + LEDOFFS + LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY);
glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY);
glVertex2f(xoffs + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT); glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT);
glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY);
glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); glVertex2f(xoffs + LEDOFFS + LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY);
glEnd(); glEnd();
/* seg b */ /* seg b */
glColor3f(pobj->ledcolor[ind][1][0], pobj->ledcolor[ind][1][1], pobj->ledcolor[ind][1][2]); glColor3f(pobj->ledcolor[ind][1][0], pobj->ledcolor[ind][1][1], pobj->ledcolor[ind][1][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT - LEDGAPY); glVertex2f(xoffs + LEDOFFS + LEDWIDTH, yoffs + LEDHEIGHT - LEDGAPY);
glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glVertex2f(xoffs + LEDOFFS + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f + LEDGAPY);
glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY);
glEnd(); glEnd();
/* seg c */ /* seg c */
glColor3f(pobj->ledcolor[ind][2][0], pobj->ledcolor[ind][2][1], pobj->ledcolor[ind][2][2]); glColor3f(pobj->ledcolor[ind][2][0], pobj->ledcolor[ind][2][1], pobj->ledcolor[ind][2][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f - LEDGAPY);
glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH, yoffs + LEDGAPY); glVertex2f(xoffs + LEDWIDTH, yoffs + LEDGAPY);
glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDANGLEY);
glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY);
glEnd(); glEnd();
/* seg d */ /* seg d */
...@@ -426,34 +424,34 @@ static int digitled_DrawDigit(sDigitLed* pobj, int ind) ...@@ -426,34 +424,34 @@ static int digitled_DrawDigit(sDigitLed* pobj, int ind)
/* seg e */ /* seg e */
glColor3f(pobj->ledcolor[ind][4][0], pobj->ledcolor[ind][4][1], pobj->ledcolor[ind][4][2]); glColor3f(pobj->ledcolor[ind][4][0], pobj->ledcolor[ind][4][1], pobj->ledcolor[ind][4][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); glVertex2f(xoffs + LEDOFFS / 2.0f, yoffs + LEDHEIGHT / 2.0f - LEDGAPY);
glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY);
glVertex2f(xoffs + LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs + LEDTHINX, yoffs + LEDANGLEY);
glVertex2f(xoffs, yoffs + LEDGAPY); glVertex2f(xoffs, yoffs + LEDGAPY);
glVertex2f(xoffs - LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs - LEDTHINX, yoffs + LEDANGLEY);
glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY);
glEnd(); glEnd();
/* seg f */ /* seg f */
glColor3f(pobj->ledcolor[ind][5][0], pobj->ledcolor[ind][5][1], pobj->ledcolor[ind][5][2]); glColor3f(pobj->ledcolor[ind][5][0], pobj->ledcolor[ind][5][1], pobj->ledcolor[ind][5][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs, yoffs + LEDHEIGHT - LEDGAPY); glVertex2f(xoffs + LEDOFFS, yoffs + LEDHEIGHT - LEDGAPY);
glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glVertex2f(xoffs + LEDOFFS + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY);
glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY);
glVertex2f(xoffs, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); glVertex2f(xoffs + LEDOFFS / 2.0f, yoffs + LEDHEIGHT / 2.0f + LEDGAPY);
glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); glVertex2f(xoffs + LEDOFFS / 2.0f - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY);
glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glVertex2f(xoffs + LEDOFFS - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY);
glEnd(); glEnd();
/* seg g */ /* seg g */
glColor3f(pobj->ledcolor[ind][6][0], pobj->ledcolor[ind][6][1], pobj->ledcolor[ind][6][2]); glColor3f(pobj->ledcolor[ind][6][0], pobj->ledcolor[ind][6][1], pobj->ledcolor[ind][6][2]);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex2f(xoffs + LEDGAPX, yoffs + LEDHEIGHT / 2.0f); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDGAPX, yoffs + LEDHEIGHT / 2.0f);
glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY);
glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY);
glVertex2f(xoffs + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT / 2.0f); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT / 2.0f);
glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY);
glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); glVertex2f(xoffs + LEDOFFS / 2.0f + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY);
glEnd(); glEnd();
/* seg dp */ /* seg dp */
...@@ -509,10 +507,14 @@ static int digitled_hdl4se_unit_Setup(HOBJECT object) ...@@ -509,10 +507,14 @@ static int digitled_hdl4se_unit_Setup(HOBJECT object)
/*读信号和读地址寄存一拍*/ /*读信号和读地址寄存一拍*/
pobj->wRead = pobj->wRead_cur; pobj->wRead = pobj->wRead_cur;
pobj->bReadAddr = pobj->bReadAddr_cur; pobj->bReadAddr = pobj->bReadAddr_cur;
pobj->count++;
/* 每256个周期新绘制一次 */
if ((pobj->count & 0xff) == 0) {
if (digitled_Render(pobj)) { if (digitled_Render(pobj)) {
/* Swap buffers */ /* Swap buffers */
glfwSwapBuffers(pobj->window); glfwSwapBuffers(pobj->window);
} }
}
glfwPollEvents(); glfwPollEvents();
......
...@@ -16,7 +16,7 @@ add_library (hdl4secell STATIC ...@@ -16,7 +16,7 @@ add_library (hdl4secell STATIC
"src/hdl4se_reg.c" "src/hdl4se_reg.c"
"src/hdl4se_bind2.c" "src/hdl4se_bind2.c"
"src/hdl4se_bind3.c" "src/hdl4se_bind3.c"
"src/hdl4se_bind4.c") "src/hdl4se_bind4.c" "src/hdl4se_split2.c" "src/hdl4se_split4.c" "src/hdl4se_unop.c" "src/hdl4se_binop.c")
include_directories("../../lcom/include") include_directories("../../lcom/include")
include_directories("../hdl4secell/include") include_directories("../hdl4secell/include")
......
...@@ -121,7 +121,7 @@ DEFINE_GUID(CLSID_HDL4SE_CONST, 0x8FBE5B87, 0xB484, 0x4f95, 0x82, 0x91, 0xDB, 0x ...@@ -121,7 +121,7 @@ DEFINE_GUID(CLSID_HDL4SE_CONST, 0x8FBE5B87, 0xB484, 0x4f95, 0x82, 0x91, 0xDB, 0x
#define BINOP_MUL 2 #define BINOP_MUL 2
#define BINOP_DIV 3 #define BINOP_DIV 3
#define BINOP_EQ 4 #define BINOP_EQ 4
#define BINOP_NEQ 5 #define BINOP_NE 5
#define BINOP_LT 6 #define BINOP_LT 6
#define BINOP_LE 7 #define BINOP_LE 7
#define BINOP_GE 8 #define BINOP_GE 8
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
/* /*
HDL4SE_BIND4 HDL4SE_BIND4
instance parameter: "8, 9, 10", inputwidth0=8, inputwidth1=9, inputwidth2=10 instance parameter: "8, 9, 10, 11", inputwidth0=8, inputwidth1=9, inputwidth2=10
outputwidth=8+9+10 outputwidth=8+9+10
*/ */
......
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* hdl4se_binop.c
修改记录:
202105230844: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "bignumber.h"
#include "hdl4secell.h"
/*
#define BINOP_ADD 0
#define BINOP_SUB 1
#define BINOP_MUL 2
#define BINOP_DIV 3
#define BINOP_EQ 4
#define BINOP_NE 5
#define BINOP_LT 6
#define BINOP_LE 7
#define BINOP_GE 8
#define BINOP_GT 9
#define BINOP_AND 10
#define BINOP_OR 11
#define BINOP_XOR 12
*/
#define BINOP_LAST BINOP_XOR
#define INCOUNT 2
/*
hdl4se_binop
instance parameter: "8, 9, 1, 4",
inputwidth0=8, inputwidth1=9, outputwidth=1, unop=BINOP_EQ
*/
typedef struct _sHDL4SEBinop {
OBJECT_HEADER
INTERFACE_DECLARE(IHDL4SEUnit)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule** parent;
char* name;
IHDL4SEUnit** wire_in[INCOUNT];
int wire_in_index[INCOUNT];
int in_width[INCOUNT];
IBigNumber** in_data[INCOUNT];
IBigNumber** out_data;
int out_width;
int op;
int datavalid;
}sHDL4SEBinop;
OBJECT_FUNCDECLARE(hdl4se_binop, CLSID_HDL4SE_BINOP);
HDL4SEUNIT_FUNCDECLARE(hdl4se_binop, CLSID_HDL4SE_BINOP, sHDL4SEBinop);
DLIST_FUNCIMPL(hdl4se_binop, CLSID_HDL4SE_BINOP, sHDL4SEBinop);
OBJECT_FUNCIMPL(hdl4se_binop, sHDL4SEBinop, CLSID_HDL4SE_BINOP);
QUERYINTERFACE_BEGIN(hdl4se_binop, CLSID_HDL4SE_BINOP)
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SEBinop)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SEBinop)
QUERYINTERFACE_END
static const char* hdl4se_binopModuleInfo()
{
return "1.0.0-20210523.0844 HDL4SE BINOP cell";
}
static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject)
{
sHDL4SEBinop* pobj;
int i;
pobj = (sHDL4SEBinop*)malloc(sizeof(sHDL4SEBinop));
if (pobj == NULL)
return -1;
*pObject = 0;
HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_BINOP);
INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_binop, hdl4se_unit);
DLIST_VARINIT(pobj, hdl4se_binop);
for (i = 0; i < INCOUNT; i++) {
pobj->wire_in[i] = NULL;
pobj->wire_in_index[i] = 0;
pobj->in_data[i] = NULL;
pobj->in_width[i] = 0;
}
pobj->out_data = NULL;
pobj->name = NULL;
pobj->out_width = 0;
pobj->datavalid = 0;
pobj->op = -1;
pobj->parent = NULL;
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
free(pobj->name);
pobj->name = strdup(pParams[i].pvalue);
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) {
pobj->parent = (IHDL4SEModule **)pParams[i].pvalue;
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) {
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
const char* lstr;
int j;
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < INCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->in_width[j]);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
}
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->op);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
objectRelease(temp);
}
}
}
for (i = 0; i < INCOUNT; i++) {
if (pobj->in_width[i] <= 0)
return EIID_INVALIDPARAM;
pobj->in_data[i] = bigintegerCreate(pobj->in_width[i]);
}
if (pobj->out_width <= 0)
return EIID_INVALIDPARAM;
if (pobj->op < UNOP_NEG || pobj->op > BINOP_LAST)
return EIID_INVALIDPARAM;
pobj->out_data = bigintegerCreate(pobj->out_width);
/* 返回生成的对象 */
OBJECT_RETURN_GEN(hdl4se_binop, pobj, pObject, CLSID_HDL4SE_BINOP);
return EIID_OK;
}
static void hdl4se_binopDestroy(HOBJECT object)
{
sHDL4SEBinop* pobj;
int i;
pobj = (sHDL4SEBinop*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
for (i = 0; i < INCOUNT; i++) {
objectRelease(pobj->wire_in[i]);
objectRelease(pobj->in_data[i]);
}
objectRelease(pobj->out_data);
memset(pobj, 0, sizeof(sHDL4SEBinop));
free(pobj);
}
static int hdl4se_binopValid(HOBJECT object)
{
sHDL4SEBinop* pobj;
pobj = (sHDL4SEBinop*)objectThis(object);
return 1;
}
static int hdl4se_binop_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex)
{
sHDL4SEBinop* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sHDL4SEBinop*)objectThis(object);
if (index >= 0 && index < INCOUNT) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->wire_in[index]);
pobj->wire_in[index] = unit;
pobj->wire_in_index[index] = fromindex;
return 0;
}
}
return -1;
}
static int hdl4se_binop_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber ** value)
{
int i;
sHDL4SEBinop* pobj;
pobj = (sHDL4SEBinop*)objectThis(object);
if (pobj->datavalid == 0) {
for (i = 0; i < INCOUNT; i++)
objectCall3(pobj->wire_in[i], GetValue, pobj->wire_in_index[i], pobj->in_width[i], pobj->in_data[i]);
switch (pobj->op) {
case BINOP_ADD:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Add, pobj->in_data[1]);
break;
case BINOP_SUB:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Sub, pobj->in_data[1]);
break;
case BINOP_MUL:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Mul, pobj->in_data[1]);
break;
case BINOP_DIV:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Div, pobj->in_data[1]);
break;
case BINOP_EQ:
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
break;
case BINOP_NE:
objectCall1(pobj->out_data, AssignInt, 1);
if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
break;
case BINOP_LT:
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
break;
case BINOP_LE:
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
break;
case BINOP_GE:
objectCall1(pobj->out_data, AssignInt, 1);
if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
break;
case BINOP_GT:
objectCall1(pobj->out_data, AssignInt, 1);
if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
break;
case BINOP_AND:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, And, pobj->in_data[1]);
break;
case BINOP_OR:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Or, pobj->in_data[1]);
break;
case BINOP_XOR:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, Xor, pobj->in_data[1]);
break;
}
pobj->datavalid = 1;
}
objectCall1(value, Assign, pobj->out_data);
return 0;
}
static int hdl4se_binop_hdl4se_unit_ClkTick(HOBJECT object)
{
sHDL4SEBinop* pobj;
pobj = (sHDL4SEBinop*)objectThis(object);
return 0;
}
static int hdl4se_binop_hdl4se_unit_Setup(HOBJECT object)
{
sHDL4SEBinop* pobj;
pobj = (sHDL4SEBinop*)objectThis(object);
pobj->datavalid = 0;
return 0;
}
...@@ -88,7 +88,7 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* ...@@ -88,7 +88,7 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
pobj->out_data = NULL; pobj->out_data = NULL;
pobj->name = NULL; pobj->name = NULL;
pobj->width = 8; pobj->width = 0;
pobj->parent = NULL; pobj->parent = NULL;
for (i = 0; i < paramcount; i++) { for (i = 0; i < paramcount; i++) {
...@@ -109,13 +109,15 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* ...@@ -109,13 +109,15 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
} }
if (pobj->width <= 0 || pobj->width > (1 << 24)) if (pobj->width <= 0 || pobj->width > (1 << 24))
return -1; return -1;
objectCall2(temp, AssignStr, nstr, NULL); pobj->out_data = bigintegerCreate(pobj->width);
pobj->out_data = temp; objectCall2(pobj->out_data, AssignStr, nstr, NULL);
objectRelease(temp);
} }
} }
} }
if (pobj->out_data == NULL) { if (pobj->out_data == NULL) {
pobj->out_data = bigintegerCreate(pobj->width); return NULL;
} }
/* 返回生成的对象 */ /* 返回生成的对象 */
......
...@@ -207,8 +207,10 @@ static int hdl4se_mux16_hdl4se_unit_GetValue(HOBJECT object, int index, int widt ...@@ -207,8 +207,10 @@ static int hdl4se_mux16_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
sHDL4SEMux16* pobj; sHDL4SEMux16* pobj;
pobj = (sHDL4SEMux16*)objectThis(object); pobj = (sHDL4SEMux16*)objectThis(object);
if (pobj->datavalid == 0) { if (pobj->datavalid == 0) {
objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel);
objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0);
objectCall1(pobj->in_sel, GetInt, &sel); objectCall1(pobj->in_sel, GetInt, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) { if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
} }
......
...@@ -210,8 +210,10 @@ static int hdl4se_mux2_hdl4se_unit_GetValue(HOBJECT object, int index, int width ...@@ -210,8 +210,10 @@ static int hdl4se_mux2_hdl4se_unit_GetValue(HOBJECT object, int index, int width
pobj = (sHDL4SEMux2*)objectThis(object); pobj = (sHDL4SEMux2*)objectThis(object);
if (pobj->datavalid == 0) { if (pobj->datavalid == 0) {
objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel);
objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0);
objectCall1(pobj->in_sel, GetInt, &sel); objectCall1(pobj->in_sel, GetInt, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) { if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
} }
......
...@@ -207,8 +207,10 @@ static int hdl4se_mux4_hdl4se_unit_GetValue(HOBJECT object, int index, int width ...@@ -207,8 +207,10 @@ static int hdl4se_mux4_hdl4se_unit_GetValue(HOBJECT object, int index, int width
sHDL4SEMux4* pobj; sHDL4SEMux4* pobj;
pobj = (sHDL4SEMux4*)objectThis(object); pobj = (sHDL4SEMux4*)objectThis(object);
if (pobj->datavalid == 0) { if (pobj->datavalid == 0) {
objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel);
objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0);
objectCall1(pobj->in_sel, GetInt, &sel); objectCall1(pobj->in_sel, GetInt, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) { if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
} }
......
...@@ -207,8 +207,10 @@ static int hdl4se_mux8_hdl4se_unit_GetValue(HOBJECT object, int index, int width ...@@ -207,8 +207,10 @@ static int hdl4se_mux8_hdl4se_unit_GetValue(HOBJECT object, int index, int width
sHDL4SEMux8* pobj; sHDL4SEMux8* pobj;
pobj = (sHDL4SEMux8*)objectThis(object); pobj = (sHDL4SEMux8*)objectThis(object);
if (pobj->datavalid == 0) { if (pobj->datavalid == 0) {
objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel);
objectCall1(pobj->in_sel, GetInt, &sel); objectCall1(pobj->in_sel, GetInt, &sel);
objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) { if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
} }
......
...@@ -158,6 +158,7 @@ static int hdl4se_reg_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT fro ...@@ -158,6 +158,7 @@ static int hdl4se_reg_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT fro
IHDL4SEUnit** unit = NULL; IHDL4SEUnit** unit = NULL;
pobj = (sHDL4SEReg*)objectThis(object); pobj = (sHDL4SEReg*)objectThis(object);
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->wire_in);
pobj->wire_in = unit; pobj->wire_in = unit;
pobj->wire_in_index = fromindex; pobj->wire_in_index = fromindex;
return 0; return 0;
......
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* hdl4se_split2.c
修改记录:
202105230810: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "bignumber.h"
#include "hdl4secell.h"
/*
HDL4SE_SPLIT2
instance parameter: "32, 8, 4, 19, 9",
inputwidth=32
outputwidth0=8
outputfrom0=4
outputwidth1=19
outputfrom1=9
*/
#define SPLITCOUNT 2
typedef struct _sHDL4SESplit2 {
OBJECT_HEADER
INTERFACE_DECLARE(IHDL4SEUnit)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule** parent;
char* name;
IHDL4SEUnit** in;
int in_index;
IBigNumber** in_data;
IBigNumber** out_data[SPLITCOUNT];
int out_info[SPLITCOUNT][2];
int datavalid;
int width;
}sHDL4SESplit2;
OBJECT_FUNCDECLARE(hdl4se_split2, CLSID_HDL4SE_SPLIT2);
HDL4SEUNIT_FUNCDECLARE(hdl4se_split2, CLSID_HDL4SE_SPLIT2, sHDL4SESplit2);
DLIST_FUNCIMPL(hdl4se_split2, CLSID_HDL4SE_SPLIT2, sHDL4SESplit2);
OBJECT_FUNCIMPL(hdl4se_split2, sHDL4SESplit2, CLSID_HDL4SE_SPLIT2);
QUERYINTERFACE_BEGIN(hdl4se_split2, CLSID_HDL4SE_SPLIT2)
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SESplit2)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SESplit2)
QUERYINTERFACE_END
static const char* hdl4se_split2ModuleInfo()
{
return "1.0.0-20210523.0810 HDL4SE Split2 cell";
}
static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject)
{
sHDL4SESplit2* pobj;
int i;
pobj = (sHDL4SESplit2*)malloc(sizeof(sHDL4SESplit2));
if (pobj == NULL)
return -1;
*pObject = 0;
HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_SPLIT2);
INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_split2, hdl4se_unit);
DLIST_VARINIT(pobj, hdl4se_split2);
pobj->datavalid = 0;
for (i = 0; i < SPLITCOUNT; i++) {
pobj->out_data[i] = NULL;
pobj->out_info[i][0] = 0;
pobj->out_info[i][1] = 0;
}
pobj->in = NULL;
pobj->in_data = NULL;
pobj->name = NULL;
pobj->width = 8;
pobj->parent = NULL;
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
free(pobj->name);
pobj->name = strdup(pParams[i].pvalue);
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) {
pobj->parent = (IHDL4SEModule **)pParams[i].pvalue;
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) {
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
const char* lstr;
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
}
else {
return -1;
}
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][0]);
}
else {
return -1;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][1]);
}
else {
return -1;
}
lstr = nstr;
}
objectRelease(temp);
}
}
}
if (pobj->width <= 0)
return EIID_INVALIDPARAM;
for (i = 0; i < SPLITCOUNT; i++) {
if (pobj->out_info[i][0] <= 0)
return EIID_INVALIDPARAM;
if (pobj->out_info[i][0] + pobj->out_info[i][1] > pobj->width)
return EIID_INVALIDPARAM;
pobj->out_data[i] = bigintegerCreate(pobj->out_info[i][0]);
}
pobj->in_data = bigintegerCreate(pobj->width);
/* 返回生成的对象 */
OBJECT_RETURN_GEN(hdl4se_split2, pobj, pObject, CLSID_HDL4SE_SPLIT2);
return EIID_OK;
}
static void hdl4se_split2Destroy(HOBJECT object)
{
sHDL4SESplit2* pobj;
int i;
pobj = (sHDL4SESplit2*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
for (i = 0; i < SPLITCOUNT; i++) {
objectRelease(pobj->out_data[i]);
}
objectRelease(pobj->in);
objectRelease(pobj->in_data);
memset(pobj, 0, sizeof(sHDL4SESplit2));
free(pobj);
}
static int hdl4se_split2Valid(HOBJECT object)
{
sHDL4SESplit2* pobj;
pobj = (sHDL4SESplit2*)objectThis(object);
return 1;
}
static int hdl4se_split2_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex)
{
sHDL4SESplit2* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sHDL4SESplit2*)objectThis(object);
if (index == 0) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->in);
pobj->in = unit;
pobj->in_index = fromindex;
}
else {
return -2;
}
}
else {
return -1;
}
return 0;
}
static int hdl4se_split2_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber** value)
{
int i;
sHDL4SESplit2* pobj;
pobj = (sHDL4SESplit2*)objectThis(object);
if (index < 1 || index > SPLITCOUNT)
return -1;
if (pobj->datavalid == 0) {
objectCall3(pobj->in, GetValue, pobj->in_index, pobj->width, pobj->in_data);
pobj->datavalid = 1;
for (i = 0; i < SPLITCOUNT; i++) {
objectCall3(pobj->out_data[i], AssignSub, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]);
}
pobj->datavalid = 1;
}
objectCall1(value, Assign, pobj->out_data[index-1]);
return 0;
}
static int hdl4se_split2_hdl4se_unit_ClkTick(HOBJECT object)
{
sHDL4SESplit2* pobj;
pobj = (sHDL4SESplit2*)objectThis(object);
return 0;
}
static int hdl4se_split2_hdl4se_unit_Setup(HOBJECT object)
{
sHDL4SESplit2* pobj;
pobj = (sHDL4SESplit2*)objectThis(object);
pobj->datavalid = 0;
return 0;
}
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* hdl4se_split4.c
修改记录:
202105230810: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "bignumber.h"
#include "hdl4secell.h"
/*
HDL4SE_SPLIT4
instance parameter: "32, 8, 4, 19, 9, 7, 3, 11, 1",
inputwidth=32
outputwidth0=8
outputfrom0=4
outputwidth1=19
outputfrom1=9
outputwidth2=7
outputfrom2=3
outputwidth3=11
outputfrom3=1
*/
#define SPLITCOUNT 4
typedef struct _sHDL4SESplit4 {
OBJECT_HEADER
INTERFACE_DECLARE(IHDL4SEUnit)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule** parent;
char* name;
IHDL4SEUnit** in;
int in_index;
IBigNumber** in_data;
IBigNumber** out_data[SPLITCOUNT];
int out_info[SPLITCOUNT][2];
int datavalid;
int width;
}sHDL4SESplit4;
OBJECT_FUNCDECLARE(hdl4se_split4, CLSID_HDL4SE_SPLIT4);
HDL4SEUNIT_FUNCDECLARE(hdl4se_split4, CLSID_HDL4SE_SPLIT4, sHDL4SESplit4);
DLIST_FUNCIMPL(hdl4se_split4, CLSID_HDL4SE_SPLIT4, sHDL4SESplit4);
OBJECT_FUNCIMPL(hdl4se_split4, sHDL4SESplit4, CLSID_HDL4SE_SPLIT4);
QUERYINTERFACE_BEGIN(hdl4se_split4, CLSID_HDL4SE_SPLIT4)
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SESplit4)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SESplit4)
QUERYINTERFACE_END
static const char* hdl4se_split4ModuleInfo()
{
return "1.0.0-20210523.0811 HDL4SE Split4 cell";
}
static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject)
{
sHDL4SESplit4* pobj;
int i;
pobj = (sHDL4SESplit4*)malloc(sizeof(sHDL4SESplit4));
if (pobj == NULL)
return -1;
*pObject = 0;
HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_SPLIT4);
INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_split4, hdl4se_unit);
DLIST_VARINIT(pobj, hdl4se_split4);
pobj->datavalid = 0;
for (i = 0; i < SPLITCOUNT; i++) {
pobj->out_data[i] = NULL;
pobj->out_info[i][0] = 0;
pobj->out_info[i][1] = 0;
}
pobj->in = NULL;
pobj->in_data = NULL;
pobj->name = NULL;
pobj->width = 8;
pobj->parent = NULL;
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
free(pobj->name);
pobj->name = strdup(pParams[i].pvalue);
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) {
pobj->parent = (IHDL4SEModule **)pParams[i].pvalue;
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) {
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
const char* lstr;
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
}
else {
return -1;
}
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][0]);
}
else {
return -1;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][1]);
}
else {
return -1;
}
lstr = nstr;
}
objectRelease(temp);
}
}
}
if (pobj->width <= 0)
return EIID_INVALIDPARAM;
for (i = 0; i < SPLITCOUNT; i++) {
if (pobj->out_info[i][0] <= 0)
return EIID_INVALIDPARAM;
if (pobj->out_info[i][0] + pobj->out_info[i][1] > pobj->width)
return EIID_INVALIDPARAM;
pobj->out_data[i] = bigintegerCreate(pobj->out_info[i][0]);
}
pobj->in_data = bigintegerCreate(pobj->width);
/* 返回生成的对象 */
OBJECT_RETURN_GEN(hdl4se_split4, pobj, pObject, CLSID_HDL4SE_SPLIT4);
return EIID_OK;
}
static void hdl4se_split4Destroy(HOBJECT object)
{
sHDL4SESplit4* pobj;
int i;
pobj = (sHDL4SESplit4*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
for (i = 0; i < SPLITCOUNT; i++) {
objectRelease(pobj->out_data[i]);
}
objectRelease(pobj->in);
objectRelease(pobj->in_data);
memset(pobj, 0, sizeof(sHDL4SESplit4));
free(pobj);
}
static int hdl4se_split4Valid(HOBJECT object)
{
sHDL4SESplit4* pobj;
pobj = (sHDL4SESplit4*)objectThis(object);
return 1;
}
static int hdl4se_split4_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex)
{
sHDL4SESplit4* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sHDL4SESplit4*)objectThis(object);
if (index == 0) {
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->in);
pobj->in = unit;
pobj->in_index = fromindex;
}
else {
return -2;
}
}
else {
return -1;
}
return 0;
}
static int hdl4se_split4_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber** value)
{
int i;
sHDL4SESplit4* pobj;
pobj = (sHDL4SESplit4*)objectThis(object);
if (index < 1 || index > SPLITCOUNT)
return -1;
if (pobj->datavalid == 0) {
objectCall3(pobj->in, GetValue, pobj->in_index, pobj->width, pobj->in_data);
pobj->datavalid = 1;
for (i = 0; i < SPLITCOUNT; i++) {
objectCall3(pobj->out_data[i], AssignSub, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]);
}
pobj->datavalid = 1;
}
objectCall1(value, Assign, pobj->out_data[index-1]);
return 0;
}
static int hdl4se_split4_hdl4se_unit_ClkTick(HOBJECT object)
{
sHDL4SESplit4* pobj;
pobj = (sHDL4SESplit4*)objectThis(object);
return 0;
}
static int hdl4se_split4_hdl4se_unit_Setup(HOBJECT object)
{
sHDL4SESplit4* pobj;
pobj = (sHDL4SESplit4*)objectThis(object);
pobj->datavalid = 0;
return 0;
}
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* hdl4se_unop.c
修改记录:
202105230816: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "bignumber.h"
#include "hdl4secell.h"
/*
#define UNOP_NEG 0
#define UNOP_NOT 1
#define UNOP_AND 2
#define UNOP_OR 3
#define UNOP_XOR 4
*/
#define UNOP_LAST UNOP_XOR
/*
HDL4SE_UNOP
instance parameter: "8, 1, 2",
inputwidth=8, outputwidth=1, unop=UNOP_AND
*/
typedef struct _sHDL4SEUnop {
OBJECT_HEADER
INTERFACE_DECLARE(IHDL4SEUnit)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule** parent;
char* name;
IHDL4SEUnit** wire_in;
int wire_in_index;
int in_width;
IBigNumber** in_data;
IBigNumber** out_data;
int out_width;
int op;
int datavalid;
}sHDL4SEUnop;
OBJECT_FUNCDECLARE(hdl4se_unop, CLSID_HDL4SE_UNOP);
HDL4SEUNIT_FUNCDECLARE(hdl4se_unop, CLSID_HDL4SE_UNOP, sHDL4SEUnop);
DLIST_FUNCIMPL(hdl4se_unop, CLSID_HDL4SE_UNOP, sHDL4SEUnop);
OBJECT_FUNCIMPL(hdl4se_unop, sHDL4SEUnop, CLSID_HDL4SE_UNOP);
QUERYINTERFACE_BEGIN(hdl4se_unop, CLSID_HDL4SE_UNOP)
QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SEUnop)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SEUnop)
QUERYINTERFACE_END
static const char* hdl4se_unopModuleInfo()
{
return "1.0.0-20210523.0816 HDL4SE UNOP cell";
}
static int hdl4se_unopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject)
{
sHDL4SEUnop* pobj;
int i;
pobj = (sHDL4SEUnop*)malloc(sizeof(sHDL4SEUnop));
if (pobj == NULL)
return -1;
*pObject = 0;
HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_UNOP);
INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_unop, hdl4se_unit);
DLIST_VARINIT(pobj, hdl4se_unop);
pobj->wire_in = NULL;
pobj->wire_in_index = 0;
pobj->out_data = NULL;
pobj->in_data = NULL;
pobj->name = NULL;
pobj->in_width = 0;
pobj->out_width = 0;
pobj->datavalid = 0;
pobj->op = -1;
pobj->parent = NULL;
for (i = 0; i < paramcount; i++) {
if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) {
if (pobj->name != NULL)
free(pobj->name);
pobj->name = strdup(pParams[i].pvalue);
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) {
pobj->parent = (IHDL4SEModule **)pParams[i].pvalue;
}
else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) {
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
const char* lstr;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->in_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->op);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
objectRelease(temp);
}
}
}
if (pobj->in_width <= 0)
return EIID_INVALIDPARAM;
if (pobj->out_width <= 0)
return EIID_INVALIDPARAM;
if (pobj->op < UNOP_NEG || pobj->op > UNOP_LAST)
return EIID_INVALIDPARAM;
pobj->out_data = bigintegerCreate(pobj->out_width);
pobj->in_data = bigintegerCreate(pobj->in_width);
/* 返回生成的对象 */
OBJECT_RETURN_GEN(hdl4se_unop, pobj, pObject, CLSID_HDL4SE_UNOP);
return EIID_OK;
}
static void hdl4se_unopDestroy(HOBJECT object)
{
sHDL4SEUnop* pobj;
int i;
pobj = (sHDL4SEUnop*)objectThis(object);
if (pobj->name != NULL)
free(pobj->name);
objectRelease(pobj->wire_in);
objectRelease(pobj->out_data);
objectRelease(pobj->in_data);
memset(pobj, 0, sizeof(sHDL4SEUnop));
free(pobj);
}
static int hdl4se_unopValid(HOBJECT object)
{
sHDL4SEUnop* pobj;
pobj = (sHDL4SEUnop*)objectThis(object);
return 1;
}
static int hdl4se_unop_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex)
{
sHDL4SEUnop* pobj;
IHDL4SEUnit** unit = NULL;
pobj = (sHDL4SEUnop*)objectThis(object);
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) {
objectRelease(pobj->wire_in);
pobj->wire_in = unit;
pobj->wire_in_index = fromindex;
return 0;
}
return -1;
}
static int hdl4se_unop_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber ** value)
{
int i;
sHDL4SEUnop* pobj;
pobj = (sHDL4SEUnop*)objectThis(object);
if (pobj->datavalid == 0) {
switch (pobj->op) {
case UNOP_NEG:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->out_data);
objectCall0(pobj->out_data, Neg);
break;
case UNOP_NOT:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->out_data);
objectCall0(pobj->out_data, Not);
break;
case UNOP_AND:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data);
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall0(pobj->out_data, uAnd) != 0) {
objectCall1(pobj->out_data, AssignInt, 1);
}
break;
case UNOP_OR:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data);
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall0(pobj->out_data, uOr) != 0) {
objectCall1(pobj->out_data, AssignInt, 1);
}
break;
case UNOP_XOR:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data);
objectCall1(pobj->out_data, AssignInt, 0);
if (objectCall0(pobj->out_data, uXor) != 0) {
objectCall1(pobj->out_data, AssignInt, 1);
}
break;
}
pobj->datavalid = 1;
}
objectCall1(value, Assign, pobj->out_data);
return 0;
}
static int hdl4se_unop_hdl4se_unit_ClkTick(HOBJECT object)
{
sHDL4SEUnop* pobj;
pobj = (sHDL4SEUnop*)objectThis(object);
return 0;
}
static int hdl4se_unop_hdl4se_unit_Setup(HOBJECT object)
{
sHDL4SEUnop* pobj;
pobj = (sHDL4SEUnop*)objectThis(object);
pobj->datavalid = 0;
return 0;
}
...@@ -178,7 +178,7 @@ static int hdl4se_wire_hdl4se_unit_GetValue(HOBJECT object, int index, int width ...@@ -178,7 +178,7 @@ static int hdl4se_wire_hdl4se_unit_GetValue(HOBJECT object, int index, int width
int i; int i;
sHDL4SEWire* pobj; sHDL4SEWire* pobj;
pobj = (sHDL4SEWire*)objectThis(object); pobj = (sHDL4SEWire*)objectThis(object);
if (pobj->datavalid) { if (pobj->datavalid == 0) {
for (i = 0; i < pobj->wire_in_count; i++) { for (i = 0; i < pobj->wire_in_count; i++) {
objectCall3(pobj->wire_in[i], GetValue, pobj->wire_in_index[i], pobj->width, pobj->out_data); objectCall3(pobj->wire_in[i], GetValue, pobj->wire_in_index[i], pobj->width, pobj->out_data);
} }
......
...@@ -51,12 +51,16 @@ ...@@ -51,12 +51,16 @@
static int hdl4secell_registed = 0; static int hdl4secell_registed = 0;
extern OFUNCPTR A_u_t_o_registor_hdl4se_reg; extern OFUNCPTR A_u_t_o_registor_hdl4se_reg;
extern OFUNCPTR A_u_t_o_registor_hdl4se_unop;
extern OFUNCPTR A_u_t_o_registor_hdl4se_binop;
extern OFUNCPTR A_u_t_o_registor_hdl4se_wire; extern OFUNCPTR A_u_t_o_registor_hdl4se_wire;
extern OFUNCPTR A_u_t_o_registor_hdl4se_const; extern OFUNCPTR A_u_t_o_registor_hdl4se_const;
extern OFUNCPTR A_u_t_o_registor_hdl4se_module; extern OFUNCPTR A_u_t_o_registor_hdl4se_module;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind2; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind3; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind3;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind4; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_split2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_split4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux2; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux4; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux8; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux8;
...@@ -74,19 +78,26 @@ IHDL4SEUnit** hdl4seCreateUnit(IHDL4SEModule** parent, IIDTYPE clsid, char* inst ...@@ -74,19 +78,26 @@ IHDL4SEUnit** hdl4seCreateUnit(IHDL4SEModule** parent, IIDTYPE clsid, char* inst
param[2].pvalue = parent; param[2].pvalue = parent;
if (hdl4secell_registed == 0) { if (hdl4secell_registed == 0) {
A_u_t_o_registor_hdl4se_reg(); A_u_t_o_registor_hdl4se_reg();
A_u_t_o_registor_hdl4se_unop();
A_u_t_o_registor_hdl4se_binop();
A_u_t_o_registor_hdl4se_wire(); A_u_t_o_registor_hdl4se_wire();
A_u_t_o_registor_hdl4se_const(); A_u_t_o_registor_hdl4se_const();
A_u_t_o_registor_hdl4se_module(); A_u_t_o_registor_hdl4se_module();
A_u_t_o_registor_hdl4se_bind2(); A_u_t_o_registor_hdl4se_bind2();
A_u_t_o_registor_hdl4se_bind3(); A_u_t_o_registor_hdl4se_bind3();
A_u_t_o_registor_hdl4se_bind4(); A_u_t_o_registor_hdl4se_bind4();
A_u_t_o_registor_hdl4se_split2();
A_u_t_o_registor_hdl4se_split4();
A_u_t_o_registor_hdl4se_mux2(); A_u_t_o_registor_hdl4se_mux2();
A_u_t_o_registor_hdl4se_mux4(); A_u_t_o_registor_hdl4se_mux4();
A_u_t_o_registor_hdl4se_mux8(); A_u_t_o_registor_hdl4se_mux8();
A_u_t_o_registor_hdl4se_mux16(); A_u_t_o_registor_hdl4se_mux16();
hdl4secell_registed = 1; hdl4secell_registed = 1;
} }
objectCreateEx(clsid, param, 3, IID_HDL4SEUNIT, (const void**)&result); if (EIID_OK != objectCreateEx(clsid, param, 3, IID_HDL4SEUNIT, (const void**)&result)) {
printf("%s[%s] create failed\n", name, instanceparam);
return NULL;
}
objectCall1(parent, AddUnit, result); objectCall1(parent, AddUnit, result);
return result; return result;
} }
......
...@@ -306,7 +306,7 @@ endmodule ...@@ -306,7 +306,7 @@ endmodule
`define BINOP_MUL 2 `define BINOP_MUL 2
`define BINOP_DIV 3 `define BINOP_DIV 3
`define BINOP_EQ 4 `define BINOP_EQ 4
`define BINOP_NEQ 5 `define BINOP_NE 5
`define BINOP_LT 6 `define BINOP_LT 6
`define BINOP_LE 7 `define BINOP_LE 7
`define BINOP_GE 8 `define BINOP_GE 8
...@@ -332,9 +332,10 @@ module #(INPUTWIDTH0=8, INPUTWIDTH1=8, OUTPUTWIDTH=8, OP=`BINOP_ADD) ...@@ -332,9 +332,10 @@ module #(INPUTWIDTH0=8, INPUTWIDTH1=8, OUTPUTWIDTH=8, OP=`BINOP_ADD)
endmodule endmodule
`define UNOP_NEG 0 `define UNOP_NEG 0
`define UNOP_AND 1 `define UNOP_NOT 1
`define UNOP_OR 2 `define UNOP_AND 2
`define UNOP_XOR 3 `define UNOP_OR 3
`define UNOP_XOR 4
(* (*
HDL4SE="LCOM", HDL4SE="LCOM",
CLSID="E6772805-57BB-4b39-A10D-FDA6A4810E3B", CLSID="E6772805-57BB-4b39-A10D-FDA6A4810E3B",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册