📄 sc_unsigned.h
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_unsigned.h -- Arbitrary precision unsigned arithmetic. This file includes the definitions of sc_unsigned_bitref, sc_unsigned_subref, and sc_unsigned classes. The first two classes are proxy classes to reference one bit and a range of bits of a sc_unsigned number, respectively. An sc_signed number has the sign-magnitude representation internally. However, its interface guarantees a 2's-complement representation. The sign-magnitude representation is chosen because of its efficiency: The sc_signed and sc_unsigned types are optimized for arithmetic rather than bitwise operations. For arithmetic operations, the sign-magnitude representation performs better. It is also important to note that an sc_unsigned number with n bits is equivalent to an sc_signed non-negative number with n + 1 bits. The implementations of sc_signed and sc_unsigned classes are almost identical: Most of the member and friend functions are defined in sc_nbcommon.cpp and sc_nbfriends.cpp so that they can be shared by both of these classes. These functions are chosed by defining a few macros before including them such as IF_SC_SIGNED and CLASS_TYPE. Our implementation choices are mostly dictated by performance considerations in that we tried to provide the most efficient sc_signed and sc_unsigned types without compromising their interface. For the behavior of operators, we have two semantics: the old and new. The most important difference between these two semantics is that the old semantics is closer to C/C++ semantics in that the result type of a binary operator on unsigned and signed arguments is unsigned; the new semantics, on the other hand, requires the result type be signed. The new semantics is required by the VSIA C/C++ data types standard. We have implemented the new semantics. Original Author: Ali Dasdan, Synopsys, Inc. *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: *****************************************************************************/// $Log: sc_unsigned.h,v $// Revision 1.1.1.1 2006/12/15 20:31:36 acg// SystemC 2.2//// Revision 1.4 2006/03/13 20:25:27 acg// Andy Goodrich: Addition of function declarations, e.g., xor_signed_friend()// to keep gcc 4.x happy.//// Revision 1.3 2006/01/13 18:49:32 acg// Added $Log command so that CVS check in comments are reproduced in the// source.//#ifndef SC_UNSIGNED_H#define SC_UNSIGNED_H#include "sysc/kernel/sc_object.h"#include "sysc/datatypes/misc/sc_value_base.h"#include "sysc/utils/sc_iostream.h"#include "sysc/utils/sc_temporary.h"#include "sysc/datatypes/int/sc_length_param.h"#include "sysc/datatypes/int/sc_nbdefs.h"#include "sysc/datatypes/int/sc_nbutils.h"#include "sysc/datatypes/int/sc_nbexterns.h"#include "sysc/utils/sc_temporary.h"namespace sc_dt{// classes defined in this moduleclass sc_unsigned_bitref_r;class sc_unsigned_bitref;class sc_unsigned_subref_r;class sc_unsigned_subref;class sc_concatref;class sc_unsigned;// forward class declarationsclass sc_bv_base;class sc_lv_base;class sc_int_base;class sc_uint_base;class sc_int_subref_r;class sc_uint_subref_r;class sc_signed;class sc_signed_subref_r;class sc_fxval;class sc_fxval_fast;class sc_fxnum;class sc_fxnum_fast;// Helper function declarionsint compare_unsigned(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd, small_type if_u_signed, small_type if_v_signed);sc_unsigned add_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd);sc_unsigned sub_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd);sc_unsigned mul_unsigned_friend(small_type s, int unb, int und, const sc_digit *ud, int vnb, int vnd, const sc_digit *vd);sc_unsigned div_unsigned_friend(small_type s, int unb, int und, const sc_digit *ud, int vnb, int vnd, const sc_digit *vd);sc_unsigned mod_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, int vnb, int vnd, const sc_digit *vd);sc_unsigned and_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd);sc_unsigned or_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd);sc_unsigned xor_unsigned_friend(small_type us, int unb, int und, const sc_digit *ud, small_type vs, int vnb, int vnd, const sc_digit *vd);// friend operator declarations // ARITHMETIC OPERATORS: // ADDition operators: sc_signed operator + (const sc_unsigned& u, const sc_signed& v); sc_signed operator + (const sc_signed& u, const sc_unsigned& v); sc_unsigned operator + (const sc_unsigned& u, const sc_unsigned& v); sc_signed operator + (const sc_unsigned& u, int64 v); sc_unsigned operator + (const sc_unsigned& u, uint64 v); sc_signed operator + (const sc_unsigned& u, long v); sc_unsigned operator + (const sc_unsigned& u, unsigned long v); sc_signed operator + (const sc_unsigned& u, int v); inline sc_unsigned operator + (const sc_unsigned& u, unsigned int v); sc_signed operator + (int64 u, const sc_unsigned& v); sc_unsigned operator + (uint64 u, const sc_unsigned& v); sc_signed operator + (long u, const sc_unsigned& v); sc_unsigned operator + (unsigned long u, const sc_unsigned& v); sc_signed operator + (int u, const sc_unsigned& v); inline sc_unsigned operator + (unsigned int u, const sc_unsigned& v); sc_unsigned operator + (const sc_unsigned& u, const sc_uint_base& v); sc_signed operator + (const sc_unsigned& u, const sc_int_base& v); sc_unsigned operator + (const sc_uint_base& u, const sc_unsigned& v); sc_signed operator + (const sc_int_base& u, const sc_unsigned& v); // SUBtraction operators: sc_signed operator - (const sc_unsigned& u, const sc_signed& v); sc_signed operator - (const sc_signed& u, const sc_unsigned& v); sc_signed operator - (const sc_unsigned& u, const sc_unsigned& v); sc_signed operator - (const sc_unsigned& u, int64 v); sc_signed operator - (const sc_unsigned& u, uint64 v); sc_signed operator - (const sc_unsigned& u, long v); sc_signed operator - (const sc_unsigned& u, unsigned long v); sc_signed operator - (const sc_unsigned& u, int v); sc_signed operator - (const sc_unsigned& u, unsigned int v); sc_signed operator - (int64 u, const sc_unsigned& v); sc_signed operator - (uint64 u, const sc_unsigned& v); sc_signed operator - (long u, const sc_unsigned& v); sc_signed operator - (unsigned long u, const sc_unsigned& v); sc_signed operator - (int u, const sc_unsigned& v); sc_signed operator - (unsigned int u, const sc_unsigned& v); sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v); sc_signed operator - (const sc_unsigned& u, const sc_int_base& v); sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v); sc_signed operator - (const sc_int_base& u, const sc_unsigned& v); // MULtiplication operators: sc_signed operator * (const sc_unsigned& u, const sc_signed& v); sc_signed operator * (const sc_signed& u, const sc_unsigned& v); sc_unsigned operator * (const sc_unsigned& u, const sc_unsigned& v); sc_signed operator * (const sc_unsigned& u, int64 v); sc_unsigned operator * (const sc_unsigned& u, uint64 v); sc_signed operator * (const sc_unsigned& u, long v); sc_unsigned operator * (const sc_unsigned& u, unsigned long v); sc_signed operator * (const sc_unsigned& u, int v); inline sc_unsigned operator * (const sc_unsigned& u, unsigned int v); sc_signed operator * (int64 u, const sc_unsigned& v); sc_unsigned operator * (uint64 u, const sc_unsigned& v); sc_signed operator * (long u, const sc_unsigned& v); sc_unsigned operator * (unsigned long u, const sc_unsigned& v); sc_signed operator * (int u, const sc_unsigned& v); inline sc_unsigned operator * (unsigned int u, const sc_unsigned& v); sc_unsigned operator * (const sc_unsigned& u, const sc_uint_base& v); sc_signed operator * (const sc_unsigned& u, const sc_int_base& v); sc_unsigned operator * (const sc_uint_base& u, const sc_unsigned& v); sc_signed operator * (const sc_int_base& u, const sc_unsigned& v); // DIVision operators: sc_signed operator / (const sc_unsigned& u, const sc_signed& v); sc_signed operator / (const sc_signed& u, const sc_unsigned& v); sc_unsigned operator / (const sc_unsigned& u, const sc_unsigned& v); sc_signed operator / (const sc_unsigned& u, int64 v); sc_unsigned operator / (const sc_unsigned& u, uint64 v); sc_signed operator / (const sc_unsigned& u, long v); sc_unsigned operator / (const sc_unsigned& u, unsigned long v); sc_signed operator / (const sc_unsigned& u, int v); inline sc_unsigned operator / (const sc_unsigned& u, unsigned int v); sc_signed operator / (int64 u, const sc_unsigned& v); sc_unsigned operator / (uint64 u, const sc_unsigned& v); sc_signed operator / (long u, const sc_unsigned& v); sc_unsigned operator / (unsigned long u, const sc_unsigned& v); sc_signed operator / (int u, const sc_unsigned& v); inline sc_unsigned operator / (unsigned int u, const sc_unsigned& v); sc_unsigned operator / (const sc_unsigned& u, const sc_uint_base& v); sc_signed operator / (const sc_unsigned& u, const sc_int_base& v); sc_unsigned operator / (const sc_uint_base& u, const sc_unsigned& v); sc_signed operator / (const sc_int_base& u, const sc_unsigned& v); // MODulo operators: sc_signed operator % (const sc_unsigned& u, const sc_signed& v); sc_signed operator % (const sc_signed& u, const sc_unsigned& v); sc_unsigned operator % (const sc_unsigned& u, const sc_unsigned& v); sc_signed operator % (const sc_unsigned& u, int64 v);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -