bignumber.h 7.4 KB
Newer Older
饶先宏's avatar
饶先宏 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
** 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.
*/

/*
* bignumber.h
    202105201110: rxh, initial version
*/

#ifndef __BIGNUMBER_H
#define __BIGNUMBER_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _ASMLANGUAGE

#include "guid.h"

DEFINE_GUID(IID_BIGNUMBER, 0x80dc5305, 0x1ca6, 0x4678, 0xbf, 0xc3, 0xd0, 0x1b, 0x9c, 0xd3, 0x63, 0x62);

typedef struct sIBigNumber {
    OBJECT_INTERFACE
饶先宏's avatar
饶先宏 已提交
52 53 54
    int (*GetWidth)(HOBJECT object);
    int (*SetWidth)(HOBJECT object, int width, int signexpand);

饶先宏's avatar
饶先宏 已提交
55 56 57
    int (*GetInt)(HOBJECT object, int* pvalue);
    int (*GetInt64)(HOBJECT object, long long* pvalue);
    int (*GetStr)(HOBJECT object, int base, char * str, int buflen);
饶先宏's avatar
饶先宏 已提交
58

饶先宏's avatar
饶先宏 已提交
59
    int (*AssignStr)(HOBJECT object, const char * str, const char ** nstr);
饶先宏's avatar
饶先宏 已提交
60 61 62
    int (*AssignInt)(HOBJECT object, int value);
    int (*AssignInt64)(HOBJECT object, long long value);
    int (*Assign)(HOBJECT object, HOBJECT src);
饶先宏's avatar
饶先宏 已提交
63 64
    int (*AssignSub)(HOBJECT object, HOBJECT src, int from, int width);

饶先宏's avatar
饶先宏 已提交
65
    int (*Bind)(HOBJECT object, HOBJECT src);
饶先宏's avatar
饶先宏 已提交
66

饶先宏's avatar
饶先宏 已提交
67
    int (*Abs)(HOBJECT object);
饶先宏's avatar
饶先宏 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80
    int (*Neg)(HOBJECT object);
    int (*AddInt)(HOBJECT object, int value);
    int (*Add)(HOBJECT object, HOBJECT src);
    int (*SubInt)(HOBJECT object, int value);
    int (*Sub)(HOBJECT object, HOBJECT src);
    int (*MulInt)(HOBJECT object, int value);
    int (*Mul)(HOBJECT object, HOBJECT src);

    int (*DivInt)(HOBJECT object, int value);
    int (*Div)(HOBJECT object, HOBJECT src);
    
    int (*SHL)(HOBJECT object, int bits);
    int (*SHR)(HOBJECT object, int bits);
饶先宏's avatar
饶先宏 已提交
81 82
    int (*SAL)(HOBJECT object, int bits);
    int (*SAR)(HOBJECT object, int bits);
饶先宏's avatar
饶先宏 已提交
83

饶先宏's avatar
饶先宏 已提交
84 85 86 87
    int (*Not)(HOBJECT object);
    int (*uAnd)(HOBJECT object);
    int (*uOr)(HOBJECT object);
    int (*uXor)(HOBJECT object);
饶先宏's avatar
饶先宏 已提交
88 89
    int (*And)(HOBJECT object, HOBJECT src);
    int (*Or)(HOBJECT object, HOBJECT src);  
饶先宏's avatar
饶先宏 已提交
90
    int (*Xor)(HOBJECT object, HOBJECT src);
饶先宏's avatar
饶先宏 已提交
91 92 93 94 95 96 97 98

    int (*IsZero)(HOBJECT object);
    int (*IsNeg)(HOBJECT object);
    int (*IsEQ)(HOBJECT object, HOBJECT src);
    int (*IsLE)(HOBJECT object, HOBJECT src);
    int (*IsLT)(HOBJECT object, HOBJECT src);
}IBigNumber;

饶先宏's avatar
饶先宏 已提交
99 100 101 102
#define BIGNUMBER_VARDECLARE
#define BIGNUMBER_VARINIT(_objptr, _sid)

#define BIGNUMBER_FUNCDECLARE(_obj, _clsid, _localstruct) \
饶先宏's avatar
饶先宏 已提交
103 104
    static int _obj##_bn_GetWidth(HOBJECT object); \
    static int _obj##_bn_SetWidth(HOBJECT object, int width, int signexpand); \
饶先宏's avatar
饶先宏 已提交
105 106 107 108
    static int _obj##_bn_GetInt(HOBJECT object, int* pvalue); \
    static int _obj##_bn_GetInt64(HOBJECT object, long long* pvalue); \
    static int _obj##_bn_GetStr(HOBJECT object, int base, char* str, int buflen); \
    static int _obj##_bn_AssignStr(HOBJECT object, const char* str, const char ** nstr); \
饶先宏's avatar
饶先宏 已提交
109 110
    static int _obj##_bn_AssignInt(HOBJECT object, int value); \
    static int _obj##_bn_AssignInt64(HOBJECT object, long long value); \
饶先宏's avatar
饶先宏 已提交
111
    static int _obj##_bn_Assign(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
