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

202105261711 不正确的版本,仅供存储

上级 1989c92d
......@@ -52,8 +52,11 @@ typedef struct sIBigNumber {
int (*GetWidth)(HOBJECT object);
int (*SetWidth)(HOBJECT object, int width, int signexpand);
int (*GetBits32)(HOBJECT object, int index, unsigned int* pbits);
int (*SetBits32)(HOBJECT object, int index, unsigned int bits);
int (*GetBits32)(HOBJECT object, int ind32, unsigned int* pbits);
int (*SetBits32)(HOBJECT object, int ind32, unsigned int bits);
int (*GetBit)(HOBJECT object, int indbit);
int (*SetBit)(HOBJECT object, int indbit, int bit);
int (*GetInt32)(HOBJECT object, int* pvalue);
int (*GetInt64)(HOBJECT object, long long* pvalue);
......@@ -101,6 +104,7 @@ typedef struct sIBigNumber {
int (*ModU)(HOBJECT object, HOBJECT src0, HOBJECT src1);
int (*Neg)(HOBJECT object, HOBJECT src);
int (*Abs)(HOBJECT object, HOBJECT src);
int (*IsGT)(HOBJECT object, HOBJECT src);
int (*IsGE)(HOBJECT object, HOBJECT src);
......@@ -118,10 +122,11 @@ typedef struct sIBigNumber {
int (*IsZero)(HOBJECT object);
int (*IsNotZero)(HOBJECT object);
int (*IsNeg)(HOBJECT object);
int (*AndL)(HOBJECT object, HOBJECT src);
int (*OrL)(HOBJECT object, HOBJECT src);
int (*NotL)(HOBJECT object, HOBJECT src);
int (*NotL)(HOBJECT object);
int (*And)(HOBJECT object, HOBJECT src0, HOBJECT src1);
int (*Or)(HOBJECT object, HOBJECT src0, HOBJECT src1);
......@@ -148,8 +153,10 @@ typedef struct sIBigNumber {
#define BIGNUMBER_FUNCDECLARE(_obj, _clsid, _localstruct) \
static int _obj##_bn_GetWidth(HOBJECT object); \
static int _obj##_bn_SetWidth(HOBJECT object, int width, int signexpand); \
static int _obj##_bn_GetBits32(HOBJECT object, int index, unsigned int* pbits); \
static int _obj##_bn_SetBits32(HOBJECT object, int index, unsigned int bits); \
static int _obj##_bn_GetBits32(HOBJECT object, int ind32, unsigned int* pbits); \
static int _obj##_bn_SetBits32(HOBJECT object, int ind32, unsigned int bits); \
static int _obj##_bn_GetBit(HOBJECT object, int indbit); \
static int _obj##_bn_SetBit(HOBJECT object, int indbit, int bit); \
static int _obj##_bn_GetInt32(HOBJECT object, int* pvalue); \
static int _obj##_bn_GetInt64(HOBJECT object, long long* pvalue); \
static int _obj##_bn_GetUint32(HOBJECT object, unsigned int* pvalue); \
......@@ -187,6 +194,7 @@ typedef struct sIBigNumber {
static int _obj##_bn_DivU(HOBJECT object, HOBJECT src0, HOBJECT src1); \
static int _obj##_bn_ModU(HOBJECT object, HOBJECT src0, HOBJECT src1); \
static int _obj##_bn_Neg(HOBJECT object, HOBJECT src); \
static int _obj##_bn_Abs(HOBJECT object, HOBJECT src); \
static int _obj##_bn_IsGT(HOBJECT object, HOBJECT src); \
static int _obj##_bn_IsGE(HOBJECT object, HOBJECT src); \
static int _obj##_bn_IsLT(HOBJECT object, HOBJECT src); \
......@@ -201,9 +209,10 @@ typedef struct sIBigNumber {
static int _obj##_bn_IsNEU(HOBJECT object, HOBJECT src); \
static int _obj##_bn_IsZero(HOBJECT object); \
static int _obj##_bn_IsNotZero(HOBJECT object); \
static int _obj##_bn_IsNeg(HOBJECT object); \
static int _obj##_bn_AndL(HOBJECT object, HOBJECT src); \
static int _obj##_bn_OrL(HOBJECT object, HOBJECT src); \
static int _obj##_bn_NotL(HOBJECT object, HOBJECT src); \
static int _obj##_bn_NotL(HOBJECT object); \
static int _obj##_bn_And(HOBJECT object, HOBJECT src0, HOBJECT src1); \
static int _obj##_bn_Or(HOBJECT object, HOBJECT src0, HOBJECT src1); \
static int _obj##_bn_Xor(HOBJECT object, HOBJECT src0, HOBJECT src1); \
......@@ -224,7 +233,9 @@ static const IBigNumber _obj##_bn_interface = { \
_obj##_bn_SetWidth, \
_obj##_bn_GetBits32, \
_obj##_bn_SetBits32, \
_obj##_bn_GetInt32, \
_obj##_bn_GetBit, \
_obj##_bn_SetBit, \
_obj##_bn_GetInt32, \
_obj##_bn_GetInt64, \
_obj##_bn_GetUint32, \
_obj##_bn_GetUint64, \
......@@ -248,6 +259,7 @@ static const IBigNumber _obj##_bn_interface = { \
_obj##_bn_AddUint32, \
_obj##_bn_SubUint32, \
_obj##_bn_MulUint32, \
_obj##_bn_DivUint32, \
_obj##_bn_ModUint32, \
_obj##_bn_Add, \
_obj##_bn_Sub, \
......@@ -260,6 +272,7 @@ static const IBigNumber _obj##_bn_interface = { \
_obj##_bn_DivU, \
_obj##_bn_ModU, \
_obj##_bn_Neg, \
_obj##_bn_Abs, \
_obj##_bn_IsGT, \
_obj##_bn_IsGE, \
_obj##_bn_IsLT, \
......@@ -274,6 +287,7 @@ static const IBigNumber _obj##_bn_interface = { \
_obj##_bn_IsNEU, \
_obj##_bn_IsZero, \
_obj##_bn_IsNotZero, \
_obj##_bn_IsNeg, \
_obj##_bn_AndL, \
_obj##_bn_OrL, \
_obj##_bn_NotL, \
......
......@@ -32,6 +32,7 @@
/*
* bignumber.c
202105201110: rxh, initial version
202105260952:修改了接口,为verilog语言编译做准备,主要是区分了带符号和不带符号计算
*/
#include "stdlib.h"
......@@ -42,6 +43,8 @@
#include "bignumber.h"
#undef IMPLEMENT_GUID
#define NOTIMPL printf("bignumber.c %d, %s is not implemented now\n", __LINE__, __FUNCTION__)
#define CELL_WIDTH 32
#define CELL_MASK 0xffffffff
......@@ -55,7 +58,7 @@ typedef struct _sBigInteger {
unsigned int* buf;
}sBigInteger;
OBJECT_FUNCDECLARE(bigint, CLSID_BIGINTEGER);
BIGNUMBER_FUNCDECLARE(bigint, CLSID_BIGINTEGER, sBigInteger);
......@@ -87,6 +90,9 @@ static int bigintCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObje
pobj->width = pParams[i].i32value;
}
if (pobj->width <= 0)
return -1;
pobj->buflen = (pobj->width + CELL_WIDTH - 1) / CELL_WIDTH;
if (pobj->buflen < 2)
pobj->buflen = 2;
......@@ -140,7 +146,6 @@ static int bigintValid(HOBJECT object)
static int bigint_bn_GetWidth(HOBJECT object)
{
int i;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return pobj->width;
......@@ -148,14 +153,11 @@ static int bigint_bn_GetWidth(HOBJECT object)
static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand)
{
int i, bc,blen, sign;
int i, bc, blen, sign;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
if (width <= 0) {
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = 0;
pobj->width = 0;
return 0;
return -1;
}
sign = 0;
if (signexpand) {
......@@ -164,6 +166,8 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand)
}
blen = (width + CELL_WIDTH - 1) / CELL_WIDTH;
if (blen < 2)
blen = 2;
if (pobj->buflen < blen) {
unsigned int * buf;
buf = (unsigned int *)malloc(blen * (CELL_WIDTH / 8));
......@@ -177,34 +181,63 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand)
}
blen = pobj->width / CELL_WIDTH;
bc = pobj->width & (CELL_WIDTH-1);
if (sign)
pobj->buf[blen] |= CELL_MASK << bc;
else
pobj->buf[blen] &= CELL_MASK >> (CELL_WIDTH - bc);
for (i = blen+1; i < pobj->buflen; i++) {
pobj->buf[i] = sign ? CELL_MASK : 0;
}
if (sign)
pobj->buf[blen] |= CELL_MASK << (pobj->width & (CELL_WIDTH - 1));
else
pobj->buf[blen] &= CELL_MASK >> (CELL_WIDTH - (pobj->width & (CELL_WIDTH-1)));
pobj->width = width;
return 0;
}
static int bigint_bn_GetBits32(HOBJECT object, int index, unsigned int* pbits)
static int bigint_bn_GetBits32(HOBJECT object, int ind32, unsigned int* pbits)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
if (ind32 < 0 || ind32 >= pobj->buflen) {
*pbits = 0;
return -1;
}
*pbits = pobj->buf[ind32];
return 0;
}
static int bigint_bn_SetBits32(HOBJECT object, int ind32, unsigned int bits)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
if (index < 0 || index >= pobj->buflen)
if (ind32 < 0 || ind32 >= pobj->buflen)
return -1;
*pbits = pobj->buf[index];
pobj->buf[ind32] = bits;
return 0;
}
static int bigint_bn_SetBits32(HOBJECT object, int index, unsigned int bits)
static int bigint_bn_GetBit(HOBJECT object, int indbit)
{
sBigInteger* pobj;
int ind32;
pobj = (sBigInteger*)objectThis(object);
if (indbit < 0 || indbit >= pobj->width)
return -1;
ind32 = indbit / 32;
return pobj->buf[ind32] & (1 << (indbit & 31));
}
static int bigint_bn_SetBit(HOBJECT object, int indbit, int bit)
{
sBigInteger* pobj;
int ind32;
pobj = (sBigInteger*)objectThis(object);
if (index < 0 || index >= pobj->buflen)
if (indbit < 0 || indbit >= pobj->width)
return -1;
pobj->buf[index] = bits;
ind32 = indbit / 32;
if (bit != 0)
pobj->buf[ind32] |= (1 << (indbit & 31));
else
pobj->buf[ind32] &= ~(1 << (indbit & 31));
return 0;
}
......@@ -235,7 +268,6 @@ static int bigint_bn_GetInt64(HOBJECT object, long long* pvalue)
((unsigned int *)pvalue)[1] = pobj->buf[1];
if (width < 64)
bigint_bn_SetWidth(object, width, 0);
return 0;
}
......@@ -302,50 +334,38 @@ static int bigint_bn_GetStr(HOBJECT object, int base, char* str, int buflen)
static int bigint_bn_AssignInt32(HOBJECT object, int value)
{
sBigInteger* pobj;
int i, width;
pobj = (sBigInteger*)objectThis(object);
width = pobj->width;
bigint_bn_SetWidth(object, 32, 0);
pobj->buf[0] = *(unsigned int*)&value;
bigint_bn_SetWidth(object, width, 1);
bigint_bn_SetWidth(object, pobj->width, 1);
return 0;
}
static int bigint_bn_AssignInt64(HOBJECT object, long long value)
{
sBigInteger* pobj;
int i, width;
pobj = (sBigInteger*)objectThis(object);
width = pobj->width;
bigint_bn_SetWidth(object, 64, 0);
pobj->buf[0] = (*(unsigned long long*)(&value)) & CELL_MASK;
pobj->buf[1] = ((*(unsigned long long*)(&value)) >> CELL_WIDTH) & CELL_MASK;
bigint_bn_SetWidth(object, width, 1);
bigint_bn_SetWidth(object, pobj->width, 1);
return 0;
}
static int bigint_bn_AssignUint32(HOBJECT object, unsigned int value)
{
sBigInteger* pobj;
int i, width;
pobj = (sBigInteger*)objectThis(object);
width = pobj->width;
bigint_bn_SetWidth(object, 32, 0);
pobj->buf[0] = *(unsigned int*)&value;
bigint_bn_SetWidth(object, width, 0);
bigint_bn_SetWidth(object, pobj->width, 0);
return 0;
}
static int bigint_bn_AssignUint64(HOBJECT object, unsigned long long value)
{
sBigInteger* pobj;
int i, width;
pobj = (sBigInteger*)objectThis(object);
width = pobj->width;
bigint_bn_SetWidth(object, 64, 0);
pobj->buf[0] = (*(unsigned long long*)(&value)) & CELL_MASK;
pobj->buf[1] = ((*(unsigned long long*)(&value)) >> CELL_WIDTH) & CELL_MASK;
bigint_bn_SetWidth(object, width, 0);
bigint_bn_SetWidth(object, pobj->width, 0);
return 0;
}
......@@ -375,15 +395,15 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
state = TOKEN_BASE;
}
else if (ch >= '0' && ch <= '9') {
bigint_bn_AssignInt(object, ch - '0');
bigint_bn_AssignInt32(object, ch - '0');
numvalid = 1;
state = TOKEN_NUM;
}
} break;
case TOKEN_NUM: {
if (ch >= '0' && ch <= '9') {
bigint_bn_MulInt(object, 10);
bigint_bn_AddInt(object, ch - '0');
bigint_bn_MulInt32(object, object, 10);
bigint_bn_AddInt32(object, object, ch - '0');
}
else if (ch == '\'') {
state = TOKEN_BASE;
......@@ -395,19 +415,19 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_BASE: {
if (ch == 'b' || ch == 'B') {
bigint_bn_AssignInt(object, 0);
bigint_bn_AssignInt32(object, 0);
state = TOKEN_BIN;
}
else if (ch == 'h' || ch == 'H') {
bigint_bn_AssignInt(object, 0);
bigint_bn_AssignInt32(object, 0);
state = TOKEN_HEX;
}
else if (ch == 'o' || ch == 'O') {
bigint_bn_AssignInt(object, 0);
bigint_bn_AssignInt32(object, 0);
state = TOKEN_OCT;
}
else if (ch == 'd' || ch == 'D') {
bigint_bn_AssignInt(object, 0);
bigint_bn_AssignInt32(object, 0);
state = TOKEN_DEC;
}
else if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') {
......@@ -419,8 +439,8 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_BIN: {
if (ch == '0' || ch == '1') {
bigint_bn_MulInt(object, 2);
bigint_bn_AddInt(object, ch - '0');
bigint_bn_MulInt32(object, object, 2);
bigint_bn_AddInt32(object, object, ch - '0');
numvalid = 1;
}
else if (ch == '_') {
......@@ -431,8 +451,8 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_OCT: {
if (ch >= '0' && ch <= '7') {
bigint_bn_MulInt(object, 8);
bigint_bn_AddInt(object, ch - '0');
bigint_bn_MulInt32(object, object, 8);
bigint_bn_AddInt32(object, object, ch - '0');
numvalid = 1;
}
else if (ch == '_') {
......@@ -443,8 +463,8 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_DEC: {
if (ch >= '0' && ch <= '9') {
bigint_bn_MulInt(object, 10);
bigint_bn_AddInt(object, ch - '0');
bigint_bn_MulInt32(object, object, 10);
bigint_bn_AddInt32(object, object, ch - '0');
numvalid = 1;
}
else {
......@@ -454,13 +474,13 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
case TOKEN_HEX: {
if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
numvalid = 1;
bigint_bn_MulInt(object, 16);
bigint_bn_MulInt32(object, object, 16);
if (ch > '0' && ch <= '9')
bigint_bn_AddInt(object, ch - '0');
bigint_bn_AddInt32(object, object, ch - '0');
else if (ch >= 'a' && ch <= 'f')
bigint_bn_AddInt(object, ch - 'a' + 10);
bigint_bn_AddInt32(object, object, ch - 'a' + 10);
else if (ch >= 'A' && ch <= 'F')
bigint_bn_AddInt(object, ch - 'A' + 10);
bigint_bn_AddInt32(object, object, ch - 'A' + 10);
}
else if (ch == '_') {
}
......@@ -481,120 +501,104 @@ lastnum:
return 0;
}
static int _obj##_bn_Clone(HOBJECT object, HOBJECT src); \
static int _obj##_bn_CloneSubBits(HOBJECT object, HOBJECT src, int from, int width); \
static int _obj##_bn_Assign(HOBJECT object, HOBJECT src); \
static int _obj##_bn_AssignSubBits(HOBJECT object, HOBJECT src, int from, int width); \
static int _obj##_bn_AssignU(HOBJECT object, HOBJECT src); \
static int _obj##_bn_AssignSubBitsU(HOBJECT object, HOBJECT src, int from, int width); \
static int bigint_bn_Clone(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
IBigNumber** numsrc;
int i;
int width;
int buflen;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&numsrc))
return -1;
width = objectCall0(numsrc, GetWidth);
if (width <= 0) {
objectRelease(numsrc);
return -1;
}
psrc = (sBigInteger*)objectThis(src);
if (pobj->buflen < psrc->buflen) {
buflen = (width + CELL_WIDTH - 1) / CELL_WIDTH;
if (buflen < 2)
buflen = 2;
if (pobj->buflen < buflen) {
unsigned int* buf;
buf = (unsigned int*)malloc(psrc->buflen * (CELL_WIDTH / 8));
if (buf == NULL)
buf = (unsigned int*)malloc(buflen * (CELL_WIDTH / 8));
if (buf == NULL) {
objectRelease(numsrc);
return -2;
}
free(pobj->buf);
pobj->buf = buf;
}
pobj->buflen = psrc->buflen;
pobj->width = psrc->width;
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = psrc->buf[i];
pobj->buflen = buflen;
pobj->width = width;
for (i = 0; i < pobj->buflen; i++) {
objectCall2(numsrc, GetBits32, i, &pobj->buf[i]);
}
objectRelease(numsrc);
return 0;
}
static int bigint_bn_CloneSubBits(HOBJECT object, HOBJECT src, int from, int width)
{
bigint_bn_Assign(object, src);
bigint_bn_SAR(object, from);
bigint_bn_SetWidth(object, width, 1);
if (from < 0 || width <= 0)
return -1;
bigint_bn_SetWidth(object, width, 0);
bigint_bn_SHR(object, src, from);
bigint_bn_SetWidth(object, width, 0);
return 0;
}
static int bigint_bn_Assign(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
if (pobj->buflen < psrc->buflen) {
unsigned int* buf;
buf = (unsigned int*)malloc(psrc->buflen * (CELL_WIDTH / 8));
if (buf == NULL)
return -2;
free(pobj->buf);
pobj->buf = buf;
}
pobj->buflen = psrc->buflen;
pobj->width = psrc->width;
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = psrc->buf[i];
int width;
width = bigint_bn_GetWidth(object);
bigint_bn_Clone(object, src);
bigint_bn_SetWidth(object, width, 1);
return 0;
}
static int bigint_bn_AssignSubBits(HOBJECT object, HOBJECT src, int from, int width)
{
bigint_bn_Assign(object, src);
bigint_bn_SAR(object, from);
bigint_bn_SetWidth(object, width, 1);
int objwidth;
objwidth = bigint_bn_GetWidth(object);
bigint_bn_CloneSubBits(object, src, from, width);
bigint_bn_SetWidth(object, objwidth, 1);
return 0;
}
static int bigint_bn_AssignU(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
if (pobj->buflen < psrc->buflen) {
unsigned int* buf;
buf = (unsigned int*)malloc(psrc->buflen * (CELL_WIDTH / 8));
if (buf == NULL)
return -2;
free(pobj->buf);
pobj->buf = buf;
}
pobj->buflen = psrc->buflen;
pobj->width = psrc->width;
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = psrc->buf[i];
int width;
width = bigint_bn_GetWidth(object);
bigint_bn_Clone(object, src);
bigint_bn_SetWidth(object, width, 0);
return 0;
}
static int bigint_bn_AssignSubBitsU(HOBJECT object, HOBJECT src, int from, int width)
{
bigint_bn_Assign(object, src);
bigint_bn_SAR(object, from);
bigint_bn_SetWidth(object, width, 1);
int objwidth;
objwidth = bigint_bn_GetWidth(object);
bigint_bn_CloneSubBits(object, src, from, width);
bigint_bn_SetWidth(object, objwidth, 0);
return 0;
}
static int bigint_bn_AddInt32(HOBJECT object, int value)
static int bigint_bn_AddInt32(HOBJECT object, HOBJECT src, int value)
{
unsigned long long temp;
int ind;
unsigned int v;
unsigned int v, vs, widthsrc;
sBigInteger* pobj;
IBigNumber** numsrc;
pobj = (sBigInteger*)objectThis(object);
temp = pobj->buf[0];
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&numsrc))
return -1;
widthsrc = objectCall0(numsrc, GetWidth);
objectCall2(numsrc, SetWidth, widthsrc, 1);
bigint_bn_SetWidth(object, pobj->width, 1);
objectCall2(numsrc, GetBits32, 0, &vs);
temp = vs;
temp += *(unsigned int*)&value;
pobj->buf[0] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
......@@ -606,6 +610,8 @@ static int bigint_bn_AddInt32(HOBJECT object, int value)
if (ind >= pobj->buflen)
break;
temp += v;
if (0 != objectCall2(numsrc, GetBits32, ind, &vs))
vs =
temp += pobj->buf[ind];
pobj->buf[ind] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
......@@ -614,54 +620,55 @@ static int bigint_bn_AddInt32(HOBJECT object, int value)
return 0;
}
static int bigint_bn_SubInt32(HOBJECT object, int value)
static int bigint_bn_SubInt32(HOBJECT object, HOBJECT src, int value)
{
return bigint_bn_AddInt(object, -value);
return bigint_bn_AddInt32(object, src, -value);
}
static int bigint_bn_MulInt32(HOBJECT object, int value)
static int bigint_bn_MulInt32(HOBJECT object, HOBJECT src, int value)
{
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignInt(temp, value);
bigint_bn_Mul(object, temp);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Mul(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_DivInt32(HOBJECT object, int value)
static int bigint_bn_DivInt32(HOBJECT object, HOBJECT src, int value)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Div(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_ModInt32(HOBJECT object, int value)
static int bigint_bn_ModInt32(HOBJECT object, HOBJECT src, int value)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignInt32(temp, value);
bigint_bn_Mod(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_AddUint32(HOBJECT object, unsigned int value)
static int bigint_bn_AddUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
unsigned long long temp;
int ind;
unsigned int v;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
temp = pobj->buf[0];
temp += *(unsigned int*)&value;
temp += value;
pobj->buf[0] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
ind = 1;
v = 0;
if (value < 0)
v = CELL_MASK;
while (temp != 0) {
if (ind >= pobj->buflen)
break;
temp += v;
temp += pobj->buf[ind];
pobj->buf[ind] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
......@@ -670,32 +677,67 @@ static int bigint_bn_AddUint32(HOBJECT object, unsigned int value)
return 0;
}
static int bigint_bn_SubUint32(HOBJECT object, unsigned int value)
static int bigint_bn_SubUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
return bigint_bn_AddInt(object, -value);
unsigned long long temp;
int ind;
unsigned int v;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
temp = pobj->buf[0];
v = 0;
/*如果不够,就向前借位*/
if (temp < value) {
v = CELL_MASK;
temp += 1ll << CELL_WIDTH;
}
temp -= value;
pobj->buf[0] = temp & CELL_MASK;
temp = v;
ind = 1;
while (temp != 0) {
if (ind >= pobj->buflen)
break;
v = 0;
if (temp < pobj->buf[ind]) {
v = CELL_MASK;
temp += 1ll << CELL_WIDTH;
}
temp -= pobj->buf[ind];
pobj->buf[ind] = temp & CELL_MASK;
temp = v;
ind++;
}
return 0;
}
static int bigint_bn_MulUint32(HOBJECT object, unsigned int value)
static int bigint_bn_MulUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignInt(temp, value);
bigint_bn_Mul(object, temp);
bigint_bn_AssignUint32(temp, value);
bigint_bn_MulU(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_DivUint32(HOBJECT object, unsigned int value)
static int bigint_bn_DivUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignUint32(temp, value);
bigint_bn_DivU(object, src, temp);
objectRelease(temp);
return 0;
}
static int bigint_bn_ModUint32(HOBJECT object, unsigned int value)
static int bigint_bn_ModUint32(HOBJECT object, HOBJECT src, unsigned int value)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
sBigInteger** temp;
temp = bigintegerCreate(32);
bigint_bn_AssignUint32(temp, value);
bigint_bn_ModU(object, src, temp);
objectRelease(temp);
return 0;
}
......@@ -703,88 +745,121 @@ static int bigint_bn_Add(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
unsigned long long temp;
sBigInteger* pobj;
sBigInteger* psrc;
int widthobj, widthsrc, wobj;
IBigNumber** psrc0;
IBigNumber** psrc1;
int widthobj, widthsrc0, widthsrc1;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
return -1;
}
if (EIID_OK != objectQueryInterface(src1, IID_BIGNUMBER, (void**)&psrc1)) {
objectRelease(psrc0);
return -1;
}
psrc = (sBigInteger*)objectThis(src);
widthobj = pobj->width;
widthsrc = psrc->width;
wobj = pobj->buflen * CELL_WIDTH;
bigint_bn_SetWidth(object, wobj, 1);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, wobj, 1);
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthobj, 1);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthobj, 1);
}
temp = 0;
for (i = 0; i < pobj->buflen; i++) {
temp += pobj->buf[i];
temp += psrc->buf[i];
unsigned int src0value, src1value;
objectCall2(psrc0, GetBits32, i, &src0value);
objectCall2(psrc1, GetBits32, i, &src1value);
temp += src0value;
temp += src1value;
pobj->buf[i] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
}
bigint_bn_SetWidth(object, widthobj, 0);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, widthsrc, 0);
bigint_bn_SetWidth(object, widthobj, 1);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthsrc0, 1);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthsrc1, 1);
}
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
static int bigint_bn_Sub(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger** temp;
temp = bigintegerCreate(64);
bigint_bn_Assign(temp, src);
bigint_bn_Neg(temp);
bigint_bn_Add(object, temp);
objectRelease(temp);
return 0;
if (EIID_OK != bigint_bn_Neg(object, src1))
return -1;
return bigint_bn_Add(object, src0, object);
}
static int bigint_bn_Mul(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
sBigInteger* psrc;
IBigNumber** psrc0;
IBigNumber** psrc1;
unsigned int* buf;
int widthobj, widthsrc0, widthsrc1;
int i, j;
int widthobj, widthsrc, wobj;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
buf = (unsigned int*)malloc(pobj->buflen * CELL_WIDTH/8);
if (buf == NULL)
return -2;
if (EIID_OK != objectQueryInterface(src1, IID_BIGNUMBER, (void**)&psrc1)) {
objectRelease(psrc0);
return -1;
}
widthobj = pobj->width;
widthsrc = psrc->width;
wobj = pobj->buflen * CELL_WIDTH;
bigint_bn_SetWidth(object, wobj, 1);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, wobj, 1);
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthobj, 1);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthobj, 1);
}
pobj->buflen = (pobj->width + CELL_WIDTH - 1) / CELL_WIDTH;
if (pobj->buflen < 2)
pobj->buflen = 2;
buf = (unsigned int*)malloc(pobj->buflen * CELL_WIDTH / 8);
if (buf == NULL) {
objectRelease(psrc0);
objectRelease(psrc1);
return -1;
}
for (i = 0; i < pobj->buflen; i++)
buf[i] = 0;
for (i = 0; i < pobj->buflen; i++) {
unsigned long long addin;
unsigned long long m0, m1;
unsigned int m0s, m1s;
addin = 0;
for (j = 0; j < psrc->buflen; j++) {
unsigned long long m0, m1;
objectCall2(psrc0, GetBits32, i, &m0s);
m0 = m0s;
for (j = 0; j < pobj->buflen; j++) {
if (i + j >= pobj->buflen)
break;
m0 = pobj->buf[i];
m1 = psrc->buf[j];
m0 = m0 * m1 + addin + buf[i+j];
buf[i + j] = m0 & CELL_MASK;
addin = m0 >> CELL_WIDTH;
objectCall2(psrc1, GetBits32, j, &m1s);
m1 = m1s;
m1 = m0 * m1 + addin + buf[i+j];
buf[i + j] = m1 & CELL_MASK;
addin = m1 >> CELL_WIDTH;
}
}
free(pobj->buf);
pobj->buf = buf;
bigint_bn_SetWidth(object, widthobj, 0);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, widthsrc, 0);
bigint_bn_SetWidth(object, widthobj, 1);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthsrc0, 1);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthsrc1, 1);
}
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
......@@ -792,6 +867,7 @@ static int bigint_bn_Div(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
NOTIMPL;
return 0;
}
......@@ -799,6 +875,7 @@ static int bigint_bn_Mod(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
NOTIMPL;
return 0;
}
......@@ -806,88 +883,121 @@ static int bigint_bn_AddU(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
unsigned long long temp;
sBigInteger* pobj;
sBigInteger* psrc;
int widthobj, widthsrc, wobj;
IBigNumber** psrc0;
IBigNumber** psrc1;
int widthobj, widthsrc0, widthsrc1;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
return -1;
}
if (EIID_OK != objectQueryInterface(src1, IID_BIGNUMBER, (void**)&psrc1)) {
objectRelease(psrc0);
return -1;
}
psrc = (sBigInteger*)objectThis(src);
widthobj = pobj->width;
widthsrc = psrc->width;
wobj = pobj->buflen * CELL_WIDTH;
bigint_bn_SetWidth(object, wobj, 1);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, wobj, 1);
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthobj, 0);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthobj, 0);
}
temp = 0;
for (i = 0; i < pobj->buflen; i++) {
temp += pobj->buf[i];
temp += psrc->buf[i];
unsigned int src0value, src1value;
objectCall2(psrc0, GetBits32, i, &src0value);
objectCall2(psrc1, GetBits32, i, &src1value);
temp += src0value;
temp += src1value;
pobj->buf[i] = temp & CELL_MASK;
temp >>= CELL_WIDTH;
}
bigint_bn_SetWidth(object, widthobj, 0);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, widthsrc, 0);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthsrc0, 0);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthsrc1, 0);
}
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
static int bigint_bn_SubU(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger** temp;
temp = bigintegerCreate(64);
bigint_bn_Assign(temp, src);
bigint_bn_Neg(temp);
bigint_bn_Add(object, temp);
objectRelease(temp);
return 0;
if (EIID_OK != bigint_bn_Neg(object, src1))
return -1;
return bigint_bn_AddU(object, src0, object);
}
static int bigint_bn_MulU(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
sBigInteger* psrc;
IBigNumber** psrc0;
IBigNumber** psrc1;
unsigned int* buf;
int widthobj, widthsrc0, widthsrc1;
int i, j;
int widthobj, widthsrc, wobj;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
if (EIID_OK != objectQueryInterface(src0, IID_BIGNUMBER, (void**)&psrc0)) {
return -1;
}
if (EIID_OK != objectQueryInterface(src1, IID_BIGNUMBER, (void**)&psrc1)) {
objectRelease(psrc0);
return -1;
}
psrc = (sBigInteger*)objectThis(src);
buf = (unsigned int*)malloc(pobj->buflen * CELL_WIDTH / 8);
if (buf == NULL)
return -2;
widthobj = pobj->width;
widthsrc = psrc->width;
wobj = pobj->buflen * CELL_WIDTH;
bigint_bn_SetWidth(object, wobj, 1);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, wobj, 1);
widthsrc0 = objectCall0(psrc0, GetWidth);
widthsrc1 = objectCall0(psrc1, GetWidth);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthobj, 0);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthobj, 0);
}
pobj->buflen = (pobj->width + CELL_WIDTH - 1) / CELL_WIDTH;
if (pobj->buflen < 2)
pobj->buflen = 2;
buf = (unsigned int*)malloc(pobj->buflen * CELL_WIDTH / 8);
if (buf == NULL) {
objectRelease(psrc0);
objectRelease(psrc1);
return -1;
}
for (i = 0; i < pobj->buflen; i++)
buf[i] = 0;
for (i = 0; i < pobj->buflen; i++) {
unsigned long long addin;
unsigned long long m0, m1;
unsigned int m0s, m1s;
addin = 0;
for (j = 0; j < psrc->buflen; j++) {
unsigned long long m0, m1;
objectCall2(psrc0, GetBits32, i, &m0s);
m0 = m0s;
for (j = 0; j < pobj->buflen; j++) {
if (i + j >= pobj->buflen)
break;
m0 = pobj->buf[i];
m1 = psrc->buf[j];
m0 = m0 * m1 + addin + buf[i + j];
buf[i + j] = m0 & CELL_MASK;
addin = m0 >> CELL_WIDTH;
objectCall2(psrc1, GetBits32, j, &m1s);
m1 = m1s;
m1 = m0 * m1 + addin + buf[i + j];
buf[i + j] = m1 & CELL_MASK;
addin = m1 >> CELL_WIDTH;
}
}
free(pobj->buf);
pobj->buf = buf;
bigint_bn_SetWidth(object, widthobj, 0);
if (widthsrc < wobj)
bigint_bn_SetWidth(src, widthsrc, 0);
bigint_bn_SetWidth(object, widthobj, 1);
if (widthsrc0 < widthobj) {
objectCall2(psrc0, SetWidth, widthsrc0, 1);
}
if (widthsrc1 < widthobj) {
objectCall2(psrc1, SetWidth, widthsrc1, 1);
}
objectRelease(psrc0);
objectRelease(psrc1);
return 0;
}
......@@ -895,6 +1005,7 @@ static int bigint_bn_DivU(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
NOTIMPL;
return 0;
}
......@@ -902,245 +1013,199 @@ static int bigint_bn_ModU(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
NOTIMPL;
return 0;
}
static int bigint_bn_Neg(HOBJECT object)
static int bigint_bn_Neg(HOBJECT object, HOBJECT src)
{
/* 反码加一 */
bigint_bn_Not(object);
bigint_bn_AddInt(object, 1);
bigint_bn_Not(object, src);
bigint_bn_AddInt32(object, object, 1);
return 0;
}
static int bigint_bn_SHL(HOBJECT object, int bits)
{
sBigInteger* pobj;
int ifrom, ito, i;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits < 0)
return bigint_bn_SHR(object, -bits);
ito = bits / CELL_WIDTH;
bits -= ito * CELL_WIDTH;
ifrom = 0;
for (i = pobj->buflen-1; i>=0; i--) {
current = 0;
if (i >= ito) {
current = pobj->buf[i - ito];
current <<= CELL_WIDTH;
}
if (i >= ito+1) {
next = pobj->buf[i - ito -1];
current |= next;
}
current >>= CELL_WIDTH - bits;
pobj->buf[i] = (unsigned int)(current & CELL_MASK);
}
static int bigint_bn_Abs(HOBJECT object, HOBJECT src)
{
return 0;
}
static int bigint_bn_IsGT(HOBJECT object, HOBJECT src)
{
return 0;
}
static int bigint_bn_IsGE(HOBJECT object, HOBJECT src)
{
return 0;
}
static int bigint_bn_SHR(HOBJECT object, int bits)
static int bigint_bn_IsLT(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
int bc;
int ifrom, ito, i, zerolen;
unsigned long long current, next;
sBigInteger* psrc;
int i;
int bc, sign, signsrc;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return 0;
if (bits < 0)
return bigint_bn_SHL(object, -bits);
ito = 0;
ifrom = bits / CELL_WIDTH;
if (ifrom >= pobj->buflen) {
memset(pobj->buf, 0, pobj->buflen * (CELL_WIDTH/8));
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) {
return 0;
}
bits -= ifrom * CELL_WIDTH;
if (ifrom+1 < pobj->buflen) {
current = pobj->buf[ifrom+1];
current <<= CELL_WIDTH;
}
else {
current = 0;
}
current |= pobj->buf[ifrom];
current >>= bits;
for (i = ifrom + 1; i < pobj->buflen-1; i++) {
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
current >>= CELL_WIDTH;
next = pobj->buf[i + 1];
next <<= CELL_WIDTH-bits;
current |= next;
else if (sign != 0 && signsrc == 0) {
return 1;
}
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
while (ito < pobj->buflen)
pobj->buf[ito++] = 0;
return 0;
}
static int bigint_bn_SAL(HOBJECT object, int bits)
{
return bigint_bn_SHL(object, bits);
}
static int bigint_bn_SAR(HOBJECT object, int bits)
{
sBigInteger* pobj;
int bc, sign;
int ifrom, ito, i, zerolen;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits < 0)
return bigint_bn_SHL(object, -bits);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
ito = 0;
ifrom = bits / CELL_WIDTH;
if (ifrom >= pobj->buflen) {
for (i = 0;i<pobj->buflen;i++)
pobj->buf[i] = sign ? CELL_MASK : 0;
return 0;
}
bits -= ifrom * CELL_WIDTH;
if (ifrom + 1 < pobj->buflen) {
current = pobj->buf[ifrom + 1];
current <<= CELL_WIDTH;
bc = pobj->buflen;
if (bc < psrc->buflen)
bc = psrc->buflen;
for (i = bc - 1; i >= pobj->buflen; i--) {
if (sign != 0) {
if (psrc->buf[i] != 0xffffffff)
return 0;
}
else {
if (psrc->buf[0] != 0)
return 1;
}
}
else {
current = 0;
for (; i >= psrc->buflen; i--) {
if (sign != 0) {
if (pobj->buf[i] != 0xffffffff)
return 1;
}
else {
if (pobj->buf[0] != 0)
return 0;
}
}
current |= pobj->buf[ifrom];
current >>= bits;
for (i = ifrom + 1; i < pobj->buflen - 1; i++) {
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
current >>= CELL_WIDTH;
next = pobj->buf[i + 1];
next <<= CELL_WIDTH - bits;
current |= next;
for (; i >= 0; i--) {
if (sign != 0) {
if (pobj->buf[i] > psrc->buf[i])
return 1;
else if (pobj->buf[i] < psrc->buf[i])
return 0;
}
else {
if (pobj->buf[i] < psrc->buf[i])
return 1;
if (pobj->buf[i] > psrc->buf[i])
return 0;
}
}
next = sign ? CELL_MASK : 0;
next <<= CELL_WIDTH - bits;
current |= next;
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
while (ito < pobj->buflen)
pobj->buf[ito++] = sign ? CELL_MASK : 0;
return 0;
}
static int bigint_bn_Not(HOBJECT object)
{
int i;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = ~pobj->buf[i];
return 0;
}
static int bigint_bn_uAnd(HOBJECT object)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uOr(HOBJECT object)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uXor(HOBJECT object)
static int bigint_bn_IsLE(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_And(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
int bc, sign, signsrc;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
return 0;
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] &= psrc->buf[i];
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) {
return 0;
}
for (; i < pobj->buflen; i++) {
pobj->buf[i] = 0;
else if (sign != 0 && signsrc == 0) {
return 1;
}
return 0;
}
static int bigint_bn_Or(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
bc = pobj->buflen;
if (bc < psrc->buflen)
bc = psrc->buflen;
for (i = bc - 1; i >= pobj->buflen; i--) {
if (sign != 0) {
if (psrc->buf[i] != 0xffffffff)
return 0;
}
else {
if (psrc->buf[0] != 0)
return 1;
}
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] |= psrc->buf[i];
for (; i >= psrc->buflen; i--) {
if (sign != 0) {
if (pobj->buf[i] != 0xffffffff)
return 1;
}
else {
if (pobj->buf[0] != 0)
return 0;
}
}
return 0;
for (; i >= 0; i--) {
if (sign != 0) {
if (pobj->buf[i] > psrc->buf[i])
return 1;
else if (pobj->buf[i] < psrc->buf[i])
return 0;
}
else {
if (pobj->buf[i] < psrc->buf[i])
return 1;
if (pobj->buf[i] > psrc->buf[i])
return 0;
}
}
return 1;
}
static int bigint_bn_Xor(HOBJECT object, HOBJECT src)
static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
int bc, sign, signsrc;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
return 0;
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign != signsrc) {
return 0;
}
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] ^= psrc->buf[i];
if (pobj->buf[i] != psrc->buf[i])
return 0;
}
for (; i < pobj->buflen; i++) {
pobj->buf[i] ^= 0;
if (sign == 0 && pobj->buf[i] != 0)
return 0;
else if (sign != 0 && pobj->buf[i] != CELL_MASK)
return 0;
}
return 0;
}
static int bigint_bn_IsZero(HOBJECT object)
{
sBigInteger* pobj;
int i;
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
if (pobj->buf[i] != 0)
for (; i < psrc->buflen; i++) {
if (sign == 0 && psrc->buf[i] != 0)
return 0;
else if (sign != 0 && psrc->buf[i] != CELL_MASK)
return 0;
}
return 1;
}
static int bigint_bn_IsNeg(HOBJECT object)
{
sBigInteger* pobj;
int bc, sign;
pobj = (sBigInteger*)objectThis(object);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
return sign?1:0;
}
static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src)
{
static int bigint_bn_IsNE(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
......@@ -1151,9 +1216,9 @@ static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src)
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign != signsrc) {
return 0;
}
......@@ -1176,8 +1241,19 @@ static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src)
return 1;
}
static int bigint_bn_IsLE(HOBJECT object, HOBJECT src)
{
static int bigint_bn_IsGTU(HOBJECT object, HOBJECT src)
{
return 0;
}
static int bigint_bn_IsGEU(HOBJECT object, HOBJECT src)
{
return 0;
}
static int bigint_bn_IsLTU(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
......@@ -1189,16 +1265,16 @@ static int bigint_bn_IsLE(HOBJECT object, HOBJECT src)
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) {
return 0;
}
else if (sign != 0 && signsrc == 0) {
return 1;
}
bc = pobj->buflen;
if (bc < psrc->buflen)
bc = psrc->buflen;
......@@ -1236,11 +1312,11 @@ static int bigint_bn_IsLE(HOBJECT object, HOBJECT src)
return 0;
}
}
return 1;
return 0;
}
static int bigint_bn_IsLT(HOBJECT object, HOBJECT src)
{
static int bigint_bn_IsLEU(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
......@@ -1252,9 +1328,9 @@ static int bigint_bn_IsLT(HOBJECT object, HOBJECT src)
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1)));
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign == 0 && signsrc != 0) {
return 0;
}
......@@ -1299,6 +1375,374 @@ static int bigint_bn_IsLT(HOBJECT object, HOBJECT src)
return 0;
}
}
return 1;
}
static int bigint_bn_IsEQU(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
int bc, sign, signsrc;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return 0;
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign != signsrc) {
return 0;
}
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
if (pobj->buf[i] != psrc->buf[i])
return 0;
}
for (; i < pobj->buflen; i++) {
if (sign == 0 && pobj->buf[i] != 0)
return 0;
else if (sign != 0 && pobj->buf[i] != CELL_MASK)
return 0;
}
for (; i < psrc->buflen; i++) {
if (sign == 0 && psrc->buf[i] != 0)
return 0;
else if (sign != 0 && psrc->buf[i] != CELL_MASK)
return 0;
}
return 1;
}
static int bigint_bn_IsNEU(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
int bc, sign, signsrc;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return 0;
}
psrc = (sBigInteger*)objectThis(src);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
bc = psrc->width / CELL_WIDTH;
signsrc = psrc->buf[bc] & (1 << ((psrc->width - 1) & (CELL_WIDTH - 1)));
if (sign != signsrc) {
return 0;
}
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
if (pobj->buf[i] != psrc->buf[i])
return 0;
}
for (; i < pobj->buflen; i++) {
if (sign == 0 && pobj->buf[i] != 0)
return 0;
else if (sign != 0 && pobj->buf[i] != CELL_MASK)
return 0;
}
for (; i < psrc->buflen; i++) {
if (sign == 0 && psrc->buf[i] != 0)
return 0;
else if (sign != 0 && psrc->buf[i] != CELL_MASK)
return 0;
}
return 1;
}
static int bigint_bn_IsZero(HOBJECT object)
{
sBigInteger* pobj;
int i;
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
if (pobj->buf[i] != 0)
return 0;
return 1;
}
static int bigint_bn_IsNotZero(HOBJECT object)
{
sBigInteger* pobj;
int i;
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
if (pobj->buf[i] != 0)
return 0;
return 1;
}
static int bigint_bn_IsNeg(HOBJECT object)
{
sBigInteger* pobj;
int bc, sign;
pobj = (sBigInteger*)objectThis(object);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width - 1) & (CELL_WIDTH - 1)));
return sign ? 1 : 0;
}
static int bigint_bn_AndL(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] &= psrc->buf[i];
}
for (; i < pobj->buflen; i++) {
pobj->buf[i] = 0;
}
return 0;
}
static int bigint_bn_OrL(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
sBigInteger* psrc;
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] |= psrc->buf[i];
}
return 0;
}
static int bigint_bn_NotL(HOBJECT object)
{
sBigInteger* pobj;
return 0;
}
static int bigint_bn_And(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
return 0;
}
static int bigint_bn_Or(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
sBigInteger* psrc;
/*
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] |= psrc->buf[i];
}*/
return 0;
}
static int bigint_bn_Xor(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
sBigInteger* pobj;
sBigInteger* psrc;
/*
int i;
pobj = (sBigInteger*)objectThis(object);
if (!objectIsClass(src, CLSID_BIGINTEGER)) {
return -1;
}
psrc = (sBigInteger*)objectThis(src);
for (i = 0; i < pobj->buflen && i < psrc->buflen; i++) {
pobj->buf[i] ^= psrc->buf[i];
}
for (; i < pobj->buflen; i++) {
pobj->buf[i] ^= 0;
}
*/
return 0;
}
static int bigint_bn_Not(HOBJECT object, HOBJECT src)
{
int i;
sBigInteger* pobj;
/*
pobj = (sBigInteger*)objectThis(object);
for (i = 0; i < pobj->buflen; i++)
pobj->buf[i] = ~pobj->buf[i];
*/
return 0;
}
static int bigint_bn_uAnd(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uAndNot(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uOr(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uOrNot(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uXor(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_uXorNot(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
return 0;
}
static int bigint_bn_SHL(HOBJECT object, HOBJECT src, int bits)
{
sBigInteger* pobj;
int ifrom, ito, i;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits < 0)
return bigint_bn_SHR(object, src, -bits);
ito = bits / CELL_WIDTH;
bits -= ito * CELL_WIDTH;
ifrom = 0;
for (i = pobj->buflen-1; i>=0; i--) {
current = 0;
if (i >= ito) {
current = pobj->buf[i - ito];
current <<= CELL_WIDTH;
}
if (i >= ito+1) {
next = pobj->buf[i - ito -1];
current |= next;
}
current >>= CELL_WIDTH - bits;
pobj->buf[i] = (unsigned int)(current & CELL_MASK);
}
return 0;
}
static int bigint_bn_SHR(HOBJECT object, HOBJECT src, int bits)
{
sBigInteger* pobj;
int bc;
int ifrom, ito, i, zerolen;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits < 0)
return bigint_bn_SHL(object, src, -bits);
ito = 0;
ifrom = bits / CELL_WIDTH;
if (ifrom >= pobj->buflen) {
memset(pobj->buf, 0, pobj->buflen * (CELL_WIDTH/8));
return 0;
}
bits -= ifrom * CELL_WIDTH;
if (ifrom+1 < pobj->buflen) {
current = pobj->buf[ifrom+1];
current <<= CELL_WIDTH;
}
else {
current = 0;
}
current |= pobj->buf[ifrom];
current >>= bits;
for (i = ifrom + 1; i < pobj->buflen-1; i++) {
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
current >>= CELL_WIDTH;
next = pobj->buf[i + 1];
next <<= CELL_WIDTH-bits;
current |= next;
}
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
while (ito < pobj->buflen)
pobj->buf[ito++] = 0;
return 0;
}
static int bigint_bn_SAL(HOBJECT object, HOBJECT src, int bits)
{
return bigint_bn_SHL(object, src, bits);
}
static int bigint_bn_SAR(HOBJECT object, HOBJECT src, int bits)
{
sBigInteger* pobj;
int bc, sign;
int ifrom, ito, i, zerolen;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits < 0)
return bigint_bn_SHL(object, src, -bits);
bc = pobj->width / CELL_WIDTH;
sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1)));
ito = 0;
ifrom = bits / CELL_WIDTH;
if (ifrom >= pobj->buflen) {
for (i = 0;i<pobj->buflen;i++)
pobj->buf[i] = sign ? CELL_MASK : 0;
return 0;
}
bits -= ifrom * CELL_WIDTH;
if (ifrom + 1 < pobj->buflen) {
current = pobj->buf[ifrom + 1];
current <<= CELL_WIDTH;
}
else {
current = 0;
}
current |= pobj->buf[ifrom];
current >>= bits;
for (i = ifrom + 1; i < pobj->buflen - 1; i++) {
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
current >>= CELL_WIDTH;
next = pobj->buf[i + 1];
next <<= CELL_WIDTH - bits;
current |= next;
}
next = sign ? CELL_MASK : 0;
next <<= CELL_WIDTH - bits;
current |= next;
pobj->buf[ito++] = (unsigned int)(current & CELL_MASK);
while (ito < pobj->buflen)
pobj->buf[ito++] = sign ? CELL_MASK : 0;
return 0;
}
......
......@@ -162,7 +162,7 @@ static int hdl4se_print_signal_list_detector()
unsigned int v;
objectCall2(signal_value, SetWidth, 32, 0);
objectCall2(signal_list[6].detector, GetSignalValue, signal_list[6].index, signal_value);
objectCall1(signal_value, GetInt, &v);
objectCall1(signal_value, GetInt32, &v);
if (v != 4) /* 只有F3按下的时候才记录 */
return 0;
}
......@@ -172,7 +172,7 @@ static int hdl4se_print_signal_list_detector()
objectCall2(signal_value, SetWidth, 32, 0);
objectCall2(signal_list[i].detector, GetSignalValue, signal_list[i].index, signal_value);
objectCall2(signal_value, SetWidth, signal_list[i].width, 1);
objectCall1(signal_value, GetInt, &v);
objectCall1(signal_value, GetInt32, &v);
if (signal_list[i].width < 9) {
fprintf(pSignalFile, ",%d", v & ( (1 << signal_list[i].width) - 1));
}
......
......@@ -260,7 +260,7 @@ static int digitled_hdl4se_unit_GetValue(HOBJECT object, int index, int width, I
return -2; /* 上周期没有读命令,不响应,高阻状态 */
if (pobj->bReadAddr == 0) {
/* 偏移地址为0,读按键状态 */
objectCall1(value, AssignInt, pobj->keypressed);
objectCall1(value, AssignInt32, pobj->keypressed);
pobj->portdata[7] = pobj->keypressed;
return 0;
}
......@@ -278,7 +278,7 @@ static int digitled_hdl4se_unit_ClkTick(HOBJECT object)
for (i = 0; i < 7; i++) {
if (0 == objectCall3(pobj->fromunit[i], GetValue, i, 32, temp)) {
objectCall1(temp, GetInt, &pobj->portdata[i]);
objectCall1(temp, GetInt32, &pobj->portdata[i]);
}
}
objectRelease(temp);
......@@ -569,9 +569,9 @@ static int digitled_hdl4se_detector_GetSignalValue(HOBJECT object, int index, IB
return -1;
objectCall2(value, SetWidth, 32, 0);
if (index < 8)
objectCall1(value, AssignInt, pobj->portdata[index]);
objectCall1(value, AssignInt32, pobj->portdata[index]);
if (index == 8)
objectCall1(value, AssignInt, pobj->baseaddr);
objectCall1(value, AssignInt32, pobj->baseaddr);
objectCall2(value, SetWidth, digitled_datawidth[index], 0);
return 0;
}
......
......@@ -53,16 +53,16 @@ int main(int argc, char* argv[])
objectCall1(bignumber, AssignInt64, 0x102435425566ll);
objectCall3(bignumber, GetStr, 16, buf, 256);
printf("n=%s\n", buf);
objectCall1(bignumber, AddInt, -12);
objectCall2(bignumber, AddInt32, bignumber, -12);
objectCall3(bignumber, GetStr, 16, buf, 256);
printf("n=%s\n", buf);
objectCall1(bignumber2, AssignInt, -12524);
objectCall1(bignumber2, AssignInt32, -12524);
objectCall3(bignumber2, GetStr, 16, buf, 256);
printf("n=%s\n", buf);
objectCall1(bignumber, Mul, bignumber2);
objectCall2(bignumber, Mul, bignumber, bignumber2);
objectCall3(bignumber, GetStr, 16, buf, 256);
printf("n=%s\n", buf);
objectCall1(bignumber, SHR, 8);
objectCall2(bignumber, SHR, bignumber, 8);
objectCall3(bignumber, GetStr, 16, buf, 256);
printf("n=%s\n", buf);
return 0;
......
......@@ -138,7 +138,7 @@ static int hdl4se_bind2Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->inputwidth[j]);
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
}
......@@ -214,8 +214,8 @@ static int hdl4se_bind2_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
objectCall3(pobj->in[i], GetValue, pobj->in_index[i], pobj->inputwidth[i], pobj->in_data[i]);
}
for (i = BINDCOUNT - 1; i >= 0; i--) {
objectCall1(pobj->out_data, SHL, pobj->inputwidth[i]);
objectCall1(pobj->out_data, Or, pobj->in_data[i]);
objectCall2(pobj->out_data, SHL, pobj->out_data, pobj->inputwidth[i]);
objectCall2(pobj->out_data, Or, pobj->out_data, pobj->in_data[i]);
}
pobj->datavalid = 1;
}
......
......@@ -138,7 +138,7 @@ static int hdl4se_bind3Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->inputwidth[j]);
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
}
......@@ -214,8 +214,8 @@ static int hdl4se_bind3_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
objectCall3(pobj->in[i], GetValue, pobj->in_index[i], pobj->inputwidth[i], pobj->in_data[i]);
}
for (i = BINDCOUNT - 1; i >= 0; i--) {
objectCall1(pobj->out_data, SHL, pobj->inputwidth[i]);
objectCall1(pobj->out_data, Or, pobj->in_data[i]);
objectCall2(pobj->out_data, SHL, pobj->out_data, pobj->inputwidth[i]);
objectCall2(pobj->out_data, Or, pobj->out_data, pobj->in_data[i]);
}
pobj->datavalid = 1;
}
......
......@@ -138,7 +138,7 @@ static int hdl4se_bind4Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->inputwidth[j]);
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
}
......@@ -214,8 +214,8 @@ static int hdl4se_bind4_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
objectCall3(pobj->in[i], GetValue, pobj->in_index[i], pobj->inputwidth[i], pobj->in_data[i]);
}
for (i = BINDCOUNT - 1; i >= 0; i--) {
objectCall1(pobj->out_data, SHL, pobj->inputwidth[i]);
objectCall1(pobj->out_data, Or, pobj->in_data[i]);
objectCall2(pobj->out_data, SHL, pobj->out_data, pobj->inputwidth[i]);
objectCall2(pobj->out_data, Or, pobj->out_data, pobj->in_data[i]);
}
pobj->datavalid = 1;
}
......
......@@ -152,7 +152,7 @@ static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
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]);
objectCall1(temp, GetInt32, &pobj->in_width[j]);
}
else {
return EIID_INVALIDPARAM;
......@@ -160,14 +160,14 @@ static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
lstr = nstr;
}
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_width);
objectCall1(temp, GetInt32, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->op);
objectCall1(temp, GetInt32, &pobj->op);
}
else {
return EIID_INVALIDPARAM;
......@@ -243,62 +243,55 @@ static int hdl4se_binop_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
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]);
objectCall2(pobj->out_data, Add, pobj->in_data[0], 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]);
objectCall2(pobj->out_data, Sub, pobj->in_data[0], 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]);
objectCall2(pobj->out_data, Mul, pobj->in_data[0], 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]);
objectCall2(pobj->out_data, Div, pobj->in_data[0], pobj->in_data[1]);
break;
case BINOP_EQ:
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
break;
case BINOP_NE:
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
break;
case BINOP_LT:
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
break;
case BINOP_LE:
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
break;
case BINOP_GE:
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
break;
case BINOP_GT:
objectCall1(pobj->out_data, AssignInt, 1);
objectCall1(pobj->out_data, AssignInt32, 1);
if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1]))
objectCall1(pobj->out_data, AssignInt, 0);
objectCall1(pobj->out_data, AssignInt32, 0);
break;
case BINOP_AND:
objectCall1(pobj->out_data, Assign, pobj->in_data[0]);
objectCall1(pobj->out_data, And, pobj->in_data[1]);
objectCall2(pobj->out_data, And, pobj->in_data[0], 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]);
objectCall2(pobj->out_data, Or, pobj->in_data[0], 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]);
objectCall2(pobj->out_data, Xor, pobj->in_data[0], pobj->in_data[1]);
break;
}
pobj->datavalid = 1;
......
......@@ -112,7 +112,7 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
if (pobj->width <= 0 || pobj->width > (1 << 24))
return -1;
......
......@@ -135,7 +135,7 @@ static int hdl4se_mux16Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......@@ -215,7 +215,7 @@ static int hdl4se_mux16_hdl4se_unit_GetValue(HOBJECT object, int index, int widt
if (pobj->datavalid == 0) {
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, GetInt32, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
......
......@@ -137,7 +137,7 @@ static int hdl4se_mux2Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......@@ -218,7 +218,7 @@ static int hdl4se_mux2_hdl4se_unit_GetValue(HOBJECT object, int index, int width
if (pobj->datavalid == 0) {
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, GetInt32, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
......
......@@ -135,7 +135,7 @@ static int hdl4se_mux4Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......@@ -215,7 +215,7 @@ static int hdl4se_mux4_hdl4se_unit_GetValue(HOBJECT object, int index, int width
if (pobj->datavalid == 0) {
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, GetInt32, &sel);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) {
objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data);
......
......@@ -135,7 +135,7 @@ static int hdl4se_mux8Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......@@ -214,7 +214,7 @@ static int hdl4se_mux8_hdl4se_unit_GetValue(HOBJECT object, int index, int width
pobj = (sHDL4SEMux8*)objectThis(object);
if (pobj->datavalid == 0) {
objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel);
objectCall1(pobj->in_sel, GetInt, &sel);
objectCall1(pobj->in_sel, GetInt32, &sel);
objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0);
sel &= MUXCOUNT - 1;
if (sel >= 0 && sel < MUXCOUNT) {
......
......@@ -121,7 +121,7 @@ static int hdl4se_regCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* p
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......
......@@ -141,7 +141,7 @@ static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
else {
return -1;
......@@ -149,14 +149,14 @@ static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][0]);
objectCall1(temp, GetInt32, &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]);
objectCall1(temp, GetInt32, &pobj->out_info[j][1]);
}
else {
return -1;
......@@ -239,7 +239,7 @@ static int hdl4se_split2_hdl4se_unit_GetValue(HOBJECT object, int index, int wid
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]);
objectCall3(pobj->out_data[i], AssignSubBits, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]);
}
pobj->datavalid = 1;
}
......
......@@ -144,7 +144,7 @@ static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
else {
return -1;
......@@ -152,14 +152,14 @@ static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_info[j][0]);
objectCall1(temp, GetInt32, &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]);
objectCall1(temp, GetInt32, &pobj->out_info[j][1]);
}
else {
return -1;
......@@ -242,7 +242,7 @@ static int hdl4se_split4_hdl4se_unit_GetValue(HOBJECT object, int index, int wid
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]);
objectCall3(pobj->out_data[i], AssignSubBits, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]);
}
pobj->datavalid = 1;
}
......
......@@ -138,21 +138,21 @@ static int hdl4se_unopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
const char* lstr;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->in_width);
objectCall1(temp, GetInt32, &pobj->in_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->out_width);
objectCall1(temp, GetInt32, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
objectCall1(temp, GetInt, &pobj->op);
objectCall1(temp, GetInt32, &pobj->op);
}
else {
return EIID_INVALIDPARAM;
......@@ -220,31 +220,31 @@ static int hdl4se_unop_hdl4se_unit_GetValue(HOBJECT object, int index, int width
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);
objectCall1(pobj->out_data, Neg, pobj->out_data);
break;
case UNOP_NOT:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->out_data);
objectCall0(pobj->out_data, Not);
objectCall1(pobj->out_data, Not, pobj->out_data);
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);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->out_data, uAnd, pobj->out_data) != 0) {
objectCall1(pobj->out_data, AssignInt32, 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);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->out_data, uOr, pobj->out_data) != 0) {
objectCall1(pobj->out_data, AssignInt32, 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);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->out_data, uXor, pobj->out_data) != 0) {
objectCall1(pobj->out_data, AssignInt32, 1);
}
break;
}
......
......@@ -126,7 +126,7 @@ static int hdl4se_wireCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
objectCall1(temp, GetInt, &pobj->width);
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
}
......
......@@ -145,7 +145,7 @@ static int hdl4sesim_hdl4se_unit_GetValue(HOBJECT object, int index, int width,
sHDL4SESim* pobj;
pobj = (sHDL4SESim*)objectThis(object);
if (index == 0) { /* 0.nwReset */
objectCall1(value, AssignInt, pobj->reset);
objectCall1(value, AssignInt32, pobj->reset);
}
else if (index >= 1 && index <= 6) { /* 1..6 转发到topmodule*/
objectCall3(pobj->topmodule, GetValue, index, width, value);
......@@ -258,7 +258,7 @@ static int hdl4sesim_hdl4se_detector_GetSignalValue(HOBJECT object, int index, I
{
sHDL4SESim* pobj;
pobj = (sHDL4SESim*)objectThis(object);
objectCall1(value, AssignInt, pobj->reset);
objectCall1(value, AssignInt32, pobj->reset);
objectCall2(value, SetWidth, 1, 1);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册