bignumber.h 6.3 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/*
** 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);

    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 strlen);

    int (*AssignStr)(HOBJECT object, const char * str);
    int (*AssignInt)(HOBJECT object, int value);
    int (*AssignInt64)(HOBJECT object, long long value);
    int (*AssignFloat)(HOBJECT object, float value);
    int (*AssignDouble)(HOBJECT object, double value);
    int (*Assign)(HOBJECT object, HOBJECT src);

    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);

    int (*And)(HOBJECT object, HOBJECT src);
    int (*Or)(HOBJECT object, HOBJECT src);  

    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;

#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 strlen); \
    static int _obj##_bn_AssignStr(HOBJECT object, const char* str); \
    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_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); \
    static int _obj##_bn_And(HOBJECT object, HOBJECT src); \
    static int _obj##_bn_Or(HOBJECT object, HOBJECT src); \
    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, \
        _obj##_bn_GetInt, \
        _obj##_bn_GetInt64, \
        _obj##_bn_GetFloat, \
        _obj##_bn_GetDouble, \
        _obj##_bn_GetStr, \
        _obj##_bn_AssignStr, \
        _obj##_bn_AssignInt, \
        _obj##_bn_AssignInt64, \
        _obj##_bn_AssignFloat, \
        _obj##_bn_AssignDouble, \
        _obj##_bn_Assign, \
        _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, \
        _obj##_bn_And, \
        _obj##_bn_Or, \
        _obj##_bn_IsZero, \
        _obj##_bn_IsNeg, \
        _obj##_bn_IsEQ, \
        _obj##_bn_IsLE, \
        _obj##_bn_IsLT \
    };

#endif /* _ASMLANGUAGE */

#ifdef __cplusplus
}
#endif

#endif /* __BIGNUMBER_H */