112
    static int _obj##_bn_AssignSub(HOBJECT object, HOBJECT src, int from, int width); \
饶先宏's avatar
饶先宏 已提交
113
    static int _obj##_bn_Bind(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
114
    static int _obj##_bn_Abs(HOBJECT object); \
饶先宏's avatar
饶先宏 已提交
115 116 117 118 119 120 121 122 123 124 125
    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); \
    static int _obj##_bn_SubInt(HOBJECT object, int value); \
    static int _obj##_bn_Sub(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_MulInt(HOBJECT object, int value); \
    static int _obj##_bn_Mul(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_DivInt(HOBJECT object, int value); \
    static int _obj##_bn_Div(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_SHL(HOBJECT object, int bits); \
    static int _obj##_bn_SHR(HOBJECT object, int bits); \
饶先宏's avatar
饶先宏 已提交
126 127
    static int _obj##_bn_SAL(HOBJECT object, int bits); \
    static int _obj##_bn_SAR(HOBJECT object, int bits); \
饶先宏's avatar
饶先宏 已提交
128 129 130 131
    static int _obj##_bn_Not(HOBJECT object); \
    static int _obj##_bn_uAnd(HOBJECT object); \
    static int _obj##_bn_uOr(HOBJECT object); \
    static int _obj##_bn_uXor(HOBJECT object); \
饶先宏's avatar
饶先宏 已提交
132 133
    static int _obj##_bn_And(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_Or(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
134
    static int _obj##_bn_Xor(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
135 136 137 138 139 140 141
    static int _obj##_bn_IsZero(HOBJECT object); \
    static int _obj##_bn_IsNeg(HOBJECT object); \
    static int _obj##_bn_IsEQ(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_IsLE(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_IsLT(HOBJECT object, HOBJECT src); \
    static const IBigNumber _obj##_bn_interface = { \
   	INTERFACE_HEADER(_obj, IBigNumber, _localstruct) \
饶先宏's avatar
饶先宏 已提交
142 143
        _obj##_bn_GetWidth, \
        _obj##_bn_SetWidth, \
饶先宏's avatar
饶先宏 已提交
144 145 146 147 148 149 150
        _obj##_bn_GetInt, \
        _obj##_bn_GetInt64, \
        _obj##_bn_GetStr, \
        _obj##_bn_AssignStr, \
        _obj##_bn_AssignInt, \
        _obj##_bn_AssignInt64, \
        _obj##_bn_Assign, \
饶先宏's avatar
饶先宏 已提交
151 152
        _obj##_bn_AssignSub, \
        _obj##_bn_Bind, \
饶先宏's avatar
饶先宏 已提交
153
        _obj##_bn_Abs, \
饶先宏's avatar
饶先宏 已提交
154 155 156 157 158 159 160 161 162 163 164
        _obj##_bn_Neg, \
        _obj##_bn_AddInt, \
        _obj##_bn_Add, \
        _obj##_bn_SubInt, \
        _obj##_bn_Sub, \
        _obj##_bn_MulInt, \
        _obj##_bn_Mul, \
        _obj##_bn_DivInt, \
        _obj##_bn_Div, \
        _obj##_bn_SHL, \
        _obj##_bn_SHR, \
饶先宏's avatar
饶先宏 已提交
165 166
        _obj##_bn_SAL, \
        _obj##_bn_SAR, \
饶先宏's avatar
饶先宏 已提交
167 168 169 170
        _obj##_bn_Not, \
        _obj##_bn_uAnd, \
        _obj##_bn_uOr, \
        _obj##_bn_uXor, \
饶先宏's avatar
饶先宏 已提交
171 172
        _obj##_bn_And, \
        _obj##_bn_Or, \
饶先宏's avatar
饶先宏 已提交
173
        _obj##_bn_Xor, \
饶先宏's avatar
饶先宏 已提交
174 175 176 177 178 179 180
        _obj##_bn_IsZero, \
        _obj##_bn_IsNeg, \
        _obj##_bn_IsEQ, \
        _obj##_bn_IsLE, \
        _obj##_bn_IsLT \
    };

饶先宏's avatar
饶先宏 已提交
181 182

DEFINE_GUID(CLSID_BIGINTEGER, 0xabde0235, 0x8f00, 0x4f30, 0x92, 0xbf, 0x95, 0x2e, 0x35, 0x8b, 0x1a, 0xeb);
饶先宏's avatar
饶先宏 已提交
183
DEFINE_GUID(PARAMID_BIGINTEGERWIDTH, 0xb3a21034, 0x27d5, 0x4e09, 0xba, 0xfd, 0x2, 0xeb, 0x0, 0xfc, 0x28, 0xfb);
饶先宏's avatar
饶先宏 已提交
184

饶先宏's avatar
饶先宏 已提交
185
IBigNumber** bigintegerCreate(int width);
饶先宏's avatar
饶先宏 已提交
186

饶先宏's avatar
饶先宏 已提交
187 188 189 190 191 192 193
#endif /* _ASMLANGUAGE */

#ifdef __cplusplus
}
#endif

#endif /* __BIGNUMBER_H */