Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
饶先宏
hdl4se
提交
5a685b4d
H
hdl4se
项目概览
饶先宏
/
hdl4se
通知
12
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hdl4se
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5a685b4d
编写于
5月 20, 2021
作者:
饶先宏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
202105201746
上级
5b61d24f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
681 addition
and
58 deletion
+681
-58
bignumber/include/bignumber.h
bignumber/include/bignumber.h
+23
-18
bignumber/src/bignumber.c
bignumber/src/bignumber.c
+590
-1
examples/CMakeLists.txt
examples/CMakeLists.txt
+1
-0
examples/testbignumber/CMakeLists.txt
examples/testbignumber/CMakeLists.txt
+16
-0
examples/testbignumber/testbignumber.c
examples/testbignumber/testbignumber.c
+51
-0
hdl4secell/include/hdl4secell.h
hdl4secell/include/hdl4secell.h
+0
-12
hdl4secell/src/hdl4secell.c
hdl4secell/src/hdl4secell.c
+0
-27
未找到文件。
bignumber/include/bignumber.h
浏览文件 @
5a685b4d
...
...
@@ -51,13 +51,13 @@ typedef struct sIBigNumber {
OBJECT_INTERFACE
int
(
*
GetBitsCount
)(
HOBJECT
object
);
int
(
*
GetInt
)(
HOBJECT
object
,
int
*
pvaue
);
int
(
*
GetInt64
)(
HOBJECT
object
,
long
long
*
pvaue
);
int
(
*
GetFloat
)(
HOBJECT
object
,
float
*
pvaue
);
int
(
*
GetDouble
)(
HOBJECT
object
,
double
*
pvaue
);
int
(
*
GetStr
)(
HOBJECT
object
,
int
base
,
char
*
str
,
int
str
len
);
int
(
*
GetInt
)(
HOBJECT
object
,
int
*
pva
l
ue
);
int
(
*
GetInt64
)(
HOBJECT
object
,
long
long
*
pva
l
ue
);
int
(
*
GetFloat
)(
HOBJECT
object
,
float
*
pva
l
ue
);
int
(
*
GetDouble
)(
HOBJECT
object
,
double
*
pva
l
ue
);
int
(
*
GetStr
)(
HOBJECT
object
,
int
base
,
char
*
str
,
int
buf
len
);
int
(
*
AssignStr
)(
HOBJECT
object
,
const
char
*
str
);
int
(
*
AssignStr
)(
HOBJECT
object
,
const
char
*
str
,
const
char
**
nstr
);
int
(
*
AssignInt
)(
HOBJECT
object
,
int
value
);
int
(
*
AssignInt64
)(
HOBJECT
object
,
long
long
value
);
int
(
*
AssignFloat
)(
HOBJECT
object
,
float
value
);
...
...
@@ -88,22 +88,22 @@ typedef struct sIBigNumber {
int
(
*
IsLT
)(
HOBJECT
object
,
HOBJECT
src
);
}
IBigNumber
;
#define
HDL4SEUNIT
_VARDECLARE
#define
HDL4SEUNIT
_VARINIT(_objptr, _sid)
#define
HDL4SEUNIT
_FUNCDECLARE(_obj, _clsid, _localstruct) \
static int _obj##_bn_GetBitsCount
)
(HOBJECT object); \
static int _obj##_bn_GetInt(HOBJECT object, int* pvaue); \
static int _obj##_bn_GetInt64(HOBJECT object, long long* pvaue); \
static int _obj##_bn_GetFloat(HOBJECT object, float* pvaue); \
static int _obj##_bn_GetDouble(HOBJECT object, double* pvaue); \
static int _obj##_bn_GetStr(HOBJECT object, int base, char* str, int
str
len); \
static int _obj##_bn_AssignStr(HOBJECT object, const char* str); \
#define
BIGNUMBER
_VARDECLARE
#define
BIGNUMBER
_VARINIT(_objptr, _sid)
#define
BIGNUMBER
_FUNCDECLARE(_obj, _clsid, _localstruct) \
static int _obj##_bn_GetBitsCount(HOBJECT object); \
static int _obj##_bn_GetInt(HOBJECT object, int* pva
l
ue); \
static int _obj##_bn_GetInt64(HOBJECT object, long long* pva
l
ue); \
static int _obj##_bn_GetFloat(HOBJECT object, float* pva
l
ue); \
static int _obj##_bn_GetDouble(HOBJECT object, double* pva
l
ue); \
static int _obj##_bn_GetStr(HOBJECT object, int base, char* str, int
buf
len); \
static int _obj##_bn_AssignStr(HOBJECT object, const char* str
, const char ** nstr
); \
static int _obj##_bn_AssignInt(HOBJECT object, int value); \
static int _obj##_bn_AssignInt64(HOBJECT object, long long value); \
static int _obj##_bn_AssignFloat(HOBJECT object, float value); \
static int _obj##_bn_AssignDouble(HOBJECT object, double value); \
static int _obj##_bn_Assign(HOBJECT object, HOBJECT src);\
static int _obj##_bn_Assign(HOBJECT object, HOBJECT src);
\
static int _obj##_bn_Neg(HOBJECT object); \
static int _obj##_bn_AddInt(HOBJECT object, int value); \
static int _obj##_bn_Add(HOBJECT object, HOBJECT src); \
...
...
@@ -156,6 +156,11 @@ typedef struct sIBigNumber {
_obj##_bn_IsLT \
};
DEFINE_GUID
(
CLSID_BIGINTEGER
,
0xabde0235
,
0x8f00
,
0x4f30
,
0x92
,
0xbf
,
0x95
,
0x2e
,
0x35
,
0x8b
,
0x1a
,
0xeb
);
IBigNumber
**
bigintegerCreate
();
#endif
/* _ASMLANGUAGE */
#ifdef __cplusplus
...
...
bignumber/src/bignumber.c
浏览文件 @
5a685b4d
...
...
@@ -39,4 +39,593 @@
#include "object.h"
#define IMPLEMENT_GUID
#include "bignumber.h"
#undef IMPLEMENT_GUID
\ No newline at end of file
#undef IMPLEMENT_GUID
typedef
struct
_sBigInteger
{
OBJECT_HEADER
INTERFACE_DECLARE
(
IBigNumber
)
BIGNUMBER_VARDECLARE
int
buflen
;
int
sign
;
unsigned
int
*
buf
;
}
sBigInteger
;
OBJECT_FUNCDECLARE
(
bigint
,
CLSID_BIGINTEGER
);
BIGNUMBER_FUNCDECLARE
(
bigint
,
CLSID_BIGINTEGER
,
sBigInteger
);
OBJECT_FUNCIMPL
(
bigint
,
sBigInteger
,
CLSID_BIGINTEGER
);
QUERYINTERFACE_BEGIN
(
bigint
,
CLSID_BIGINTEGER
)
QUERYINTERFACE_ITEM
(
IID_BIGNUMBER
,
IBigNumber
,
sBigInteger
)
QUERYINTERFACE_END
static
const
char
*
bigintModuleInfo
()
{
return
"1.0.0-20210520.1355 Big integer library"
;
}
static
int
bigintCreate
(
const
PARAMITEM
*
pParams
,
int
paramcount
,
HOBJECT
*
pObject
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
malloc
(
sizeof
(
sBigInteger
));
if
(
pobj
==
NULL
)
return
-
1
;
*
pObject
=
0
;
BIGNUMBER_VARINIT
(
pobj
,
CLSID_BIGINTEGER
);
INTERFACE_INIT
(
IBigNumber
,
pobj
,
bigint
,
bn
);
pobj
->
sign
=
0
;
pobj
->
buflen
=
2
;
pobj
->
buf
=
malloc
(
pobj
->
buflen
*
sizeof
(
unsigned
int
));
pobj
->
buf
[
0
]
=
pobj
->
buf
[
1
]
=
0
;
/* 返回生成的对象 */
OBJECT_RETURN_GEN
(
bigint
,
pobj
,
pObject
,
CLSID_BIGINTEGER
);
return
EIID_OK
;
}
static
int
actualwidth
(
unsigned
int
n
)
{
unsigned
int
c
=
1
;
int
ret
=
1
;
if
(
c
&
0x80000000
)
return
32
;
while
(
c
<
n
)
{
c
<<=
1
;
ret
++
;
}
return
ret
;
}
static
void
bigintDestroy
(
HOBJECT
object
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
free
(
pobj
->
buf
);
free
(
pobj
);
}
static
int
bigintValid
(
HOBJECT
object
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
pobj
==
NULL
)
return
0
;
if
(
pobj
->
buflen
<
2
)
return
0
;
if
(
pobj
->
buf
==
NULL
)
return
0
;
return
1
;
}
static
int
bigint_bn_GetBitsCount
(
HOBJECT
object
)
{
int
i
;
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
for
(
i
=
pobj
->
buflen
-
1
;
i
>=
0
;
i
--
)
{
if
(
pobj
->
buf
[
i
]
!=
0
)
{
return
i
*
32
+
actualwidth
(
pobj
->
buf
[
i
]);
}
}
return
0
;
}
static
int
bigint_bn_GetInt
(
HOBJECT
object
,
int
*
pvalue
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
*
pvalue
=
pobj
->
buf
[
0
];
if
(
pobj
->
sign
)
*
pvalue
=
-
(
*
pvalue
);
return
0
;
}
static
int
bigint_bn_GetInt64
(
HOBJECT
object
,
long
long
*
pvalue
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
*
pvalue
=
(
long
long
)
pobj
->
buf
[
0
];
if
(
pobj
->
buflen
>=
2
)
{
long
long
temp
;
temp
=
pobj
->
buf
[
1
];
temp
<<=
32
;
*
pvalue
+=
temp
;
}
if
(
pobj
->
sign
)
*
pvalue
=
-
(
*
pvalue
);
return
0
;
}
static
int
bigint_bn_GetFloat
(
HOBJECT
object
,
float
*
pvalue
)
{
return
0
;
}
static
int
bigint_bn_GetDouble
(
HOBJECT
object
,
double
*
pvalue
)
{
return
0
;
}
static
int
bigint_bn_GetStr
(
HOBJECT
object
,
int
base
,
char
*
str
,
int
buflen
)
{
int
i
;
int
bc
,
ac
;
char
fmt
[
10
];
char
buf
[
10
];
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
str
[
0
]
=
0
;
bc
=
bigint_bn_GetBitsCount
(
object
);
sprintf
(
str
,
"%d'h"
,
bc
);
i
=
((
bc
+
31
)
/
32
)
-
1
;
ac
=
actualwidth
(
pobj
->
buf
[
i
]);
ac
=
(
ac
+
7
)
/
8
;
sprintf
(
fmt
,
"%%%dx_"
,
ac
);
sprintf
(
buf
,
fmt
,
pobj
->
buf
[
i
]);
strcat
(
str
,
buf
);
for
(
i
=
((
bc
+
31
)
/
32
)
-
2
;
i
>=
0
;
i
--
)
{
sprintf
(
buf
,
"%08x"
,
pobj
->
buf
[
i
]);
strcat
(
str
,
buf
);
if
(
i
>
0
)
strcat
(
str
,
"_"
);
}
return
0
;
}
enum
TOKEN_STATE
{
TOKEN_INITIAL
,
TOKEN_NUM
,
TOKEN_BASE
,
TOKEN_BIN
,
TOKEN_OCT
,
TOKEN_DEC
,
TOKEN_HEX
};
static
int
bigint_bn_AssignStr
(
HOBJECT
object
,
const
char
*
str
,
const
char
**
nstr
)
{
enum
TOKEN_STATE
state
;
const
char
*
strt
=
str
;
int
numvalid
=
0
;
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
state
=
TOKEN_INITIAL
;
*
nstr
=
strt
;
while
(
*
strt
!=
0
)
{
int
ch
=
*
strt
;
switch
(
state
)
{
case
TOKEN_INITIAL
:
{
if
(
ch
==
'\''
)
{
state
=
TOKEN_BASE
;
}
else
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
bigint_bn_AssignInt
(
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'
);
}
else
if
(
ch
==
'\''
)
{
state
=
TOKEN_BASE
;
numvalid
=
0
;
}
else
{
goto
lastnum
;
}
}
break
;
case
TOKEN_BASE
:
{
if
(
ch
==
'b'
||
ch
==
'B'
)
{
bigint_bn_AssignInt
(
object
,
0
);
state
=
TOKEN_BIN
;
}
else
if
(
ch
==
'h'
||
ch
==
'H'
)
{
bigint_bn_AssignInt
(
object
,
0
);
state
=
TOKEN_HEX
;
}
else
if
(
ch
==
'o'
||
ch
==
'O'
)
{
bigint_bn_AssignInt
(
object
,
0
);
state
=
TOKEN_OCT
;
}
else
if
(
ch
==
'd'
||
ch
==
'D'
)
{
bigint_bn_AssignInt
(
object
,
0
);
state
=
TOKEN_DEC
;
}
else
if
(
ch
==
' '
||
ch
==
'\t'
||
ch
==
'\r'
||
ch
==
'\n'
)
{
}
else
{
return
-
1
;
}
}
break
;
case
TOKEN_BIN
:
{
if
(
ch
==
'0'
||
ch
==
'1'
)
{
bigint_bn_MulInt
(
object
,
2
);
bigint_bn_AddInt
(
object
,
ch
-
'0'
);
numvalid
=
1
;
}
else
if
(
ch
==
'_'
)
{
}
else
{
goto
lastnum
;
}
}
break
;
case
TOKEN_OCT
:
{
if
(
ch
>=
'0'
&&
ch
<=
'7'
)
{
bigint_bn_MulInt
(
object
,
8
);
bigint_bn_AddInt
(
object
,
ch
-
'0'
);
numvalid
=
1
;
}
else
if
(
ch
==
'_'
)
{
}
else
{
goto
lastnum
;
}
}
break
;
case
TOKEN_DEC
:
{
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
bigint_bn_MulInt
(
object
,
10
);
bigint_bn_AddInt
(
object
,
ch
-
'0'
);
numvalid
=
1
;
}
else
{
goto
lastnum
;
}
}
break
;
case
TOKEN_HEX
:
{
if
((
ch
>=
'0'
&&
ch
<=
'9'
)
||
(
ch
>=
'a'
&&
ch
<=
'f'
)
||
(
ch
>=
'A'
&&
ch
<=
'F'
))
{
numvalid
=
1
;
bigint_bn_MulInt
(
object
,
16
);
if
(
ch
>
'0'
&&
ch
<=
'9'
)
bigint_bn_AddInt
(
object
,
ch
-
'0'
);
else
if
(
ch
>=
'a'
&&
ch
<=
'f'
)
bigint_bn_AddInt
(
object
,
ch
-
'a'
+
10
);
else
if
(
ch
>=
'A'
&&
ch
<=
'F'
)
bigint_bn_AddInt
(
object
,
ch
-
'A'
+
10
);
}
else
if
(
ch
==
'_'
)
{
}
else
{
goto
lastnum
;
}
}
break
;
}
strt
++
;
}
if
(
numvalid
==
0
)
return
-
1
;
lastnum:
*
nstr
=
strt
;
return
0
;
}
static
int
bigint_bn_AssignInt
(
HOBJECT
object
,
int
value
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
value
<
0
)
{
pobj
->
sign
=
1
;
value
=
-
value
;
}
else
{
pobj
->
sign
=
0
;
}
memset
(
pobj
->
buf
,
0
,
pobj
->
buflen
*
sizeof
(
unsigned
int
));
pobj
->
buf
[
0
]
=
value
;
return
0
;
}
static
int
bigint_bn_AssignInt64
(
HOBJECT
object
,
long
long
value
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
value
<
0
)
{
pobj
->
sign
=
1
;
value
=
-
value
;
}
else
{
pobj
->
sign
=
0
;
}
memset
(
pobj
->
buf
,
0
,
pobj
->
buflen
*
sizeof
(
unsigned
int
));
pobj
->
buf
[
0
]
=
value
&
0xFFFFFFFF
;
pobj
->
buf
[
1
]
=
value
>>
32
;
return
0
;
}
static
int
bigint_bn_AssignFloat
(
HOBJECT
object
,
float
value
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_AssignDouble
(
HOBJECT
object
,
double
value
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_Assign
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
sBigInteger
*
psrc
;
unsigned
int
*
buf
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
!
objectIsClass
(
src
,
CLSID_BIGINTEGER
))
{
return
-
1
;
}
psrc
=
(
sBigInteger
*
)
objectThis
(
src
);
buf
=
(
unsigned
int
*
)
malloc
(
psrc
->
buflen
*
sizeof
(
unsigned
int
));
if
(
buf
==
NULL
)
return
-
2
;
free
(
pobj
->
buf
);
pobj
->
buf
=
buf
;
memcpy
(
pobj
->
buf
,
psrc
->
buf
,
psrc
->
buflen
*
sizeof
(
unsigned
int
));
pobj
->
buflen
=
psrc
->
buflen
;
pobj
->
sign
=
psrc
->
sign
;
return
0
;
}
static
int
bigint_bn_Neg
(
HOBJECT
object
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
pobj
->
sign
=
1
-
pobj
->
sign
;
return
0
;
}
static
int
bigint_expandbuf
(
sBigInteger
*
pobj
)
{
unsigned
int
*
buf
;
buf
=
(
unsigned
int
*
)
malloc
(
pobj
->
buflen
*
2
*
sizeof
(
unsigned
int
));
if
(
buf
==
NULL
)
return
-
1
;
memcpy
(
buf
,
pobj
->
buf
,
pobj
->
buflen
*
sizeof
(
unsigned
int
));
memset
(
&
buf
[
pobj
->
buflen
],
0
,
pobj
->
buflen
*
sizeof
(
unsigned
int
));
free
(
pobj
->
buf
);
pobj
->
buf
=
buf
;
pobj
->
buflen
*=
2
;
return
0
;
}
static
int
bigint_bn_AddInt
(
HOBJECT
object
,
int
value
)
{
int
vsign
;
long
long
temp
;
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
value
>=
0
)
{
vsign
=
0
;
}
else
{
vsign
=
1
;
value
=
-
value
;
}
temp
=
pobj
->
buf
[
0
];
if
(
vsign
==
pobj
->
sign
)
{
int
i
;
temp
=
temp
+
value
;
pobj
->
buf
[
0
]
=
temp
&
0xffffffff
;
temp
>>=
32
;
i
=
1
;
/* 处理进位 */
while
(
temp
!=
0
)
{
if
(
i
>=
pobj
->
buflen
)
{
if
(
0
!=
bigint_expandbuf
(
pobj
))
return
-
1
;
}
temp
+=
pobj
->
buf
[
i
];
pobj
->
buf
[
i
]
=
temp
&
0xffffffff
;
temp
>>=
32
;
i
++
;
}
}
else
{
int
bc
=
bigint_bn_GetBitsCount
(
object
);
if
(
bc
<=
32
)
{
if
(
pobj
->
buf
[
0
]
<
value
)
{
pobj
->
sign
=
1
-
pobj
->
sign
;
pobj
->
buf
[
0
]
=
value
-
pobj
->
buf
[
0
];
}
else
{
pobj
->
buf
[
0
]
-=
value
;
}
}
else
{
int
borrow
;
int
i
;
borrow
=
0
;
temp
=
pobj
->
buf
[
0
];
if
(
temp
<
value
)
{
temp
+=
1ll
<<
32
;
borrow
=
1
;
}
i
=
1
;
temp
-=
value
;
pobj
->
buf
[
0
]
=
temp
&
0xffffffff
;
/* 处理借位 */
while
(
borrow
)
{
if
(
pobj
->
buf
[
i
]
==
0
)
{
i
++
;
}
else
{
pobj
->
buf
[
i
]
--
;
borrow
=
0
;
}
}
}
}
return
0
;
}
static
int
bigint_bn_Add
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_SubInt
(
HOBJECT
object
,
int
value
)
{
return
bigint_bn_AddInt
(
object
,
-
value
);
}
static
int
bigint_bn_Sub
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_MulInt
(
HOBJECT
object
,
int
value
)
{
long
long
addin
,
mulr
;
int
vsign
;
int
i
;
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
if
(
value
>=
0
)
{
vsign
=
0
;
}
else
{
vsign
=
1
;
value
=
-
value
;
}
pobj
->
sign
=
(
vsign
==
pobj
->
sign
)
?
0
:
1
;
addin
=
0
;
for
(
i
=
0
;
i
<
pobj
->
buflen
;
i
++
)
{
mulr
=
value
;
mulr
*=
pobj
->
buf
[
i
];
mulr
+=
addin
;
pobj
->
buf
[
i
]
=
mulr
&
0xffffffff
;
addin
=
mulr
>>
32
;
}
if
(
addin
!=
0
)
{
if
(
0
!=
bigint_expandbuf
(
pobj
))
return
-
1
;
pobj
->
buf
[
i
]
=
addin
&
0xffffffff
;
}
return
0
;
}
static
int
bigint_bn_Mul
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_DivInt
(
HOBJECT
object
,
int
value
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_Div
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_SHL
(
HOBJECT
object
,
int
bits
)
{
sBigInteger
*
pobj
;
int
bc
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
bc
=
bigint_bn_GetBitsCount
(
object
);
while
(
bc
+
bits
>
pobj
->
buflen
*
32
)
{
if
(
bigint_expandbuf
(
pobj
)
!=
0
)
return
-
1
;
}
/* fixed me */
return
0
;
}
static
int
bigint_bn_SHR
(
HOBJECT
object
,
int
bits
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_And
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_Or
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_IsZero
(
HOBJECT
object
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_IsNeg
(
HOBJECT
object
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_IsEQ
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_IsLE
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
static
int
bigint_bn_IsLT
(
HOBJECT
object
,
HOBJECT
src
)
{
sBigInteger
*
pobj
;
pobj
=
(
sBigInteger
*
)
objectThis
(
object
);
return
0
;
}
IBigNumber
**
bigintegerCreate
()
{
int
ret
;
IBigNumber
**
bn
;
A_u_t_o_registor_bigint
();
ret
=
objectCreateEx
(
CLSID_BIGINTEGER
,
NULL
,
0
,
IID_BIGNUMBER
,
(
const
void
**
)
&
bn
);
return
bn
;
}
examples/CMakeLists.txt
浏览文件 @
5a685b4d
...
...
@@ -4,4 +4,5 @@
cmake_minimum_required
(
VERSION 3.8
)
add_subdirectory
(
"counter"
)
add_subdirectory
(
"testbignumber"
)
\ No newline at end of file
examples/testbignumber/CMakeLists.txt
0 → 100644
浏览文件 @
5a685b4d
# CMakeList.txt: 顶层 CMake 项目文件,在此处执行全局配置
# 并包含子项目。
#
cmake_minimum_required
(
VERSION 3.8
)
add_executable
(
testbignumber
"testbignumber.c"
)
target_link_libraries
(
testbignumber lcom bignumber
)
include_directories
(
"../../../lcom/include"
)
include_directories
(
"../../hdl4sesim/include"
)
include_directories
(
"../../hdl4secell/include"
)
include_directories
(
"../../preprocess/include"
)
include_directories
(
"../../bignumber/include"
)
include_directories
(
"../counter/include"
)
include_directories
(
"../../../glfw/include"
)
include_directories
(
"../../../glfw/deps"
)
examples/testbignumber/testbignumber.c
0 → 100644
浏览文件 @
5a685b4d
/*
** 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.
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "bignumber.h"
const
char
*
testnumber
=
"43, 4, 128'b0101011111011010100011000101010101010100010101010101010001, 'h94397afc4343, 5'd98"
;
int
main
(
int
argc
,
char
*
argv
[])
{
char
buf
[
128
];
IBigNumber
**
bignumber
=
bigintegerCreate
();
const
char
*
nstr
=
testnumber
;
const
char
*
lstr
=
testnumber
;
while
(
0
==
objectCall2
(
bignumber
,
AssignStr
,
lstr
,
&
nstr
))
{
objectCall3
(
bignumber
,
GetStr
,
16
,
buf
,
128
);
printf
(
"%s=%s,
\n
next=%s
\n
"
,
lstr
,
buf
,
nstr
);
lstr
=
nstr
;
}
return
0
;
}
\ No newline at end of file
hdl4secell/include/hdl4secell.h
浏览文件 @
5a685b4d
...
...
@@ -164,18 +164,6 @@ DEFINE_GUID(CLSID_HDL4SE_MODULE,0x167d115e, 0x0c1e, 0x484e, 0x8b, 0xf3, 0xa7, 0x
*/
IHDL4SEUnit
**
hdl4seCreateUnit
(
IHDL4SEModule
**
parent
,
IIDTYPE
clsid
,
char
*
instanceparam
,
char
*
name
);
/*
下面是支持函数
*/
/*
把一个"7691029B-DAE3-4AC9-9A81-411C1B529039"格式的IID转换成一个IIDTYPE
返回值:
0 -- 成功
否则 -- 格式不对
*/
int
str2iid
(
const
char
*
str
,
IIDTYPE
iid
);
/*
从字符串中解析下一个数字,数字是verilog数字格式, 自动跳过开始的非数字字符
str: 字符串,
...
...
hdl4secell/src/hdl4secell.c
浏览文件 @
5a685b4d
...
...
@@ -60,33 +60,6 @@ IHDL4SEUnit** hdl4seCreateUnit(IHDL4SEModule** parent, IIDTYPE clsid, char* inst
return
result
;
}
/*
把一个"7691029B-DAE3-4AC9-9A81-411C1B529039"格式的IID转换成一个IIDTYPE
返回值:
0 -- 成功
否则 -- 格式不对
*/
int
str2iid
(
const
char
*
str
,
IIDTYPE
iid
)
{
unsigned
int
L
;
unsigned
int
s
[
2
];
unsigned
int
b
[
8
];
if
(
sscanf_s
(
str
,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
,
&
L
,
&
s
[
0
],
&
s
[
1
],
&
b
[
0
],
&
b
[
1
],
&
b
[
2
],
&
b
[
3
],
&
b
[
4
],
&
b
[
5
],
&
b
[
6
],
&
b
[
7
])
!=
11
)
return
-
1
;
#define IMPLEMENT_GUID
#include "guid.h"
{
DEFINE_GUID
(
temp
,
L
,
s
[
0
],
s
[
1
],
b
[
0
],
b
[
1
],
b
[
2
],
b
[
3
],
b
[
4
],
b
[
5
],
b
[
6
],
b
[
7
]);
iid
[
0
]
=
temp
[
0
];
iid
[
1
]
=
temp
[
1
];
iid
[
2
]
=
temp
[
2
];
iid
[
3
]
=
temp
[
3
];
}
#undef IMPLEMENT_GUID
return
0
;
}
/*
从字符串中解析下一个数字,数字是verilog数字格式, 自动跳过开始的非数字字符
str: 字符串
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录