bignumber.h 7.1 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 52
/*
** 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
    int (*GetBitsCount)(HOBJECT object);
饶先宏's avatar
饶先宏 已提交
53
    int (*SetBitsCount)(HOBJECT object, int count);
饶先宏's avatar
饶先宏 已提交
54 55 56
    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
饶先宏 已提交
57

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

    int (*Bind)(HOBJECT object, HOBJECT src, int width);
饶先宏's avatar
饶先宏 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

    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
饶先宏 已提交
80 81 82 83
    int (*Not)(HOBJECT object);
    int (*uAnd)(HOBJECT object);
    int (*uOr)(HOBJECT object);
    int (*uXor)(HOBJECT object);
饶先宏's avatar
饶先宏 已提交
84 85
    int (*And)(HOBJECT object, HOBJECT src);
    int (*Or)(HOBJECT object, HOBJECT src);  
饶先宏's avatar
饶先宏 已提交
86
    int (*Xor)(HOBJECT object, HOBJECT src);
饶先宏's avatar
饶先宏 已提交
87 88 89 90 91 92 93 94

    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
饶先宏 已提交
95 96 97 98 99
#define BIGNUMBER_VARDECLARE
#define BIGNUMBER_VARINIT(_objptr, _sid)

#define BIGNUMBER_FUNCDECLARE(_obj, _clsid, _localstruct) \
    static int _obj##_bn_GetBitsCount(HOBJECT object); \
饶先宏's avatar
饶先宏 已提交
100
    static int _obj##_bn_SetBitsCount(HOBJECT object, int count); \
饶先宏's avatar
饶先宏 已提交
101 102 103 104
    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
饶先宏 已提交
105 106
    static int _obj##_bn_AssignInt(HOBJECT object, int value); \
    static int _obj##_bn_AssignInt64(HOBJECT object, long long value); \
饶先宏's avatar
饶先宏 已提交
107
    static int _obj##_bn_Assign(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
108 109
    static int _obj##_bn_AssignSub(HOBJECT object, HOBJECT src, int from, int width); \
    static int _obj##_bn_Bind(HOBJECT object, HOBJECT src, int width); \
饶先宏's avatar
饶先宏 已提交
110 111 112 113 114 115 116 117 118 119 120
    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
饶先宏 已提交
121 122 123 124
    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
饶先宏 已提交
125 126
    static int _obj##_bn_And(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_Or(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
127
    static int _obj##_bn_Xor(HOBJECT object, HOBJECT src); \
饶先宏's avatar
饶先宏 已提交
128 129 130 131 132 133 134 135
    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) \
        _obj##_bn_GetBitsCount, \
饶先宏's avatar
饶先宏 已提交
136
        _obj##_bn_SetBitsCount, \
饶先宏's avatar
饶先宏 已提交
137 138 139 140 141 142 143
        _obj##_bn_GetInt, \
        _obj##_bn_GetInt64, \
        _obj##_bn_GetStr, \
        _obj##_bn_AssignStr, \
        _obj##_bn_AssignInt, \
        _obj##_bn_AssignInt64, \
        _obj##_bn_Assign, \
饶先宏's avatar
饶先宏 已提交
144 145
        _obj##_bn_AssignSub, \
        _obj##_bn_Bind, \
饶先宏's avatar
饶先宏 已提交
146 147 148 149 150 151 152 153 154 155 156
        _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
饶先宏 已提交
157 158 159 160
        _obj##_bn_Not, \
        _obj##_bn_uAnd, \
        _obj##_bn_uOr, \
        _obj##_bn_uXor, \
饶先宏's avatar
饶先宏 已提交
161 162
        _obj##_bn_And, \
        _obj##_bn_Or, \
饶先宏's avatar
饶先宏 已提交
163
        _obj##_bn_Xor, \
饶先宏's avatar
饶先宏 已提交
164 165 166 167 168 169 170
        _obj##_bn_IsZero, \
        _obj##_bn_IsNeg, \
        _obj##_bn_IsEQ, \
        _obj##_bn_IsLE, \
        _obj##_bn_IsLT \
    };

饶先宏's avatar
饶先宏 已提交
171 172

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

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

饶先宏's avatar
饶先宏 已提交
177 178 179 180 181 182 183
#endif /* _ASMLANGUAGE */

#ifdef __cplusplus
}
#endif

#endif /* __BIGNUMBER_H */