112853Sgabeblack@google.com/*****************************************************************************
212853Sgabeblack@google.com
312853Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412853Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512853Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612853Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712853Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812853Sgabeblack@google.com  License.  You may obtain a copy of the License at
912853Sgabeblack@google.com
1012853Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112853Sgabeblack@google.com
1212853Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312853Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412853Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512853Sgabeblack@google.com  implied.  See the License for the specific language governing
1612853Sgabeblack@google.com  permissions and limitations under the License.
1712853Sgabeblack@google.com
1812853Sgabeblack@google.com *****************************************************************************/
1912853Sgabeblack@google.com
2012853Sgabeblack@google.com/*****************************************************************************
2112853Sgabeblack@google.com
2212853Sgabeblack@google.com  sc_unsigned.h -- Arbitrary precision unsigned arithmetic.
2312853Sgabeblack@google.com
2412853Sgabeblack@google.com    This file includes the definitions of sc_unsigned_bitref,
2512853Sgabeblack@google.com    sc_unsigned_subref, and sc_unsigned classes. The first two classes
2612853Sgabeblack@google.com    are proxy classes to reference one bit and a range of bits of a
2712853Sgabeblack@google.com    sc_unsigned number, respectively.
2812853Sgabeblack@google.com
2912853Sgabeblack@google.com    An sc_signed number has the sign-magnitude representation
3012853Sgabeblack@google.com    internally. However, its interface guarantees a 2's-complement
3112853Sgabeblack@google.com    representation. The sign-magnitude representation is chosen
3212853Sgabeblack@google.com    because of its efficiency: The sc_signed and sc_unsigned types are
3312853Sgabeblack@google.com    optimized for arithmetic rather than bitwise operations. For
3412853Sgabeblack@google.com    arithmetic operations, the sign-magnitude representation performs
3512853Sgabeblack@google.com    better.
3612853Sgabeblack@google.com
3712853Sgabeblack@google.com    It is also important to note that an sc_unsigned number with n
3812853Sgabeblack@google.com    bits is equivalent to an sc_signed non-negative number with n + 1
3912853Sgabeblack@google.com    bits.
4012853Sgabeblack@google.com
4112853Sgabeblack@google.com    The implementations of sc_signed and sc_unsigned classes are
4212853Sgabeblack@google.com    almost identical: Most of the member and friend functions are
4312853Sgabeblack@google.com    defined in sc_nbcommon.cpp and sc_nbfriends.cpp so that they can
4412853Sgabeblack@google.com    be shared by both of these classes. These functions are chosed by
4512853Sgabeblack@google.com    defining a few macros before including them such as IF_SC_SIGNED
4612853Sgabeblack@google.com    and CLASS_TYPE. Our implementation choices are mostly dictated by
4712853Sgabeblack@google.com    performance considerations in that we tried to provide the most
4812853Sgabeblack@google.com    efficient sc_signed and sc_unsigned types without compromising
4912853Sgabeblack@google.com    their interface.
5012853Sgabeblack@google.com
5112853Sgabeblack@google.com    For the behavior of operators, we have two semantics: the old and
5212853Sgabeblack@google.com    new. The most important difference between these two semantics is
5312853Sgabeblack@google.com    that the old semantics is closer to C/C++ semantics in that the
5412853Sgabeblack@google.com    result type of a binary operator on unsigned and signed arguments
5512853Sgabeblack@google.com    is unsigned; the new semantics, on the other hand, requires the
5612853Sgabeblack@google.com    result type be signed. The new semantics is required by the VSIA
5712853Sgabeblack@google.com    C/C++ data types standard. We have implemented the new semantics.
5812853Sgabeblack@google.com
5912853Sgabeblack@google.com  Original Author: Ali Dasdan, Synopsys, Inc.
6012853Sgabeblack@google.com
6112853Sgabeblack@google.com *****************************************************************************/
6212853Sgabeblack@google.com
6312853Sgabeblack@google.com/*****************************************************************************
6412853Sgabeblack@google.com
6512853Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
6612853Sgabeblack@google.com  changes you are making here.
6712853Sgabeblack@google.com
6812853Sgabeblack@google.com      Name, Affiliation, Date:
6912853Sgabeblack@google.com  Description of Modification:
7012853Sgabeblack@google.com
7112853Sgabeblack@google.com *****************************************************************************/
7212853Sgabeblack@google.com
7312853Sgabeblack@google.com// $Log: sc_unsigned.h,v $
7412853Sgabeblack@google.com// Revision 1.4  2011/08/24 22:05:46  acg
7512853Sgabeblack@google.com//  Torsten Maehne: initialization changes to remove warnings.
7612853Sgabeblack@google.com//
7712853Sgabeblack@google.com// Revision 1.3  2011/02/18 20:19:15  acg
7812853Sgabeblack@google.com//  Andy Goodrich: updating Copyright notice.
7912853Sgabeblack@google.com//
8012853Sgabeblack@google.com// Revision 1.2  2009/02/28 00:26:26  acg
8112853Sgabeblack@google.com//  Andy Goodrich: bug fixes.
8212853Sgabeblack@google.com//
8312853Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:20:05  acg
8412853Sgabeblack@google.com// SystemC 2.3
8512853Sgabeblack@google.com//
8612853Sgabeblack@google.com// Revision 1.5  2006/05/08 17:50:02  acg
8712853Sgabeblack@google.com//   Andy Goodrich: Added David Long's declarations for friend operators,
8812853Sgabeblack@google.com//   functions, and methods, to keep the Microsoft compiler happy.
8912853Sgabeblack@google.com//
9012853Sgabeblack@google.com// Revision 1.4  2006/03/13 20:25:27  acg
9112853Sgabeblack@google.com//  Andy Goodrich: Addition of function declarations, e.g., xor_signed_friend()
9212853Sgabeblack@google.com//  to keep gcc 4.x happy.
9312853Sgabeblack@google.com//
9412853Sgabeblack@google.com// Revision 1.3  2006/01/13 18:49:32  acg
9512853Sgabeblack@google.com// Added $Log command so that CVS check in comments are reproduced in the
9612853Sgabeblack@google.com// source.
9712853Sgabeblack@google.com//
9812853Sgabeblack@google.com
9912853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_INT_SC_UNSIGNED_HH__
10012853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_INT_SC_UNSIGNED_HH__
10112853Sgabeblack@google.com
10212853Sgabeblack@google.com#include <iostream>
10312853Sgabeblack@google.com
10412853Sgabeblack@google.com#include "../misc/sc_value_base.hh"
10512853Sgabeblack@google.com#include "../sc_temporary.hh"
10612853Sgabeblack@google.com#include "sc_length_param.hh"
10712853Sgabeblack@google.com#include "sc_nbdefs.hh"
10812853Sgabeblack@google.com#include "sc_nbexterns.hh"
10912853Sgabeblack@google.com#include "sc_nbutils.hh"
11012853Sgabeblack@google.com
11112853Sgabeblack@google.comnamespace sc_dt
11212853Sgabeblack@google.com{
11312853Sgabeblack@google.com
11412853Sgabeblack@google.com// classes defined in this module
11512853Sgabeblack@google.comclass sc_unsigned_bitref_r;
11612853Sgabeblack@google.comclass sc_unsigned_bitref;
11712853Sgabeblack@google.comclass sc_unsigned_subref_r;
11812853Sgabeblack@google.comclass sc_unsigned_subref;
11912853Sgabeblack@google.comclass sc_concatref;
12012853Sgabeblack@google.comclass sc_unsigned;
12112853Sgabeblack@google.com
12212853Sgabeblack@google.com// forward class declarations
12312853Sgabeblack@google.comclass sc_bv_base;
12412853Sgabeblack@google.comclass sc_lv_base;
12512853Sgabeblack@google.comclass sc_int_base;
12612853Sgabeblack@google.comclass sc_uint_base;
12712853Sgabeblack@google.comclass sc_int_subref_r;
12812853Sgabeblack@google.comclass sc_uint_subref_r;
12912853Sgabeblack@google.comclass sc_signed;
13012853Sgabeblack@google.comclass sc_signed_subref_r;
13112853Sgabeblack@google.comclass sc_fxval;
13212853Sgabeblack@google.comclass sc_fxval_fast;
13312853Sgabeblack@google.comclass sc_fxnum;
13412853Sgabeblack@google.comclass sc_fxnum_fast;
13512853Sgabeblack@google.com
13612853Sgabeblack@google.com} // namespace sc_dt
13712853Sgabeblack@google.com
13812853Sgabeblack@google.com// extern template instantiations
13912853Sgabeblack@google.comnamespace sc_core
14012853Sgabeblack@google.com{
14112853Sgabeblack@google.com
14212853Sgabeblack@google.comextern template class sc_vpool<sc_dt::sc_unsigned_bitref>;
14312853Sgabeblack@google.comextern template class sc_vpool<sc_dt::sc_unsigned_subref>;
14412853Sgabeblack@google.comextern template class sc_vpool<sc_dt::sc_unsigned>;
14512853Sgabeblack@google.com
14612853Sgabeblack@google.com} // namespace sc_core
14712853Sgabeblack@google.com
14812853Sgabeblack@google.comnamespace sc_dt
14912853Sgabeblack@google.com{
15012853Sgabeblack@google.com
15112853Sgabeblack@google.com// Helper function declarions
15212853Sgabeblack@google.comint compare_unsigned(small_type us, int unb, int und, const sc_digit *ud,
15312853Sgabeblack@google.com                     small_type vs, int vnb, int vnd, const sc_digit *vd,
15412853Sgabeblack@google.com                     small_type if_u_signed=0, small_type if_v_signed=0);
15512853Sgabeblack@google.com
15612853Sgabeblack@google.comsc_unsigned add_unsigned_friend(
15712853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
15812853Sgabeblack@google.com        small_type vs, int vnb, int vnd, const sc_digit *vd);
15912853Sgabeblack@google.com
16012853Sgabeblack@google.comsc_unsigned sub_unsigned_friend(
16112853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
16212853Sgabeblack@google.com        small_type vs, int vnb, int vnd, const sc_digit *vd);
16312853Sgabeblack@google.com
16412853Sgabeblack@google.comsc_unsigned mul_unsigned_friend(
16512853Sgabeblack@google.com        small_type s, int unb, int und, const sc_digit *ud,
16612853Sgabeblack@google.com        int vnb, int vnd, const sc_digit *vd);
16712853Sgabeblack@google.com
16812853Sgabeblack@google.comsc_unsigned div_unsigned_friend(
16912853Sgabeblack@google.com        small_type s, int unb, int und, const sc_digit *ud,
17012853Sgabeblack@google.com        int vnb, int vnd, const sc_digit *vd);
17112853Sgabeblack@google.com
17212853Sgabeblack@google.comsc_unsigned mod_unsigned_friend(
17312853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
17412853Sgabeblack@google.com        int vnb, int vnd, const sc_digit *vd);
17512853Sgabeblack@google.com
17612853Sgabeblack@google.comsc_unsigned and_unsigned_friend(
17712853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
17812853Sgabeblack@google.com        small_type vs, int vnb, int vnd, const sc_digit *vd);
17912853Sgabeblack@google.com
18012853Sgabeblack@google.com
18112853Sgabeblack@google.comsc_unsigned or_unsigned_friend(
18212853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
18312853Sgabeblack@google.com        small_type vs, int vnb, int vnd, const sc_digit *vd);
18412853Sgabeblack@google.com
18512853Sgabeblack@google.comsc_unsigned xor_unsigned_friend(
18612853Sgabeblack@google.com        small_type us, int unb, int und, const sc_digit *ud,
18712853Sgabeblack@google.com        small_type vs, int vnb, int vnd, const sc_digit *vd);
18812853Sgabeblack@google.com
18912853Sgabeblack@google.com
19012853Sgabeblack@google.com/*
19112853Sgabeblack@google.com * friend operator declarations
19212853Sgabeblack@google.com */
19312853Sgabeblack@google.com
19412853Sgabeblack@google.com// ARITHMETIC OPERATORS:
19512853Sgabeblack@google.com
19612853Sgabeblack@google.com// ADDition operators:
19712853Sgabeblack@google.comsc_signed operator + (const sc_unsigned &u, const sc_signed &v);
19812853Sgabeblack@google.comsc_signed operator + (const sc_signed &u, const sc_unsigned &v);
19912853Sgabeblack@google.com
20012853Sgabeblack@google.comsc_unsigned operator + (const sc_unsigned &u, const sc_unsigned &v);
20112853Sgabeblack@google.comsc_signed operator + (const sc_unsigned &u, int64 v);
20212853Sgabeblack@google.comsc_unsigned operator + (const sc_unsigned &u, uint64 v);
20312853Sgabeblack@google.comsc_signed operator + (const sc_unsigned &u, long v);
20412853Sgabeblack@google.comsc_unsigned operator + (const sc_unsigned &u, unsigned long v);
20512853Sgabeblack@google.comsc_signed operator + (const sc_unsigned &u, int v);
20612853Sgabeblack@google.cominline sc_unsigned operator + (const sc_unsigned &u, unsigned int v);
20712853Sgabeblack@google.com
20812853Sgabeblack@google.comsc_signed operator + (int64 u, const sc_unsigned &v);
20912853Sgabeblack@google.comsc_unsigned operator + (uint64 u, const sc_unsigned &v);
21012853Sgabeblack@google.comsc_signed operator + (long u, const sc_unsigned &v);
21112853Sgabeblack@google.comsc_unsigned operator + (unsigned long u, const sc_unsigned &v);
21212853Sgabeblack@google.comsc_signed operator + (int u, const sc_unsigned &v);
21312853Sgabeblack@google.cominline sc_unsigned operator + (unsigned int u, const sc_unsigned &v);
21412853Sgabeblack@google.com
21512853Sgabeblack@google.comsc_unsigned operator + (const sc_unsigned &u, const sc_uint_base &v);
21612853Sgabeblack@google.comsc_signed operator + (const sc_unsigned &u, const sc_int_base &v);
21712853Sgabeblack@google.comsc_unsigned operator + (const sc_uint_base &u, const sc_unsigned &v);
21812853Sgabeblack@google.comsc_signed operator + (const sc_int_base &u, const sc_unsigned &v);
21912853Sgabeblack@google.com
22012853Sgabeblack@google.com// SUBtraction operators:
22112853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, const sc_signed &v);
22212853Sgabeblack@google.comsc_signed operator - (const sc_signed &u, const sc_unsigned &v);
22312853Sgabeblack@google.com
22412853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, const sc_unsigned &v);
22512853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, int64 v);
22612853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, uint64 v);
22712853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, long v);
22812853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, unsigned long v);
22912853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, int v);
23012853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, unsigned int v);
23112853Sgabeblack@google.com
23212853Sgabeblack@google.comsc_signed operator - (int64 u, const sc_unsigned &v);
23312853Sgabeblack@google.comsc_signed operator - (uint64 u, const sc_unsigned &v);
23412853Sgabeblack@google.comsc_signed operator - (long u, const sc_unsigned &v);
23512853Sgabeblack@google.comsc_signed operator - (unsigned long u, const sc_unsigned &v);
23612853Sgabeblack@google.comsc_signed operator - (int u, const sc_unsigned &v);
23712853Sgabeblack@google.comsc_signed operator - (unsigned int u, const sc_unsigned &v);
23812853Sgabeblack@google.com
23912853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, const sc_uint_base &v);
24012853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u, const sc_int_base &v);
24112853Sgabeblack@google.comsc_signed operator - (const sc_uint_base &u, const sc_unsigned &v);
24212853Sgabeblack@google.comsc_signed operator - (const sc_int_base &u, const sc_unsigned &v);
24312853Sgabeblack@google.com
24412853Sgabeblack@google.com// MULtiplication operators:
24512853Sgabeblack@google.comsc_signed operator * (const sc_unsigned &u, const sc_signed &v);
24612853Sgabeblack@google.comsc_signed operator * (const sc_signed &u, const sc_unsigned &v);
24712853Sgabeblack@google.com
24812853Sgabeblack@google.comsc_unsigned operator * (const sc_unsigned &u, const sc_unsigned &v);
24912853Sgabeblack@google.comsc_signed operator * (const sc_unsigned &u, int64 v);
25012853Sgabeblack@google.comsc_unsigned operator * (const sc_unsigned &u, uint64 v);
25112853Sgabeblack@google.comsc_signed operator * (const sc_unsigned &u, long v);
25212853Sgabeblack@google.comsc_unsigned operator * (const sc_unsigned &u, unsigned long v);
25312853Sgabeblack@google.comsc_signed operator * (const sc_unsigned &u, int v);
25412853Sgabeblack@google.cominline sc_unsigned operator * (const sc_unsigned &u, unsigned int v);
25512853Sgabeblack@google.com
25612853Sgabeblack@google.comsc_signed operator * (int64 u, const sc_unsigned &v);
25712853Sgabeblack@google.comsc_unsigned operator * (uint64 u, const sc_unsigned &v);
25812853Sgabeblack@google.comsc_signed operator * (long u, const sc_unsigned &v);
25912853Sgabeblack@google.comsc_unsigned operator * (unsigned long u, const sc_unsigned &v);
26012853Sgabeblack@google.comsc_signed operator * (int u, const sc_unsigned &v);
26112853Sgabeblack@google.cominline sc_unsigned operator * (unsigned int u, const sc_unsigned &v);
26212853Sgabeblack@google.com
26312853Sgabeblack@google.comsc_unsigned operator * (const sc_unsigned &u, const sc_uint_base &v);
26412853Sgabeblack@google.comsc_signed operator * (const sc_unsigned &u, const sc_int_base &v);
26512853Sgabeblack@google.comsc_unsigned operator * (const sc_uint_base &u, const sc_unsigned &v);
26612853Sgabeblack@google.comsc_signed operator * (const sc_int_base &u, const sc_unsigned &v);
26712853Sgabeblack@google.com
26812853Sgabeblack@google.com// DIVision operators:
26912853Sgabeblack@google.comsc_signed operator / (const sc_unsigned &u, const sc_signed &v);
27012853Sgabeblack@google.comsc_signed operator / (const sc_signed &u, const sc_unsigned &v);
27112853Sgabeblack@google.com
27212853Sgabeblack@google.comsc_unsigned operator / (const sc_unsigned &u, const sc_unsigned &v);
27312853Sgabeblack@google.comsc_signed operator / (const sc_unsigned &u, int64 v);
27412853Sgabeblack@google.comsc_unsigned operator / (const sc_unsigned &u, uint64 v);
27512853Sgabeblack@google.comsc_signed operator / (const sc_unsigned &u, long v);
27612853Sgabeblack@google.comsc_unsigned operator / (const sc_unsigned &u, unsigned long v);
27712853Sgabeblack@google.comsc_signed operator / (const sc_unsigned &u, int v);
27812853Sgabeblack@google.cominline sc_unsigned operator / (const sc_unsigned &u, unsigned int v);
27912853Sgabeblack@google.com
28012853Sgabeblack@google.comsc_signed operator / (int64 u, const sc_unsigned &v);
28112853Sgabeblack@google.comsc_unsigned operator / (uint64 u, const sc_unsigned &v);
28212853Sgabeblack@google.comsc_signed operator / (long u, const sc_unsigned &v);
28312853Sgabeblack@google.comsc_unsigned operator / (unsigned long u, const sc_unsigned &v);
28412853Sgabeblack@google.comsc_signed operator / (int u, const sc_unsigned &v);
28512853Sgabeblack@google.cominline sc_unsigned operator / (unsigned int u, const sc_unsigned &v);
28612853Sgabeblack@google.com
28712853Sgabeblack@google.comsc_unsigned operator / (const sc_unsigned &u, const sc_uint_base &v);
28812853Sgabeblack@google.comsc_signed operator / (const sc_unsigned &u, const sc_int_base &v);
28912853Sgabeblack@google.comsc_unsigned operator / (const sc_uint_base &u, const sc_unsigned &v);
29012853Sgabeblack@google.comsc_signed operator / (const sc_int_base &u, const sc_unsigned &v);
29112853Sgabeblack@google.com
29212853Sgabeblack@google.com// MODulo operators:
29312853Sgabeblack@google.comsc_signed operator % (const sc_unsigned &u, const sc_signed &v);
29412853Sgabeblack@google.comsc_signed operator % (const sc_signed &u, const sc_unsigned &v);
29512853Sgabeblack@google.com
29612853Sgabeblack@google.comsc_unsigned operator % (const sc_unsigned &u, const sc_unsigned &v);
29712853Sgabeblack@google.comsc_signed operator % (const sc_unsigned &u, int64 v);
29812853Sgabeblack@google.comsc_unsigned operator % (const sc_unsigned &u, uint64 v);
29912853Sgabeblack@google.comsc_signed operator % (const sc_unsigned &u, long v);
30012853Sgabeblack@google.comsc_unsigned operator % (const sc_unsigned &u, unsigned long v);
30112853Sgabeblack@google.comsc_signed operator % (const sc_unsigned &u, int v);
30212853Sgabeblack@google.cominline sc_unsigned operator % (const sc_unsigned &u, unsigned int v);
30312853Sgabeblack@google.com
30412853Sgabeblack@google.comsc_signed operator % (int64 u, const sc_unsigned &v);
30512853Sgabeblack@google.comsc_unsigned operator % (uint64 u, const sc_unsigned &v);
30612853Sgabeblack@google.comsc_signed operator % (long u, const sc_unsigned &v);
30712853Sgabeblack@google.comsc_unsigned operator % (unsigned long u, const sc_unsigned &v);
30812853Sgabeblack@google.comsc_signed operator % (int u, const sc_unsigned &v);
30912853Sgabeblack@google.cominline sc_unsigned operator % (unsigned int u, const sc_unsigned &v);
31012853Sgabeblack@google.com
31112853Sgabeblack@google.comsc_unsigned operator % (const sc_unsigned &u, const sc_uint_base &v);
31212853Sgabeblack@google.comsc_signed operator % (const sc_unsigned &u, const sc_int_base &v);
31312853Sgabeblack@google.comsc_unsigned operator % (const sc_uint_base &u, const sc_unsigned &v);
31412853Sgabeblack@google.comsc_signed operator % (const sc_int_base &u, const sc_unsigned &v);
31512853Sgabeblack@google.com
31612853Sgabeblack@google.com// BITWISE OPERATORS:
31712853Sgabeblack@google.com
31812853Sgabeblack@google.com// Bitwise AND operators:
31912853Sgabeblack@google.comsc_signed operator & (const sc_unsigned &u, const sc_signed &v);
32012853Sgabeblack@google.comsc_signed operator & (const sc_signed &u, const sc_unsigned &v);
32112853Sgabeblack@google.com
32212853Sgabeblack@google.comsc_unsigned operator & (const sc_unsigned &u, const sc_unsigned &v);
32312853Sgabeblack@google.comsc_signed operator & (const sc_unsigned &u, int64 v);
32412853Sgabeblack@google.comsc_unsigned operator & (const sc_unsigned &u, uint64 v);
32512853Sgabeblack@google.comsc_signed operator & (const sc_unsigned &u, long v);
32612853Sgabeblack@google.comsc_unsigned operator & (const sc_unsigned &u, unsigned long v);
32712853Sgabeblack@google.comsc_signed operator & (const sc_unsigned &u, int v);
32812853Sgabeblack@google.cominline sc_unsigned operator & (const sc_unsigned &u, unsigned int v);
32912853Sgabeblack@google.com
33012853Sgabeblack@google.comsc_signed operator & (int64 u, const sc_unsigned &v);
33112853Sgabeblack@google.comsc_unsigned operator & (uint64 u, const sc_unsigned &v);
33212853Sgabeblack@google.comsc_signed operator & (long u, const sc_unsigned &v);
33312853Sgabeblack@google.comsc_unsigned operator & (unsigned long u, const sc_unsigned &v);
33412853Sgabeblack@google.comsc_signed operator & (int u, const sc_unsigned &v);
33512853Sgabeblack@google.cominline sc_unsigned operator & (unsigned int u, const sc_unsigned &v);
33612853Sgabeblack@google.com
33712853Sgabeblack@google.comsc_unsigned operator & (const sc_unsigned &u, const sc_uint_base &v);
33812853Sgabeblack@google.comsc_signed operator & (const sc_unsigned &u, const sc_int_base &v);
33912853Sgabeblack@google.comsc_unsigned operator & (const sc_uint_base &u, const sc_unsigned &v);
34012853Sgabeblack@google.comsc_signed operator & (const sc_int_base &u, const sc_unsigned &v);
34112853Sgabeblack@google.com
34212853Sgabeblack@google.com// Bitwise OR operators:
34312853Sgabeblack@google.comsc_signed operator | (const sc_unsigned &u, const sc_signed &v);
34412853Sgabeblack@google.comsc_signed operator | (const sc_signed &u, const sc_unsigned &v);
34512853Sgabeblack@google.com
34612853Sgabeblack@google.comsc_unsigned operator | (const sc_unsigned &u, const sc_unsigned &v);
34712853Sgabeblack@google.comsc_signed operator | (const sc_unsigned &u, int64 v);
34812853Sgabeblack@google.comsc_unsigned operator | (const sc_unsigned &u, uint64 v);
34912853Sgabeblack@google.comsc_signed operator | (const sc_unsigned &u, long v);
35012853Sgabeblack@google.comsc_unsigned operator | (const sc_unsigned &u, unsigned long v);
35112853Sgabeblack@google.comsc_signed operator | (const sc_unsigned &u, int v);
35212853Sgabeblack@google.cominline sc_unsigned operator | (const sc_unsigned &u, unsigned int v);
35312853Sgabeblack@google.com
35412853Sgabeblack@google.comsc_signed operator | (int64 u, const sc_unsigned &v);
35512853Sgabeblack@google.comsc_unsigned operator | (uint64 u, const sc_unsigned &v);
35612853Sgabeblack@google.comsc_signed operator | (long u, const sc_unsigned &v);
35712853Sgabeblack@google.comsc_unsigned operator | (unsigned long u, const sc_unsigned &v);
35812853Sgabeblack@google.comsc_signed operator | (int u, const sc_unsigned &v);
35912853Sgabeblack@google.cominline sc_unsigned operator | (unsigned int u, const sc_unsigned &v);
36012853Sgabeblack@google.com
36112853Sgabeblack@google.comsc_unsigned operator | (const sc_unsigned &u, const sc_uint_base &v);
36212853Sgabeblack@google.comsc_signed operator | (const sc_unsigned &u, const sc_int_base &v);
36312853Sgabeblack@google.comsc_unsigned operator | (const sc_uint_base &u, const sc_unsigned &v);
36412853Sgabeblack@google.comsc_signed operator | (const sc_int_base &u, const sc_unsigned &v);
36512853Sgabeblack@google.com
36612853Sgabeblack@google.com// Bitwise XOR operators:
36712853Sgabeblack@google.comsc_signed operator ^ (const sc_unsigned &u, const sc_signed &v);
36812853Sgabeblack@google.comsc_signed operator ^ (const sc_signed &u, const sc_unsigned &v);
36912853Sgabeblack@google.com
37012853Sgabeblack@google.comsc_unsigned operator ^ (const sc_unsigned &u, const sc_unsigned &v);
37112853Sgabeblack@google.comsc_signed operator ^ (const sc_unsigned &u, int64 v);
37212853Sgabeblack@google.comsc_unsigned operator ^ (const sc_unsigned &u, uint64 v);
37312853Sgabeblack@google.comsc_signed operator ^ (const sc_unsigned &u, long v);
37412853Sgabeblack@google.comsc_unsigned operator ^ (const sc_unsigned &u, unsigned long v);
37512853Sgabeblack@google.comsc_signed operator ^ (const sc_unsigned &u, int v);
37612853Sgabeblack@google.cominline sc_unsigned operator ^ (const sc_unsigned &u, unsigned int v);
37712853Sgabeblack@google.com
37812853Sgabeblack@google.comsc_signed operator ^ (int64 u, const sc_unsigned &v);
37912853Sgabeblack@google.comsc_unsigned operator ^ (uint64 u, const sc_unsigned &v);
38012853Sgabeblack@google.comsc_signed operator ^ (long u, const sc_unsigned &v);
38112853Sgabeblack@google.comsc_unsigned operator ^ (unsigned long u, const sc_unsigned &v);
38212853Sgabeblack@google.comsc_signed operator ^ (int u, const sc_unsigned &v);
38312853Sgabeblack@google.cominline sc_unsigned operator ^ (unsigned int u, const sc_unsigned &v);
38412853Sgabeblack@google.com
38512853Sgabeblack@google.comsc_unsigned operator ^ (const sc_unsigned &u, const sc_uint_base &v);
38612853Sgabeblack@google.comsc_signed operator ^ (const sc_unsigned &u, const sc_int_base &v);
38712853Sgabeblack@google.comsc_unsigned operator ^ (const sc_uint_base &u, const sc_unsigned &v);
38812853Sgabeblack@google.comsc_signed operator ^ (const sc_int_base &u, const sc_unsigned &v);
38912853Sgabeblack@google.com
39012853Sgabeblack@google.com// SHIFT OPERATORS:
39112853Sgabeblack@google.com
39212853Sgabeblack@google.com// LEFT SHIFT operators:
39312853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, const sc_signed &v);
39412853Sgabeblack@google.comsc_signed operator << (const sc_signed &u, const sc_unsigned &v);
39512853Sgabeblack@google.com
39612853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, const sc_unsigned &v);
39712853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, int64 v);
39812853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, uint64 v);
39912853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, long v);
40012853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, unsigned long v);
40112853Sgabeblack@google.cominline sc_unsigned operator << (const sc_unsigned &u, int v);
40212853Sgabeblack@google.cominline sc_unsigned operator << (const sc_unsigned &u, unsigned int v);
40312853Sgabeblack@google.com
40412853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, const sc_uint_base &v);
40512853Sgabeblack@google.comsc_unsigned operator << (const sc_unsigned &u, const sc_int_base &v);
40612853Sgabeblack@google.com
40712853Sgabeblack@google.com// RIGHT SHIFT operators:
40812853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, const sc_signed &v);
40912853Sgabeblack@google.comsc_signed operator >> (const sc_signed &u, const sc_unsigned &v);
41012853Sgabeblack@google.com
41112853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, const sc_unsigned &v);
41212853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, int64 v);
41312853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, uint64 v);
41412853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, long v);
41512853Sgabeblack@google.comsc_unsigned operator >> (const sc_unsigned &u, unsigned long v);
41612853Sgabeblack@google.cominline sc_unsigned operator >> (const sc_unsigned &u, int v);
41712853Sgabeblack@google.cominline sc_unsigned operator >> (const sc_unsigned &u, unsigned int v);
41812853Sgabeblack@google.com
41912853Sgabeblack@google.comsc_unsigned operator >> ( const sc_unsigned &, const sc_uint_base &);
42012853Sgabeblack@google.comsc_unsigned operator >> ( const sc_unsigned&, const sc_int_base &);
42112853Sgabeblack@google.com
42212853Sgabeblack@google.com// Unary arithmetic operators
42312853Sgabeblack@google.comsc_unsigned operator + (const sc_unsigned &u);
42412853Sgabeblack@google.comsc_signed operator - (const sc_unsigned &u);
42512853Sgabeblack@google.com
42612853Sgabeblack@google.com// LOGICAL OPERATORS:
42712853Sgabeblack@google.com
42812853Sgabeblack@google.com// Logical EQUAL operators:
42912853Sgabeblack@google.combool operator == (const sc_unsigned &u, const sc_signed &v);
43012853Sgabeblack@google.combool operator == (const sc_signed &u, const sc_unsigned &v);
43112853Sgabeblack@google.com
43212853Sgabeblack@google.combool operator == (const sc_unsigned &u, const sc_unsigned &v);
43312853Sgabeblack@google.combool operator == (const sc_unsigned &u, int64 v);
43412853Sgabeblack@google.combool operator == (const sc_unsigned &u, uint64 v);
43512853Sgabeblack@google.combool operator == (const sc_unsigned &u, long v);
43612853Sgabeblack@google.combool operator == (const sc_unsigned &u, unsigned long v);
43712853Sgabeblack@google.cominline bool operator == (const sc_unsigned &u, int v);
43812853Sgabeblack@google.cominline bool operator == (const sc_unsigned &u, unsigned int v);
43912853Sgabeblack@google.com
44012853Sgabeblack@google.combool operator == (int64 u, const sc_unsigned &v);
44112853Sgabeblack@google.combool operator == (uint64 u, const sc_unsigned &v);
44212853Sgabeblack@google.combool operator == (long u, const sc_unsigned &v);
44312853Sgabeblack@google.combool operator == (unsigned long u, const sc_unsigned &v);
44412853Sgabeblack@google.cominline bool operator == (int u, const sc_unsigned &v);
44512853Sgabeblack@google.cominline bool operator == (unsigned int u, const sc_unsigned &v) ;
44612853Sgabeblack@google.com
44712853Sgabeblack@google.combool operator == (const sc_unsigned &u, const sc_uint_base &v);
44812853Sgabeblack@google.combool operator == (const sc_unsigned &u, const sc_int_base &v);
44912853Sgabeblack@google.combool operator == (const sc_uint_base &u, const sc_unsigned &v);
45012853Sgabeblack@google.combool operator == (const sc_int_base &u, const sc_unsigned &v);
45112853Sgabeblack@google.com
45212853Sgabeblack@google.com// Logical NOT_EQUAL operators:
45312853Sgabeblack@google.combool operator != (const sc_unsigned &u, const sc_signed &v);
45412853Sgabeblack@google.combool operator != (const sc_signed &u, const sc_unsigned &v);
45512853Sgabeblack@google.com
45612853Sgabeblack@google.combool operator != (const sc_unsigned &u, const sc_unsigned &v);
45712853Sgabeblack@google.combool operator != (const sc_unsigned &u, int64 v);
45812853Sgabeblack@google.combool operator != (const sc_unsigned &u, uint64 v);
45912853Sgabeblack@google.combool operator != (const sc_unsigned &u, long v);
46012853Sgabeblack@google.combool operator != (const sc_unsigned &u, unsigned long v);
46112853Sgabeblack@google.cominline bool operator != (const sc_unsigned &u, int v);
46212853Sgabeblack@google.cominline bool operator != (const sc_unsigned &u, unsigned int v);
46312853Sgabeblack@google.com
46412853Sgabeblack@google.combool operator != (int64 u, const sc_unsigned &v);
46512853Sgabeblack@google.combool operator != (uint64 u, const sc_unsigned &v);
46612853Sgabeblack@google.combool operator != (long u, const sc_unsigned &v);
46712853Sgabeblack@google.combool operator != (unsigned long u, const sc_unsigned &v);
46812853Sgabeblack@google.cominline bool operator != (int u, const sc_unsigned &v);
46912853Sgabeblack@google.cominline bool operator != (unsigned int u, const sc_unsigned &v);
47012853Sgabeblack@google.com
47112853Sgabeblack@google.combool operator != (const sc_unsigned &u, const sc_uint_base &v);
47212853Sgabeblack@google.combool operator != (const sc_unsigned &u, const sc_int_base &v);
47312853Sgabeblack@google.combool operator != (const sc_uint_base &u, const sc_unsigned &v);
47412853Sgabeblack@google.combool operator != (const sc_int_base &u, const sc_unsigned &v);
47512853Sgabeblack@google.com
47612853Sgabeblack@google.com// Logical LESS_THAN operators:
47712853Sgabeblack@google.combool operator < (const sc_unsigned &u, const sc_signed &v);
47812853Sgabeblack@google.combool operator < (const sc_signed &u, const sc_unsigned &v);
47912853Sgabeblack@google.com
48012853Sgabeblack@google.combool operator < (const sc_unsigned &u, const sc_unsigned &v);
48112853Sgabeblack@google.combool operator < (const sc_unsigned &u, int64 v);
48212853Sgabeblack@google.combool operator < (const sc_unsigned &u, uint64 v);
48312853Sgabeblack@google.combool operator < (const sc_unsigned &u, long v);
48412853Sgabeblack@google.combool operator < (const sc_unsigned &u, unsigned long v);
48512853Sgabeblack@google.cominline bool operator < (const sc_unsigned &u, int v);
48612853Sgabeblack@google.cominline bool operator < (const sc_unsigned &u, unsigned int v);
48712853Sgabeblack@google.com
48812853Sgabeblack@google.combool operator < (int64 u, const sc_unsigned &v);
48912853Sgabeblack@google.combool operator < (uint64 u, const sc_unsigned &v);
49012853Sgabeblack@google.combool operator < (long u, const sc_unsigned &v);
49112853Sgabeblack@google.combool operator < (unsigned long u, const sc_unsigned &v);
49212853Sgabeblack@google.cominline bool operator < (int u, const sc_unsigned &v);
49312853Sgabeblack@google.cominline bool operator < (unsigned int u, const sc_unsigned &v);
49412853Sgabeblack@google.com
49512853Sgabeblack@google.combool operator < (const sc_unsigned &u, const sc_uint_base &v);
49612853Sgabeblack@google.combool operator < (const sc_unsigned &u, const sc_int_base &v);
49712853Sgabeblack@google.combool operator < (const sc_uint_base &u, const sc_unsigned &v);
49812853Sgabeblack@google.combool operator < (const sc_int_base &u, const sc_unsigned &v);
49912853Sgabeblack@google.com
50012853Sgabeblack@google.com// Logical LESS_THAN_AND_EQUAL operators:
50112853Sgabeblack@google.combool operator <= (const sc_unsigned &u, const sc_signed &v);
50212853Sgabeblack@google.combool operator <= (const sc_signed &u, const sc_unsigned &v);
50312853Sgabeblack@google.com
50412853Sgabeblack@google.combool operator <= (const sc_unsigned &u, const sc_unsigned &v);
50512853Sgabeblack@google.combool operator <= (const sc_unsigned &u, int64 v);
50612853Sgabeblack@google.combool operator <= (const sc_unsigned &u, uint64 v);
50712853Sgabeblack@google.combool operator <= (const sc_unsigned &u, long v);
50812853Sgabeblack@google.combool operator <= (const sc_unsigned &u, unsigned long v);
50912853Sgabeblack@google.cominline bool operator <= (const sc_unsigned &u, int v);
51012853Sgabeblack@google.cominline bool operator <= (const sc_unsigned &u, unsigned int v);
51112853Sgabeblack@google.com
51212853Sgabeblack@google.combool operator <= (int64 u, const sc_unsigned &v);
51312853Sgabeblack@google.combool operator <= (uint64 u, const sc_unsigned &v);
51412853Sgabeblack@google.combool operator <= (long u, const sc_unsigned &v);
51512853Sgabeblack@google.combool operator <= (unsigned long u, const sc_unsigned &v);
51612853Sgabeblack@google.cominline bool operator <= (int u, const sc_unsigned &v);
51712853Sgabeblack@google.cominline bool operator <= (unsigned int u, const sc_unsigned &v);
51812853Sgabeblack@google.com
51912853Sgabeblack@google.combool operator <= (const sc_unsigned &u, const sc_uint_base &v);
52012853Sgabeblack@google.combool operator <= (const sc_unsigned &u, const sc_int_base &v);
52112853Sgabeblack@google.combool operator <= (const sc_uint_base &u, const sc_unsigned &v);
52212853Sgabeblack@google.combool operator <= (const sc_int_base &u, const sc_unsigned &v);
52312853Sgabeblack@google.com
52412853Sgabeblack@google.com// Logical GREATER_THAN operators:
52512853Sgabeblack@google.combool operator > (const sc_unsigned &u, const sc_signed &v);
52612853Sgabeblack@google.combool operator > (const sc_signed &u, const sc_unsigned &v);
52712853Sgabeblack@google.com
52812853Sgabeblack@google.combool operator > (const sc_unsigned &u, const sc_unsigned &v);
52912853Sgabeblack@google.combool operator > (const sc_unsigned &u, int64 v);
53012853Sgabeblack@google.combool operator > (const sc_unsigned &u, uint64 v);
53112853Sgabeblack@google.combool operator > (const sc_unsigned &u, long v);
53212853Sgabeblack@google.combool operator > (const sc_unsigned &u, unsigned long v);
53312853Sgabeblack@google.cominline bool operator > (const sc_unsigned &u, int v);
53412853Sgabeblack@google.cominline bool operator > (const sc_unsigned &u, unsigned int v);
53512853Sgabeblack@google.com
53612853Sgabeblack@google.combool operator > (int64 u, const sc_unsigned &v);
53712853Sgabeblack@google.combool operator > (uint64 u, const sc_unsigned &v);
53812853Sgabeblack@google.combool operator > (long u, const sc_unsigned &v);
53912853Sgabeblack@google.combool operator > (unsigned long u, const sc_unsigned &v);
54012853Sgabeblack@google.cominline bool operator > (int u, const sc_unsigned &v);
54112853Sgabeblack@google.cominline bool operator > (unsigned int u, const sc_unsigned &v);
54212853Sgabeblack@google.com
54312853Sgabeblack@google.combool operator > (const sc_unsigned &u, const sc_uint_base &v);
54412853Sgabeblack@google.combool operator > (const sc_unsigned &u, const sc_int_base &v);
54512853Sgabeblack@google.combool operator > (const sc_uint_base &u, const sc_unsigned &v);
54612853Sgabeblack@google.combool operator > (const sc_int_base &u, const sc_unsigned &v);
54712853Sgabeblack@google.com
54812853Sgabeblack@google.com// Logical GREATER_THAN_AND_EQUAL operators:
54912853Sgabeblack@google.combool operator >= (const sc_unsigned &u, const sc_signed &v);
55012853Sgabeblack@google.combool operator >= (const sc_signed &u, const sc_unsigned &v);
55112853Sgabeblack@google.com
55212853Sgabeblack@google.combool operator >= (const sc_unsigned &u, const sc_unsigned &v);
55312853Sgabeblack@google.combool operator >= (const sc_unsigned &u, int64 v);
55412853Sgabeblack@google.combool operator >= (const sc_unsigned &u, uint64 v);
55512853Sgabeblack@google.combool operator >= (const sc_unsigned &u, long v);
55612853Sgabeblack@google.combool operator >= (const sc_unsigned &u, unsigned long v);
55712853Sgabeblack@google.cominline bool operator >= (const sc_unsigned &u, int v);
55812853Sgabeblack@google.cominline bool operator >= (const sc_unsigned &u, unsigned int v);
55912853Sgabeblack@google.com
56012853Sgabeblack@google.combool operator >= (int64 u, const sc_unsigned &v);
56112853Sgabeblack@google.combool operator >= (uint64 u, const sc_unsigned &v);
56212853Sgabeblack@google.combool operator >= (long u, const sc_unsigned &v);
56312853Sgabeblack@google.combool operator >= (unsigned long u, const sc_unsigned &v);
56412853Sgabeblack@google.cominline bool operator >= (int u, const sc_unsigned &v);
56512853Sgabeblack@google.cominline bool operator >= (unsigned int u, const sc_unsigned &v);
56612853Sgabeblack@google.com
56712853Sgabeblack@google.combool operator >= (const sc_unsigned &u, const sc_uint_base &v);
56812853Sgabeblack@google.combool operator >= (const sc_unsigned &u, const sc_int_base &v);
56912853Sgabeblack@google.combool operator >= (const sc_uint_base &u, const sc_unsigned &v);
57012853Sgabeblack@google.combool operator >= (const sc_int_base &u, const sc_unsigned &v);
57112853Sgabeblack@google.com
57212853Sgabeblack@google.com// Bitwise NOT operator (unary).
57312853Sgabeblack@google.comsc_unsigned operator ~ (const sc_unsigned &u);
57412853Sgabeblack@google.com
57512853Sgabeblack@google.com// ----------------------------------------------------------------------------
57612853Sgabeblack@google.com//  CLASS : sc_unsigned_bitref_r
57712853Sgabeblack@google.com//
57812853Sgabeblack@google.com//  Proxy class for sc_unsigned bit selection (r-value only).
57912853Sgabeblack@google.com// ----------------------------------------------------------------------------
58012853Sgabeblack@google.com
58112853Sgabeblack@google.comclass sc_unsigned_bitref_r : public sc_value_base
58212853Sgabeblack@google.com{
58312853Sgabeblack@google.com    friend class sc_unsigned;
58412853Sgabeblack@google.com
58512853Sgabeblack@google.com  protected:
58612853Sgabeblack@google.com    // construction and initialization:
58712853Sgabeblack@google.com    sc_unsigned_bitref_r() : sc_value_base(), m_index(0), m_obj_p(0) {}
58812853Sgabeblack@google.com
58912853Sgabeblack@google.com    void
59012853Sgabeblack@google.com    initialize(const sc_unsigned *obj_p, int index_)
59112853Sgabeblack@google.com    {
59212853Sgabeblack@google.com        m_obj_p = const_cast<sc_unsigned *>(obj_p);
59312853Sgabeblack@google.com        m_index = index_;
59412853Sgabeblack@google.com    }
59512853Sgabeblack@google.com
59612853Sgabeblack@google.com  public:
59712853Sgabeblack@google.com    // destructor
59812853Sgabeblack@google.com    virtual ~sc_unsigned_bitref_r() {}
59912853Sgabeblack@google.com
60012853Sgabeblack@google.com    // copy constructor
60112853Sgabeblack@google.com    sc_unsigned_bitref_r(const sc_unsigned_bitref_r &a) :
60212853Sgabeblack@google.com        sc_value_base(a), m_index(a.m_index), m_obj_p(a.m_obj_p)
60312853Sgabeblack@google.com    {}
60412853Sgabeblack@google.com
60512853Sgabeblack@google.com    // capacity
60612853Sgabeblack@google.com    int length() const { return 1; }
60712853Sgabeblack@google.com
60812853Sgabeblack@google.com    // implicit conversion to bool
60912853Sgabeblack@google.com    operator uint64 () const;
61012853Sgabeblack@google.com    bool operator ! () const;
61112853Sgabeblack@google.com    bool operator ~ () const;
61212853Sgabeblack@google.com
61312853Sgabeblack@google.com    // explicit conversions
61412853Sgabeblack@google.com    uint64 value() const { return operator uint64(); }
61512853Sgabeblack@google.com    bool to_bool() const { return operator uint64(); }
61612853Sgabeblack@google.com
61712853Sgabeblack@google.com    // concatenation support
61812853Sgabeblack@google.com    virtual int
61912853Sgabeblack@google.com    concat_length(bool *xz_present_p) const
62012853Sgabeblack@google.com    {
62112853Sgabeblack@google.com        if (xz_present_p)
62212853Sgabeblack@google.com            *xz_present_p = false;
62312853Sgabeblack@google.com        return 1;
62412853Sgabeblack@google.com    }
62512853Sgabeblack@google.com    virtual uint64
62612853Sgabeblack@google.com    concat_get_uint64() const
62712853Sgabeblack@google.com    {
62812853Sgabeblack@google.com        return (uint64)operator uint64();
62912853Sgabeblack@google.com    }
63012853Sgabeblack@google.com    virtual bool
63112853Sgabeblack@google.com    concat_get_ctrl(sc_digit *dst_p, int low_i) const
63212853Sgabeblack@google.com    {
63312853Sgabeblack@google.com        int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
63412853Sgabeblack@google.com        int word_i = low_i / BITS_PER_DIGIT;
63512853Sgabeblack@google.com        dst_p[word_i] &= ~bit_mask;
63612853Sgabeblack@google.com        return false;
63712853Sgabeblack@google.com    }
63812853Sgabeblack@google.com    virtual bool
63912853Sgabeblack@google.com    concat_get_data(sc_digit *dst_p, int low_i) const
64012853Sgabeblack@google.com    {
64112853Sgabeblack@google.com        int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
64212853Sgabeblack@google.com        bool result; // True if non-zero.
64312853Sgabeblack@google.com        int word_i = low_i / BITS_PER_DIGIT;
64412853Sgabeblack@google.com        if (operator uint64())
64512853Sgabeblack@google.com        {
64612853Sgabeblack@google.com            dst_p[word_i] |= bit_mask;
64712853Sgabeblack@google.com            result = true;
64812853Sgabeblack@google.com        } else {
64912853Sgabeblack@google.com            dst_p[word_i] &= ~bit_mask;
65012853Sgabeblack@google.com            result = false;
65112853Sgabeblack@google.com        }
65212853Sgabeblack@google.com        return result;
65312853Sgabeblack@google.com    }
65412853Sgabeblack@google.com
65512853Sgabeblack@google.com    // other methods
65612853Sgabeblack@google.com    void print(::std::ostream &os=::std::cout) const { os << to_bool(); }
65712853Sgabeblack@google.com
65812853Sgabeblack@google.com  protected:
65912853Sgabeblack@google.com    int m_index;
66012853Sgabeblack@google.com    sc_unsigned *m_obj_p;
66112853Sgabeblack@google.com
66212853Sgabeblack@google.com  private:
66312853Sgabeblack@google.com    // Disabled
66412853Sgabeblack@google.com    const sc_unsigned_bitref_r &operator = (const sc_unsigned_bitref_r &);
66512853Sgabeblack@google.com};
66612853Sgabeblack@google.com
66712853Sgabeblack@google.cominline ::std::ostream &operator << (
66812853Sgabeblack@google.com        ::std::ostream &, const sc_unsigned_bitref_r &);
66912853Sgabeblack@google.com
67012853Sgabeblack@google.com
67112853Sgabeblack@google.com// ----------------------------------------------------------------------------
67212853Sgabeblack@google.com//  CLASS : sc_unsigned_bitref
67312853Sgabeblack@google.com//
67412853Sgabeblack@google.com//  Proxy class for sc_unsigned bit selection (r-value and l-value).
67512853Sgabeblack@google.com// ----------------------------------------------------------------------------
67612853Sgabeblack@google.com
67712853Sgabeblack@google.comclass sc_unsigned_bitref : public sc_unsigned_bitref_r
67812853Sgabeblack@google.com{
67912853Sgabeblack@google.com    friend class sc_unsigned;
68012853Sgabeblack@google.com    friend class sc_core::sc_vpool<sc_unsigned_bitref>;
68112853Sgabeblack@google.com
68212853Sgabeblack@google.com  protected: // construction
68312853Sgabeblack@google.com    sc_unsigned_bitref() : sc_unsigned_bitref_r() {}
68412853Sgabeblack@google.com
68512853Sgabeblack@google.com  public:
68612853Sgabeblack@google.com    // copy constructor
68712853Sgabeblack@google.com    sc_unsigned_bitref(const sc_unsigned_bitref &a) : sc_unsigned_bitref_r(a)
68812853Sgabeblack@google.com    {}
68912853Sgabeblack@google.com
69012853Sgabeblack@google.com    // assignment operators
69112853Sgabeblack@google.com    const sc_unsigned_bitref &operator = (const sc_unsigned_bitref_r &);
69212853Sgabeblack@google.com    const sc_unsigned_bitref &operator = (const sc_unsigned_bitref &);
69312853Sgabeblack@google.com    const sc_unsigned_bitref &operator = (bool);
69412853Sgabeblack@google.com
69512853Sgabeblack@google.com    const sc_unsigned_bitref &operator &= (bool);
69612853Sgabeblack@google.com    const sc_unsigned_bitref &operator |= (bool);
69712853Sgabeblack@google.com    const sc_unsigned_bitref &operator ^= (bool);
69812853Sgabeblack@google.com
69912853Sgabeblack@google.com    // concatenation methods
70012853Sgabeblack@google.com    virtual void concat_set(int64 src, int low_i);
70112853Sgabeblack@google.com    virtual void concat_set(const sc_signed &src, int low_i);
70212853Sgabeblack@google.com    virtual void concat_set(const sc_unsigned &src, int low_i);
70312853Sgabeblack@google.com    virtual void concat_set(uint64 src, int low_i);
70412853Sgabeblack@google.com
70512853Sgabeblack@google.com    // other methods
70612853Sgabeblack@google.com    void scan(::std::istream &is=::std::cin);
70712853Sgabeblack@google.com
70812853Sgabeblack@google.com  protected:
70912853Sgabeblack@google.com    static sc_core::sc_vpool<sc_unsigned_bitref> m_pool;
71012853Sgabeblack@google.com};
71112853Sgabeblack@google.com
71212853Sgabeblack@google.cominline ::std::istream &operator >> (::std::istream &, sc_unsigned_bitref &);
71312853Sgabeblack@google.com
71412853Sgabeblack@google.com
71512853Sgabeblack@google.com// ----------------------------------------------------------------------------
71612853Sgabeblack@google.com//  CLASS : sc_unsigned_subref_r
71712853Sgabeblack@google.com//
71812853Sgabeblack@google.com//  Proxy class for sc_unsigned part selection (r-value only).
71912853Sgabeblack@google.com// ----------------------------------------------------------------------------
72012853Sgabeblack@google.com
72112853Sgabeblack@google.comclass sc_unsigned_subref_r : public sc_value_base
72212853Sgabeblack@google.com{
72312853Sgabeblack@google.com    friend class sc_signed;
72412853Sgabeblack@google.com    friend class sc_unsigned;
72512853Sgabeblack@google.com    friend class sc_unsigned_signal;
72612853Sgabeblack@google.com
72712853Sgabeblack@google.com  protected:
72812853Sgabeblack@google.com    // constructor
72912853Sgabeblack@google.com    sc_unsigned_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
73012853Sgabeblack@google.com    {}
73112853Sgabeblack@google.com
73212853Sgabeblack@google.com    void
73312853Sgabeblack@google.com    initialize(const sc_unsigned *obj_p, int left_, int right_)
73412853Sgabeblack@google.com    {
73512853Sgabeblack@google.com        m_obj_p = const_cast<sc_unsigned *>(obj_p);
73612853Sgabeblack@google.com        m_left = left_;
73712853Sgabeblack@google.com        m_right = right_;
73812853Sgabeblack@google.com    }
73912853Sgabeblack@google.com
74012853Sgabeblack@google.com  public:
74112853Sgabeblack@google.com    // destructor
74212853Sgabeblack@google.com    virtual ~sc_unsigned_subref_r() {}
74312853Sgabeblack@google.com
74412853Sgabeblack@google.com    // copy constructor
74512853Sgabeblack@google.com    sc_unsigned_subref_r(const sc_unsigned_subref_r &a) :
74612853Sgabeblack@google.com            sc_value_base(a), m_left(a.m_left), m_obj_p(a.m_obj_p),
74712853Sgabeblack@google.com            m_right(a.m_right)
74812853Sgabeblack@google.com    {}
74912853Sgabeblack@google.com
75012853Sgabeblack@google.com    // capacity
75112853Sgabeblack@google.com    int
75212853Sgabeblack@google.com    length() const
75312853Sgabeblack@google.com    {
75412853Sgabeblack@google.com        if (m_left >= m_right)
75512853Sgabeblack@google.com            return m_left - m_right + 1;
75612853Sgabeblack@google.com        else
75712853Sgabeblack@google.com            return m_right - m_left + 1;
75812853Sgabeblack@google.com    }
75912853Sgabeblack@google.com
76012853Sgabeblack@google.com    // implicit conversion to sc_unsigned
76112853Sgabeblack@google.com    operator sc_unsigned () const;
76212853Sgabeblack@google.com
76312853Sgabeblack@google.com    // explicit conversions
76412853Sgabeblack@google.com    int to_int() const;
76512853Sgabeblack@google.com    unsigned int to_uint() const;
76612853Sgabeblack@google.com    long to_long() const;
76712853Sgabeblack@google.com    unsigned long to_ulong() const;
76812853Sgabeblack@google.com    int64 to_int64() const;
76912853Sgabeblack@google.com    uint64 to_uint64() const;
77012853Sgabeblack@google.com    double to_double() const;
77112853Sgabeblack@google.com
77212853Sgabeblack@google.com    // explicit conversion to character string
77312853Sgabeblack@google.com    const std::string to_string(sc_numrep numrep=SC_DEC) const;
77412853Sgabeblack@google.com    const std::string to_string(sc_numrep numrep, bool w_prefix) const;
77512853Sgabeblack@google.com
77612853Sgabeblack@google.com    // concatenation support
77712853Sgabeblack@google.com    virtual int concat_length(bool *xz_present_p) const
77812853Sgabeblack@google.com    {
77912853Sgabeblack@google.com        if (xz_present_p)
78012853Sgabeblack@google.com            *xz_present_p = false;
78112853Sgabeblack@google.com        return m_left - m_right + 1;
78212853Sgabeblack@google.com    }
78312853Sgabeblack@google.com    virtual uint64 concat_get_uint64() const;
78412853Sgabeblack@google.com    virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const;
78512853Sgabeblack@google.com    virtual bool concat_get_data(sc_digit *dst_p, int low_i) const;
78612853Sgabeblack@google.com
78712853Sgabeblack@google.com    // reduce methods
78812853Sgabeblack@google.com    bool and_reduce() const;
78912853Sgabeblack@google.com    bool nand_reduce() const;
79012853Sgabeblack@google.com    bool or_reduce() const;
79112853Sgabeblack@google.com    bool nor_reduce() const;
79212853Sgabeblack@google.com    bool xor_reduce() const ;
79312853Sgabeblack@google.com    bool xnor_reduce() const;
79412853Sgabeblack@google.com
79512853Sgabeblack@google.com    // other methods
79612853Sgabeblack@google.com    void
79712853Sgabeblack@google.com    print(::std::ostream &os=::std::cout) const
79812853Sgabeblack@google.com    {
79912853Sgabeblack@google.com        os << to_string(sc_io_base(os, SC_DEC), sc_io_show_base(os));
80012853Sgabeblack@google.com    }
80112853Sgabeblack@google.com
80212853Sgabeblack@google.com  protected:
80312853Sgabeblack@google.com    int m_left; // Left-most bit in this part selection.
80412853Sgabeblack@google.com    sc_unsigned *m_obj_p; // Target of this part selection.
80512853Sgabeblack@google.com    int m_right; // Right-most bit in this part selection.
80612853Sgabeblack@google.com
80712853Sgabeblack@google.com  private:
80812853Sgabeblack@google.com    // Disabled
80912853Sgabeblack@google.com    const sc_unsigned_subref_r &operator = (const sc_unsigned_subref_r &);
81012853Sgabeblack@google.com};
81112853Sgabeblack@google.com
81212853Sgabeblack@google.cominline ::std::ostream &operator << (
81312853Sgabeblack@google.com        ::std::ostream &, const sc_unsigned_subref_r &);
81412853Sgabeblack@google.com
81512853Sgabeblack@google.com
81612853Sgabeblack@google.com// ----------------------------------------------------------------------------
81712853Sgabeblack@google.com//  CLASS : sc_unsigned_subref
81812853Sgabeblack@google.com//
81912853Sgabeblack@google.com//  Proxy class for sc_unsigned part selection (r-value and l-value).
82012853Sgabeblack@google.com// ----------------------------------------------------------------------------
82112853Sgabeblack@google.com
82212853Sgabeblack@google.comclass sc_unsigned_subref : public sc_unsigned_subref_r
82312853Sgabeblack@google.com{
82412853Sgabeblack@google.com    friend class sc_unsigned;
82512853Sgabeblack@google.com    friend class sc_core::sc_vpool<sc_unsigned_subref>;
82612853Sgabeblack@google.com
82712853Sgabeblack@google.com    // constructor
82812853Sgabeblack@google.com  protected:
82912853Sgabeblack@google.com    sc_unsigned_subref() : sc_unsigned_subref_r() {}
83012853Sgabeblack@google.com
83112853Sgabeblack@google.com  public:
83212853Sgabeblack@google.com    // copy constructor
83312853Sgabeblack@google.com    sc_unsigned_subref(const sc_unsigned_subref &a) : sc_unsigned_subref_r(a)
83412853Sgabeblack@google.com    {}
83512853Sgabeblack@google.com
83612853Sgabeblack@google.com    // assignment operators
83712853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_unsigned_subref_r &a);
83812853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_unsigned_subref &a);
83912853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_unsigned &a);
84012853Sgabeblack@google.com
84112853Sgabeblack@google.com    template<class T>
84212853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_generic_base<T> &a);
84312853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_signed_subref_r &a);
84412853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_signed &a);
84512853Sgabeblack@google.com
84612853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const char *a);
84712853Sgabeblack@google.com    const sc_unsigned_subref &operator = (unsigned long a);
84812853Sgabeblack@google.com    const sc_unsigned_subref &operator = (long a);
84912853Sgabeblack@google.com
85012853Sgabeblack@google.com    const sc_unsigned_subref &
85112853Sgabeblack@google.com    operator = (unsigned int a)
85212853Sgabeblack@google.com    {
85312853Sgabeblack@google.com        return operator = ((unsigned long)a);
85412853Sgabeblack@google.com    }
85512853Sgabeblack@google.com
85612853Sgabeblack@google.com    const sc_unsigned_subref &
85712853Sgabeblack@google.com    operator = (int a)
85812853Sgabeblack@google.com    {
85912853Sgabeblack@google.com        return operator = ((long)a);
86012853Sgabeblack@google.com    }
86112853Sgabeblack@google.com
86212853Sgabeblack@google.com    const sc_unsigned_subref &operator = (uint64 a);
86312853Sgabeblack@google.com    const sc_unsigned_subref &operator = (int64 a);
86412853Sgabeblack@google.com    const sc_unsigned_subref &operator = (double a);
86512853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_int_base &a);
86612853Sgabeblack@google.com    const sc_unsigned_subref &operator = (const sc_uint_base &a);
86712853Sgabeblack@google.com
86812853Sgabeblack@google.com    // concatenation methods
86912853Sgabeblack@google.com    virtual void concat_set(int64 src, int low_i);
87012853Sgabeblack@google.com    virtual void concat_set(const sc_signed &src, int low_i);
87112853Sgabeblack@google.com    virtual void concat_set(const sc_unsigned &src, int low_i);
87212853Sgabeblack@google.com    virtual void concat_set(uint64 src, int low_i);
87312853Sgabeblack@google.com
87412853Sgabeblack@google.com    // other methods
87512853Sgabeblack@google.com    void scan(::std::istream &is=::std::cin);
87612853Sgabeblack@google.com
87712853Sgabeblack@google.com  protected:
87812853Sgabeblack@google.com    static sc_core::sc_vpool<sc_unsigned_subref> m_pool;
87912853Sgabeblack@google.com};
88012853Sgabeblack@google.com
88112853Sgabeblack@google.cominline ::std::istream &operator >> (::std::istream &, sc_unsigned_subref &);
88212853Sgabeblack@google.com
88312853Sgabeblack@google.com
88412853Sgabeblack@google.com// ----------------------------------------------------------------------------
88512853Sgabeblack@google.com//  CLASS : sc_unsigned
88612853Sgabeblack@google.com//
88712853Sgabeblack@google.com//  Arbitrary precision unsigned number.
88812853Sgabeblack@google.com// ----------------------------------------------------------------------------
88912853Sgabeblack@google.com
89012853Sgabeblack@google.comclass sc_unsigned : public sc_value_base
89112853Sgabeblack@google.com{
89212853Sgabeblack@google.com    friend class sc_concatref;
89312853Sgabeblack@google.com    friend class sc_unsigned_bitref_r;
89412853Sgabeblack@google.com    friend class sc_unsigned_bitref;
89512853Sgabeblack@google.com    friend class sc_unsigned_subref_r;
89612853Sgabeblack@google.com    friend class sc_unsigned_subref;
89712853Sgabeblack@google.com    friend class sc_signed;
89812853Sgabeblack@google.com    friend class sc_signed_subref;
89912853Sgabeblack@google.com    friend class sc_signed_subref_r;
90012853Sgabeblack@google.com
90112853Sgabeblack@google.com    // Needed for types using sc_unsigned.
90212853Sgabeblack@google.com    typedef bool elemtype;
90312853Sgabeblack@google.com
90412853Sgabeblack@google.com    void invalid_init(const char *type_name, int nb) const;
90512853Sgabeblack@google.com
90612853Sgabeblack@google.com  public:
90712853Sgabeblack@google.com    // constructors
90812853Sgabeblack@google.com    explicit sc_unsigned(int nb=sc_length_param().len());
90912853Sgabeblack@google.com    sc_unsigned(const sc_unsigned &v);
91012853Sgabeblack@google.com    sc_unsigned(const sc_signed &v);
91112853Sgabeblack@google.com    template<class T>
91212853Sgabeblack@google.com    explicit sc_unsigned(const sc_generic_base<T> &v);
91312853Sgabeblack@google.com    explicit sc_unsigned(const sc_bv_base &v);
91412853Sgabeblack@google.com    explicit sc_unsigned(const sc_lv_base &v);
91512853Sgabeblack@google.com    explicit sc_unsigned(const sc_int_subref_r &v);
91612853Sgabeblack@google.com    explicit sc_unsigned(const sc_uint_subref_r &v);
91712853Sgabeblack@google.com    explicit sc_unsigned(const sc_signed_subref_r &v);
91812853Sgabeblack@google.com    explicit sc_unsigned(const sc_unsigned_subref_r &v);
91912853Sgabeblack@google.com
92012853Sgabeblack@google.com    // assignment operators
92112853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_unsigned &v);
92212853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_unsigned_subref_r &a);
92312853Sgabeblack@google.com
92412853Sgabeblack@google.com    template<class T>
92512853Sgabeblack@google.com    const sc_unsigned &
92612853Sgabeblack@google.com    operator = (const sc_generic_base<T> &a)
92712853Sgabeblack@google.com    {
92812853Sgabeblack@google.com        a->to_sc_unsigned(*this);
92912853Sgabeblack@google.com        return *this;
93012853Sgabeblack@google.com    }
93112853Sgabeblack@google.com
93212853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_signed &v);
93312853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_signed_subref_r &a);
93412853Sgabeblack@google.com
93512853Sgabeblack@google.com    const sc_unsigned &operator = (const char *v);
93612853Sgabeblack@google.com    const sc_unsigned &operator = (int64 v);
93712853Sgabeblack@google.com    const sc_unsigned &operator = (uint64 v);
93812853Sgabeblack@google.com    const sc_unsigned &operator = (long v);
93912853Sgabeblack@google.com    const sc_unsigned &operator = (unsigned long v);
94012853Sgabeblack@google.com
94112853Sgabeblack@google.com    const sc_unsigned &
94212853Sgabeblack@google.com    operator = (int v)
94312853Sgabeblack@google.com    {
94412853Sgabeblack@google.com        return operator = ((long)v);
94512853Sgabeblack@google.com    }
94612853Sgabeblack@google.com
94712853Sgabeblack@google.com    const sc_unsigned &
94812853Sgabeblack@google.com    operator = (unsigned int v)
94912853Sgabeblack@google.com    {
95012853Sgabeblack@google.com        return operator = ((unsigned long)v);
95112853Sgabeblack@google.com    }
95212853Sgabeblack@google.com
95312853Sgabeblack@google.com    const sc_unsigned &operator = (double v);
95412853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_int_base &v);
95512853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_uint_base &v);
95612853Sgabeblack@google.com
95712853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_bv_base &);
95812853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_lv_base &);
95912853Sgabeblack@google.com
96012853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_fxval &);
96112853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_fxval_fast &);
96212853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_fxnum &);
96312853Sgabeblack@google.com    const sc_unsigned &operator = (const sc_fxnum_fast &);
96412853Sgabeblack@google.com
96512853Sgabeblack@google.com    // destructor
96612853Sgabeblack@google.com    virtual ~sc_unsigned()
96712853Sgabeblack@google.com    {
96812853Sgabeblack@google.com#       ifndef SC_MAX_NBITS
96912853Sgabeblack@google.com            delete [] digit;
97012853Sgabeblack@google.com#       endif
97112853Sgabeblack@google.com    }
97212853Sgabeblack@google.com
97312853Sgabeblack@google.com    // Concatenation support:
97412853Sgabeblack@google.com    sc_digit *get_raw() const { return digit; }
97512853Sgabeblack@google.com    virtual int
97612853Sgabeblack@google.com    concat_length(bool *xz_present_p) const
97712853Sgabeblack@google.com    {
97812853Sgabeblack@google.com        if (xz_present_p)
97912853Sgabeblack@google.com            *xz_present_p = false;
98012853Sgabeblack@google.com        return nbits - 1;
98112853Sgabeblack@google.com    }
98212853Sgabeblack@google.com    virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const;
98312853Sgabeblack@google.com    virtual bool concat_get_data(sc_digit *dst_p, int low_i) const;
98412853Sgabeblack@google.com    virtual uint64 concat_get_uint64() const;
98512853Sgabeblack@google.com    virtual void concat_set(int64 src, int low_i);
98612853Sgabeblack@google.com    virtual void concat_set(const sc_signed &src, int low_i);
98712853Sgabeblack@google.com    virtual void concat_set(const sc_unsigned &src, int low_i);
98812853Sgabeblack@google.com    virtual void concat_set(uint64 src, int low_i);
98912853Sgabeblack@google.com
99012853Sgabeblack@google.com    // Increment operators.
99112853Sgabeblack@google.com    sc_unsigned &operator ++ ();
99212853Sgabeblack@google.com    const sc_unsigned operator ++ (int);
99312853Sgabeblack@google.com
99412853Sgabeblack@google.com    // Decrement operators.
99512853Sgabeblack@google.com    sc_unsigned &operator -- ();
99612853Sgabeblack@google.com    const sc_unsigned operator -- (int);
99712853Sgabeblack@google.com
99812853Sgabeblack@google.com    // bit selection
99912853Sgabeblack@google.com    inline void
100012853Sgabeblack@google.com    check_index(int i) const
100112853Sgabeblack@google.com    {
100212853Sgabeblack@google.com        if ((i < 0) || (i >= nbits - 1))
100312853Sgabeblack@google.com            invalid_index(i);
100412853Sgabeblack@google.com    }
100512853Sgabeblack@google.com
100612853Sgabeblack@google.com    void invalid_index(int i) const;
100712853Sgabeblack@google.com
100812853Sgabeblack@google.com    sc_unsigned_bitref &
100912853Sgabeblack@google.com    operator [] (int i)
101012853Sgabeblack@google.com    {
101112853Sgabeblack@google.com        check_index(i);
101212853Sgabeblack@google.com        sc_unsigned_bitref *result_p = sc_unsigned_bitref::m_pool.allocate();
101312853Sgabeblack@google.com        result_p->initialize(this, i);
101412853Sgabeblack@google.com        return *result_p;
101512853Sgabeblack@google.com    }
101612853Sgabeblack@google.com
101712853Sgabeblack@google.com    const sc_unsigned_bitref_r &
101812853Sgabeblack@google.com    operator [] (int i) const
101912853Sgabeblack@google.com    {
102012853Sgabeblack@google.com        check_index(i);
102112853Sgabeblack@google.com        sc_unsigned_bitref *result_p = sc_unsigned_bitref::m_pool.allocate();
102212853Sgabeblack@google.com        result_p->initialize(this, i);
102312853Sgabeblack@google.com        return *result_p;
102412853Sgabeblack@google.com    }
102512853Sgabeblack@google.com
102612853Sgabeblack@google.com    sc_unsigned_bitref &
102712853Sgabeblack@google.com    bit(int i)
102812853Sgabeblack@google.com    {
102912853Sgabeblack@google.com        check_index(i);
103012853Sgabeblack@google.com        sc_unsigned_bitref *result_p = sc_unsigned_bitref::m_pool.allocate();
103112853Sgabeblack@google.com        result_p->initialize(this, i);
103212853Sgabeblack@google.com        return *result_p;
103312853Sgabeblack@google.com    }
103412853Sgabeblack@google.com
103512853Sgabeblack@google.com    const sc_unsigned_bitref_r &
103612853Sgabeblack@google.com    bit(int i) const
103712853Sgabeblack@google.com    {
103812853Sgabeblack@google.com        check_index(i);
103912853Sgabeblack@google.com        sc_unsigned_bitref *result_p = sc_unsigned_bitref::m_pool.allocate();
104012853Sgabeblack@google.com        result_p->initialize(this, i);
104112853Sgabeblack@google.com        return *result_p;
104212853Sgabeblack@google.com    }
104312853Sgabeblack@google.com
104412853Sgabeblack@google.com    // part selection
104512853Sgabeblack@google.com
104612853Sgabeblack@google.com    // Subref operators. Help access the range of bits from the ith to
104712853Sgabeblack@google.com    // jth. These indices have arbitrary precedence with respect to each
104812853Sgabeblack@google.com    // other, i.e., we can have i <= j or i > j. Note the equivalence
104912853Sgabeblack@google.com    // between range(i, j) and operator (i, j). Also note that
105012853Sgabeblack@google.com    // operator (i, i) returns an unsigned number that corresponds to the
105112853Sgabeblack@google.com    // bit operator [i], so these two forms are not the same.
105212853Sgabeblack@google.com    inline void
105312853Sgabeblack@google.com    check_range(int l, int r) const
105412853Sgabeblack@google.com    {
105512853Sgabeblack@google.com        if (l < r) {
105612853Sgabeblack@google.com            if ((l < 0) || (r >= nbits - 1))
105712853Sgabeblack@google.com                invalid_range(l, r);
105812853Sgabeblack@google.com        } else {
105912853Sgabeblack@google.com            if ((r < 0) || (l >= nbits - 1))
106012853Sgabeblack@google.com                invalid_range(l, r);
106112853Sgabeblack@google.com        }
106212853Sgabeblack@google.com    }
106312853Sgabeblack@google.com
106412853Sgabeblack@google.com    void invalid_range(int l, int r) const;
106512853Sgabeblack@google.com
106612853Sgabeblack@google.com    sc_unsigned_subref &
106712853Sgabeblack@google.com    range(int i, int j)
106812853Sgabeblack@google.com    {
106912853Sgabeblack@google.com        check_range(i, j);
107012853Sgabeblack@google.com        sc_unsigned_subref *result_p = sc_unsigned_subref::m_pool.allocate();
107112853Sgabeblack@google.com        result_p->initialize(this, i, j);
107212853Sgabeblack@google.com        return *result_p;
107312853Sgabeblack@google.com    }
107412853Sgabeblack@google.com
107512853Sgabeblack@google.com    const sc_unsigned_subref_r &
107612853Sgabeblack@google.com    range(int i, int j) const
107712853Sgabeblack@google.com    {
107812853Sgabeblack@google.com        check_range(i, j);
107912853Sgabeblack@google.com        sc_unsigned_subref *result_p = sc_unsigned_subref::m_pool.allocate();
108012853Sgabeblack@google.com        result_p->initialize(this, i, j);
108112853Sgabeblack@google.com        return *result_p;
108212853Sgabeblack@google.com    }
108312853Sgabeblack@google.com
108412853Sgabeblack@google.com    sc_unsigned_subref &
108512853Sgabeblack@google.com    operator () (int i, int j)
108612853Sgabeblack@google.com    {
108712853Sgabeblack@google.com        check_range(i,j);
108812853Sgabeblack@google.com        sc_unsigned_subref *result_p = sc_unsigned_subref::m_pool.allocate();
108912853Sgabeblack@google.com        result_p->initialize(this, i, j);
109012853Sgabeblack@google.com        return *result_p;
109112853Sgabeblack@google.com    }
109212853Sgabeblack@google.com
109312853Sgabeblack@google.com    const sc_unsigned_subref_r &
109412853Sgabeblack@google.com    operator () (int i, int j) const
109512853Sgabeblack@google.com    {
109612853Sgabeblack@google.com        check_range(i,j);
109712853Sgabeblack@google.com        sc_unsigned_subref *result_p = sc_unsigned_subref::m_pool.allocate();
109812853Sgabeblack@google.com        result_p->initialize(this, i, j);
109912853Sgabeblack@google.com        return *result_p;
110012853Sgabeblack@google.com    }
110112853Sgabeblack@google.com
110212853Sgabeblack@google.com    // explicit conversions
110312853Sgabeblack@google.com    int to_int() const;
110412853Sgabeblack@google.com    unsigned int to_uint() const;
110512853Sgabeblack@google.com    long to_long() const;
110612853Sgabeblack@google.com    unsigned long to_ulong() const;
110712853Sgabeblack@google.com    int64 to_int64() const;
110812853Sgabeblack@google.com    uint64 to_uint64() const;
110912853Sgabeblack@google.com    double to_double() const;
111012853Sgabeblack@google.com
111112853Sgabeblack@google.com    // explicit conversion to character string
111212853Sgabeblack@google.com    const std::string to_string(sc_numrep numrep=SC_DEC) const;
111312853Sgabeblack@google.com    const std::string to_string(sc_numrep numrep, bool w_prefix) const;
111412853Sgabeblack@google.com
111512853Sgabeblack@google.com    // Print functions. dump prints the internals of the class.
111612853Sgabeblack@google.com    void
111712853Sgabeblack@google.com    print(::std::ostream &os=::std::cout) const
111812853Sgabeblack@google.com    {
111912853Sgabeblack@google.com        os << to_string(sc_io_base(os, SC_DEC), sc_io_show_base(os));
112012853Sgabeblack@google.com    }
112112853Sgabeblack@google.com
112212853Sgabeblack@google.com    void scan(::std::istream &is=::std::cin);
112312853Sgabeblack@google.com    void dump(::std::ostream &os=::std::cout) const;
112412853Sgabeblack@google.com
112512853Sgabeblack@google.com    // Functions to find various properties.
112612853Sgabeblack@google.com    int length() const { return nbits - 1; } // Bit width.
112712853Sgabeblack@google.com    bool iszero() const; // Is the number zero?
112812853Sgabeblack@google.com    bool sign() const { return 0; } // Sign.
112912853Sgabeblack@google.com
113012853Sgabeblack@google.com    // reduce methods
113112853Sgabeblack@google.com    bool and_reduce() const;
113212853Sgabeblack@google.com    bool nand_reduce() const { return !and_reduce(); }
113312853Sgabeblack@google.com    bool or_reduce() const;
113412853Sgabeblack@google.com    bool nor_reduce() const { return !or_reduce(); }
113512853Sgabeblack@google.com    bool xor_reduce() const;
113612853Sgabeblack@google.com    bool xnor_reduce() const { return !xor_reduce(); }
113712853Sgabeblack@google.com
113812853Sgabeblack@google.com    // Functions to access individual bits.
113912853Sgabeblack@google.com    bool test(int i) const; // Is the ith bit 0 or 1?
114012853Sgabeblack@google.com    void set(int i); // Set the ith bit to 1.
114112853Sgabeblack@google.com    void clear(int i); // Set the ith bit to 0.
114212853Sgabeblack@google.com    void
114312853Sgabeblack@google.com    set(int i, bool v) // Set the ith bit to v.
114412853Sgabeblack@google.com    {
114512853Sgabeblack@google.com        if (v)
114612853Sgabeblack@google.com            set(i);
114712853Sgabeblack@google.com        else
114812853Sgabeblack@google.com            clear(i);
114912853Sgabeblack@google.com    }
115012853Sgabeblack@google.com    void
115112853Sgabeblack@google.com    invert(int i)           // Negate the ith bit.
115212853Sgabeblack@google.com    {
115312853Sgabeblack@google.com        if (test(i))
115412853Sgabeblack@google.com            clear(i);
115512853Sgabeblack@google.com        else
115612853Sgabeblack@google.com            set(i);
115712853Sgabeblack@google.com    }
115812853Sgabeblack@google.com
115912853Sgabeblack@google.com    // Make the number equal to its mirror image.
116012853Sgabeblack@google.com    void reverse();
116112853Sgabeblack@google.com
116212853Sgabeblack@google.com    // Get/set a packed bit representation of the number.
116312853Sgabeblack@google.com    void get_packed_rep(sc_digit *buf) const;
116412853Sgabeblack@google.com    void set_packed_rep(sc_digit *buf);
116512853Sgabeblack@google.com
116612853Sgabeblack@google.com    /*
116712853Sgabeblack@google.com      The comparison of the old and new semantics are as follows:
116812853Sgabeblack@google.com
116912853Sgabeblack@google.com      Let s = sc_signed,
117012853Sgabeblack@google.com          u = sc_unsigned,
117112853Sgabeblack@google.com          un = { uint64, unsigned long, unsigned int },
117212853Sgabeblack@google.com          sn = { int64, long, int, char* }, and
117312853Sgabeblack@google.com          OP = { +, -, *, /, % }.
117412853Sgabeblack@google.com
117512853Sgabeblack@google.com      Old semantics:                     New semantics:
117612853Sgabeblack@google.com        u OP u -> u                        u OP u -> u
117712853Sgabeblack@google.com        s OP u -> u                        s OP u -> s
117812853Sgabeblack@google.com        u OP s -> u                        u OP s -> s
117912853Sgabeblack@google.com        s OP s -> s                        s OP s -> s
118012853Sgabeblack@google.com
118112853Sgabeblack@google.com        u OP un = un OP u -> u             u OP un = un OP u -> u
118212853Sgabeblack@google.com        u OP sn = sn OP u -> u             u OP sn = sn OP u -> s
118312853Sgabeblack@google.com
118412853Sgabeblack@google.com        s OP un = un OP s -> s             s OP un = un OP s -> s
118512853Sgabeblack@google.com        s OP sn = sn OP s -> s             s OP sn = sn OP s -> s
118612853Sgabeblack@google.com
118712853Sgabeblack@google.com      In the new semantics, the result is u if both operands are u; the
118812853Sgabeblack@google.com      result is s otherwise. The only exception is subtraction. The result
118912853Sgabeblack@google.com      of a subtraction is always s.
119012853Sgabeblack@google.com
119112853Sgabeblack@google.com      The old semantics is like C/C++ semantics on integer types; the
119212853Sgabeblack@google.com      new semantics is due to the VSIA C/C++ data types standard.
119312853Sgabeblack@google.com    */
119412853Sgabeblack@google.com
119512853Sgabeblack@google.com    // ARITHMETIC OPERATORS:
119612853Sgabeblack@google.com
119712853Sgabeblack@google.com    // ADDition operators:
119812853Sgabeblack@google.com    friend sc_signed operator + (const sc_unsigned &u, const sc_signed &v);
119912853Sgabeblack@google.com    friend sc_signed operator + (const sc_signed &u, const sc_unsigned &v);
120012853Sgabeblack@google.com
120112853Sgabeblack@google.com    friend sc_unsigned operator + (const sc_unsigned &u, const sc_unsigned &v);
120212853Sgabeblack@google.com    friend sc_signed operator + (const sc_unsigned &u, int64 v);
120312853Sgabeblack@google.com    friend sc_unsigned operator + (const sc_unsigned &u, uint64 v);
120412853Sgabeblack@google.com    friend sc_signed operator + (const sc_unsigned &u, long v);
120512853Sgabeblack@google.com    friend sc_unsigned operator + (const sc_unsigned &u, unsigned long v);
120612853Sgabeblack@google.com    friend sc_signed operator + (const sc_unsigned &u, int v);
120712853Sgabeblack@google.com    friend sc_unsigned
120812853Sgabeblack@google.com    operator + (const sc_unsigned &u, unsigned int v)
120912853Sgabeblack@google.com    {
121012853Sgabeblack@google.com        return operator + (u, (unsigned long)v);
121112853Sgabeblack@google.com    }
121212853Sgabeblack@google.com
121312853Sgabeblack@google.com    friend sc_signed operator + (int64 u, const sc_unsigned &v);
121412853Sgabeblack@google.com    friend sc_unsigned operator + (uint64 u, const sc_unsigned &v);
121512853Sgabeblack@google.com    friend sc_signed operator + (long u, const sc_unsigned &v);
121612853Sgabeblack@google.com    friend sc_unsigned operator + (unsigned long u, const sc_unsigned &v);
121712853Sgabeblack@google.com    friend sc_signed operator + (int u, const sc_unsigned &v);
121812853Sgabeblack@google.com    friend sc_unsigned
121912853Sgabeblack@google.com    operator + (unsigned int u, const sc_unsigned &v)
122012853Sgabeblack@google.com    {
122112853Sgabeblack@google.com        return operator + ((unsigned long)u, v);
122212853Sgabeblack@google.com    }
122312853Sgabeblack@google.com
122412853Sgabeblack@google.com    const sc_unsigned &operator += (const sc_signed &v);
122512853Sgabeblack@google.com    const sc_unsigned &operator += (const sc_unsigned &v);
122612853Sgabeblack@google.com    const sc_unsigned &operator += (int64 v);
122712853Sgabeblack@google.com    const sc_unsigned &operator += (uint64 v);
122812853Sgabeblack@google.com    const sc_unsigned &operator += (long v);
122912853Sgabeblack@google.com    const sc_unsigned &operator += (unsigned long v);
123012853Sgabeblack@google.com    const sc_unsigned &
123112853Sgabeblack@google.com    operator += (int v)
123212853Sgabeblack@google.com    {
123312853Sgabeblack@google.com        return operator += ((long)v);
123412853Sgabeblack@google.com    }
123512853Sgabeblack@google.com    const sc_unsigned &
123612853Sgabeblack@google.com    operator += (unsigned int v)
123712853Sgabeblack@google.com    {
123812853Sgabeblack@google.com        return operator += ((unsigned long)v);
123912853Sgabeblack@google.com    }
124012853Sgabeblack@google.com
124112853Sgabeblack@google.com    friend sc_unsigned operator + (
124212853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
124312853Sgabeblack@google.com    friend sc_signed operator + (const sc_unsigned &u, const sc_int_base &v);
124412853Sgabeblack@google.com    friend sc_unsigned operator + (
124512853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
124612853Sgabeblack@google.com    friend sc_signed operator + (const sc_int_base &u, const sc_unsigned &v);
124712853Sgabeblack@google.com    const sc_unsigned &operator += (const sc_int_base &v);
124812853Sgabeblack@google.com    const sc_unsigned &operator += (const sc_uint_base &v);
124912853Sgabeblack@google.com
125012853Sgabeblack@google.com    // SUBtraction operators:
125112853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, const sc_signed &v);
125212853Sgabeblack@google.com    friend sc_signed operator - (const sc_signed &u, const sc_unsigned &v);
125312853Sgabeblack@google.com
125412853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, const sc_unsigned &v);
125512853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, int64 v);
125612853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, uint64 v);
125712853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, long v);
125812853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, unsigned long v);
125912853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, int v);
126012853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, unsigned int v);
126112853Sgabeblack@google.com
126212853Sgabeblack@google.com    friend sc_signed operator - (int64 u, const sc_unsigned &v);
126312853Sgabeblack@google.com    friend sc_signed operator - (uint64 u, const sc_unsigned &v);
126412853Sgabeblack@google.com    friend sc_signed operator - (long u, const sc_unsigned &v);
126512853Sgabeblack@google.com    friend sc_signed operator - (unsigned long u, const sc_unsigned &v);
126612853Sgabeblack@google.com    friend sc_signed operator - (int u, const sc_unsigned &v);
126712853Sgabeblack@google.com    friend sc_signed operator - (unsigned int u, const sc_unsigned &v);
126812853Sgabeblack@google.com
126912853Sgabeblack@google.com    const sc_unsigned &operator -= (const sc_signed &v);
127012853Sgabeblack@google.com    const sc_unsigned &operator -= (const sc_unsigned &v);
127112853Sgabeblack@google.com    const sc_unsigned &operator -= (int64 v);
127212853Sgabeblack@google.com    const sc_unsigned &operator -= (uint64 v);
127312853Sgabeblack@google.com    const sc_unsigned &operator -= (long v);
127412853Sgabeblack@google.com    const sc_unsigned &operator -= (unsigned long v);
127512853Sgabeblack@google.com    const sc_unsigned &
127612853Sgabeblack@google.com    operator -= (int v)
127712853Sgabeblack@google.com    {
127812853Sgabeblack@google.com        return operator -= ((long)v);
127912853Sgabeblack@google.com    }
128012853Sgabeblack@google.com    const sc_unsigned &
128112853Sgabeblack@google.com    operator -= (unsigned int v)
128212853Sgabeblack@google.com    {
128312853Sgabeblack@google.com        return operator -= ((unsigned long)v);
128412853Sgabeblack@google.com    }
128512853Sgabeblack@google.com
128612853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, const sc_uint_base &v);
128712853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u, const sc_int_base &v);
128812853Sgabeblack@google.com    friend sc_signed operator - (const sc_uint_base &u, const sc_unsigned &v);
128912853Sgabeblack@google.com    friend sc_signed operator - (const sc_int_base &u, const sc_unsigned &v);
129012853Sgabeblack@google.com    const sc_unsigned &operator -= (const sc_int_base &v);
129112853Sgabeblack@google.com    const sc_unsigned &operator -= (const sc_uint_base &v);
129212853Sgabeblack@google.com
129312853Sgabeblack@google.com    // MULtiplication operators:
129412853Sgabeblack@google.com    friend sc_signed operator * (const sc_unsigned &u, const sc_signed &v);
129512853Sgabeblack@google.com    friend sc_signed operator * (const sc_signed &u, const sc_unsigned &v);
129612853Sgabeblack@google.com
129712853Sgabeblack@google.com    friend sc_unsigned operator * (const sc_unsigned &u, const sc_unsigned &v);
129812853Sgabeblack@google.com    friend sc_signed operator * (const sc_unsigned &u, int64 v);
129912853Sgabeblack@google.com    friend sc_unsigned operator * (const sc_unsigned &u, uint64 v);
130012853Sgabeblack@google.com    friend sc_signed operator * (const sc_unsigned &u, long v);
130112853Sgabeblack@google.com    friend sc_unsigned operator * (const sc_unsigned &u, unsigned long v);
130212853Sgabeblack@google.com    friend sc_signed operator * (const sc_unsigned &u, int v);
130312853Sgabeblack@google.com    friend sc_unsigned
130412853Sgabeblack@google.com    operator * (const sc_unsigned &u, unsigned int v)
130512853Sgabeblack@google.com    {
130612853Sgabeblack@google.com        return operator * (u, (unsigned long)v);
130712853Sgabeblack@google.com    }
130812853Sgabeblack@google.com
130912853Sgabeblack@google.com    friend sc_signed operator * (int64 u, const sc_unsigned &v);
131012853Sgabeblack@google.com    friend sc_unsigned operator * (uint64 u, const sc_unsigned &v);
131112853Sgabeblack@google.com    friend sc_signed operator * (long u, const sc_unsigned &v);
131212853Sgabeblack@google.com    friend sc_unsigned operator * (unsigned long u, const sc_unsigned &v);
131312853Sgabeblack@google.com    friend sc_signed operator * (int u, const sc_unsigned &v);
131412853Sgabeblack@google.com    friend sc_unsigned
131512853Sgabeblack@google.com    operator * (unsigned int u, const sc_unsigned &v)
131612853Sgabeblack@google.com    {
131712853Sgabeblack@google.com        return operator * ((unsigned long)u, v);
131812853Sgabeblack@google.com    }
131912853Sgabeblack@google.com
132012853Sgabeblack@google.com    const sc_unsigned &operator *= (const sc_signed &v);
132112853Sgabeblack@google.com    const sc_unsigned &operator *= (const sc_unsigned &v);
132212853Sgabeblack@google.com    const sc_unsigned &operator *= (int64 v);
132312853Sgabeblack@google.com    const sc_unsigned &operator *= (uint64 v);
132412853Sgabeblack@google.com    const sc_unsigned &operator *= (long v);
132512853Sgabeblack@google.com    const sc_unsigned &operator *= (unsigned long v);
132612853Sgabeblack@google.com    const sc_unsigned &operator *= (int v) { return operator *= ((long)v); }
132712853Sgabeblack@google.com    const sc_unsigned &
132812853Sgabeblack@google.com    operator *= (unsigned int v)
132912853Sgabeblack@google.com    {
133012853Sgabeblack@google.com        return operator *= ((unsigned long)v);
133112853Sgabeblack@google.com    }
133212853Sgabeblack@google.com
133312853Sgabeblack@google.com    friend sc_unsigned operator * (
133412853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
133512853Sgabeblack@google.com    friend sc_signed operator * (const sc_unsigned &u, const sc_int_base &v);
133612853Sgabeblack@google.com    friend sc_unsigned operator * (
133712853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
133812853Sgabeblack@google.com    friend sc_signed operator * (const sc_int_base &u, const sc_unsigned &v);
133912853Sgabeblack@google.com    const sc_unsigned &operator *= (const sc_int_base &v);
134012853Sgabeblack@google.com    const sc_unsigned &operator *= (const sc_uint_base &v);
134112853Sgabeblack@google.com
134212853Sgabeblack@google.com    // DIVision operators:
134312853Sgabeblack@google.com    friend sc_signed operator / (const sc_unsigned &u, const sc_signed &v);
134412853Sgabeblack@google.com    friend sc_signed operator / (const sc_signed &u, const sc_unsigned &v);
134512853Sgabeblack@google.com
134612853Sgabeblack@google.com    friend sc_unsigned operator / (const sc_unsigned &u, const sc_unsigned &v);
134712853Sgabeblack@google.com    friend sc_signed operator / (const sc_unsigned &u, int64 v);
134812853Sgabeblack@google.com    friend sc_unsigned operator / (const sc_unsigned &u, uint64 v);
134912853Sgabeblack@google.com    friend sc_signed operator / (const sc_unsigned &u, long v);
135012853Sgabeblack@google.com    friend sc_unsigned operator / (const sc_unsigned &u, unsigned long v);
135112853Sgabeblack@google.com    friend sc_signed operator / (const sc_unsigned &u, int v);
135212853Sgabeblack@google.com    friend sc_unsigned
135312853Sgabeblack@google.com    operator / (const sc_unsigned &u, unsigned int v)
135412853Sgabeblack@google.com    {
135512853Sgabeblack@google.com        return operator / (u, (unsigned long)v);
135612853Sgabeblack@google.com    }
135712853Sgabeblack@google.com
135812853Sgabeblack@google.com    friend sc_signed operator / (int64 u, const sc_unsigned &v);
135912853Sgabeblack@google.com    friend sc_unsigned operator / (uint64 u, const sc_unsigned &v);
136012853Sgabeblack@google.com    friend sc_signed operator / (long u, const sc_unsigned &v);
136112853Sgabeblack@google.com    friend sc_unsigned operator / (unsigned long u, const sc_unsigned &v);
136212853Sgabeblack@google.com    friend sc_signed operator / (int u, const sc_unsigned &v);
136312853Sgabeblack@google.com    friend sc_unsigned
136412853Sgabeblack@google.com    operator / (unsigned int u, const sc_unsigned &v)
136512853Sgabeblack@google.com    {
136612853Sgabeblack@google.com        return operator / ((unsigned long)u, v);
136712853Sgabeblack@google.com    }
136812853Sgabeblack@google.com
136912853Sgabeblack@google.com    const sc_unsigned &operator /= (const sc_signed &v);
137012853Sgabeblack@google.com    const sc_unsigned &operator /= (const sc_unsigned &v);
137112853Sgabeblack@google.com    const sc_unsigned &operator /= (int64 v);
137212853Sgabeblack@google.com    const sc_unsigned &operator /= (uint64 v);
137312853Sgabeblack@google.com    const sc_unsigned &operator /= (long v);
137412853Sgabeblack@google.com    const sc_unsigned &operator /= (unsigned long v);
137512853Sgabeblack@google.com    const sc_unsigned &operator /= (int v) { return operator /= ((long)v); }
137612853Sgabeblack@google.com    const sc_unsigned &
137712853Sgabeblack@google.com    operator /= (unsigned int v)
137812853Sgabeblack@google.com    {
137912853Sgabeblack@google.com        return operator /= ((unsigned long)v);
138012853Sgabeblack@google.com    }
138112853Sgabeblack@google.com
138212853Sgabeblack@google.com    friend sc_unsigned operator / (
138312853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
138412853Sgabeblack@google.com    friend sc_signed operator / (const sc_unsigned &u, const sc_int_base &v);
138512853Sgabeblack@google.com    friend sc_unsigned operator / (
138612853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
138712853Sgabeblack@google.com    friend sc_signed operator / (const sc_int_base &u, const sc_unsigned &v);
138812853Sgabeblack@google.com    const sc_unsigned &operator /= (const sc_int_base &v);
138912853Sgabeblack@google.com    const sc_unsigned &operator /= (const sc_uint_base &v);
139012853Sgabeblack@google.com
139112853Sgabeblack@google.com    // MODulo operators:
139212853Sgabeblack@google.com    friend sc_signed operator % (const sc_unsigned &u, const sc_signed &v);
139312853Sgabeblack@google.com    friend sc_signed operator % (const sc_signed &u, const sc_unsigned &v);
139412853Sgabeblack@google.com
139512853Sgabeblack@google.com    friend sc_unsigned operator % (const sc_unsigned &u, const sc_unsigned &v);
139612853Sgabeblack@google.com    friend sc_signed operator % (const sc_unsigned &u, int64 v);
139712853Sgabeblack@google.com    friend sc_unsigned operator % (const sc_unsigned &u, uint64 v);
139812853Sgabeblack@google.com    friend sc_signed operator % (const sc_unsigned &u, long v);
139912853Sgabeblack@google.com    friend sc_unsigned operator % (const sc_unsigned &u, unsigned long v);
140012853Sgabeblack@google.com    friend sc_signed operator % (const sc_unsigned &u, int v);
140112853Sgabeblack@google.com    friend sc_unsigned
140212853Sgabeblack@google.com    operator % (const sc_unsigned &u, unsigned int v)
140312853Sgabeblack@google.com    {
140412853Sgabeblack@google.com        return operator % (u, (unsigned long)v);
140512853Sgabeblack@google.com    }
140612853Sgabeblack@google.com
140712853Sgabeblack@google.com    friend sc_signed operator % (int64 u, const sc_unsigned &v);
140812853Sgabeblack@google.com    friend sc_unsigned operator % (uint64 u, const sc_unsigned &v);
140912853Sgabeblack@google.com    friend sc_signed operator % (long u, const sc_unsigned &v);
141012853Sgabeblack@google.com    friend sc_unsigned operator % (unsigned long u, const sc_unsigned &v);
141112853Sgabeblack@google.com    friend sc_signed operator % (int u, const sc_unsigned &v);
141212853Sgabeblack@google.com    friend sc_unsigned
141312853Sgabeblack@google.com    operator % (unsigned int u, const sc_unsigned &v)
141412853Sgabeblack@google.com    {
141512853Sgabeblack@google.com        return operator % ((unsigned long)u, v);
141612853Sgabeblack@google.com    }
141712853Sgabeblack@google.com
141812853Sgabeblack@google.com    const sc_unsigned &operator %= (const sc_signed &v);
141912853Sgabeblack@google.com    const sc_unsigned &operator %= (const sc_unsigned &v);
142012853Sgabeblack@google.com    const sc_unsigned &operator %= (int64 v);
142112853Sgabeblack@google.com    const sc_unsigned &operator %= (uint64 v);
142212853Sgabeblack@google.com    const sc_unsigned &operator %= (long v);
142312853Sgabeblack@google.com    const sc_unsigned &operator %= (unsigned long v);
142412853Sgabeblack@google.com    const sc_unsigned &operator %= (int v) { return operator %= ((long)v); }
142512853Sgabeblack@google.com    const sc_unsigned &
142612853Sgabeblack@google.com    operator %= (unsigned int v)
142712853Sgabeblack@google.com    {
142812853Sgabeblack@google.com        return operator %= ((unsigned long)v);
142912853Sgabeblack@google.com    }
143012853Sgabeblack@google.com
143112853Sgabeblack@google.com    friend sc_unsigned operator % (
143212853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
143312853Sgabeblack@google.com    friend sc_signed operator % (const sc_unsigned &u, const sc_int_base &v);
143412853Sgabeblack@google.com    friend sc_unsigned operator % (
143512853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
143612853Sgabeblack@google.com    friend sc_signed operator % (const sc_int_base &u, const sc_unsigned &v);
143712853Sgabeblack@google.com    const sc_unsigned &operator %= (const sc_int_base &v);
143812853Sgabeblack@google.com    const sc_unsigned &operator %= (const sc_uint_base &v);
143912853Sgabeblack@google.com
144012853Sgabeblack@google.com    // BITWISE OPERATORS:
144112853Sgabeblack@google.com
144212853Sgabeblack@google.com    // Bitwise AND operators:
144312853Sgabeblack@google.com    friend sc_signed operator & (const sc_unsigned &u, const sc_signed &v);
144412853Sgabeblack@google.com    friend sc_signed operator & (const sc_signed &u, const sc_unsigned &v);
144512853Sgabeblack@google.com
144612853Sgabeblack@google.com    friend sc_unsigned operator & (const sc_unsigned &u, const sc_unsigned &v);
144712853Sgabeblack@google.com    friend sc_signed operator & (const sc_unsigned &u, int64 v);
144812853Sgabeblack@google.com    friend sc_unsigned operator & (const sc_unsigned &u, uint64 v);
144912853Sgabeblack@google.com    friend sc_signed operator & (const sc_unsigned &u, long v);
145012853Sgabeblack@google.com    friend sc_unsigned operator & (const sc_unsigned &u, unsigned long v);
145112853Sgabeblack@google.com    friend sc_signed operator & (const sc_unsigned &u, int v);
145212853Sgabeblack@google.com    friend sc_unsigned
145312853Sgabeblack@google.com    operator & (const sc_unsigned &u, unsigned int v)
145412853Sgabeblack@google.com    {
145512853Sgabeblack@google.com        return operator & (u, (unsigned long)v);
145612853Sgabeblack@google.com    }
145712853Sgabeblack@google.com
145812853Sgabeblack@google.com    friend sc_signed operator & (int64 u, const sc_unsigned &v);
145912853Sgabeblack@google.com    friend sc_unsigned operator & (uint64 u, const sc_unsigned &v);
146012853Sgabeblack@google.com    friend sc_signed operator & (long u, const sc_unsigned &v);
146112853Sgabeblack@google.com    friend sc_unsigned operator & (unsigned long u, const sc_unsigned &v);
146212853Sgabeblack@google.com    friend sc_signed operator & (int u, const sc_unsigned &v);
146312853Sgabeblack@google.com    friend sc_unsigned
146412853Sgabeblack@google.com    operator & (unsigned int u, const sc_unsigned &v)
146512853Sgabeblack@google.com    {
146612853Sgabeblack@google.com        return operator & ((unsigned long)u, v);
146712853Sgabeblack@google.com    }
146812853Sgabeblack@google.com
146912853Sgabeblack@google.com    const sc_unsigned &operator &= (const sc_signed &v);
147012853Sgabeblack@google.com    const sc_unsigned &operator &= (const sc_unsigned &v);
147112853Sgabeblack@google.com    const sc_unsigned &operator &= (int64 v);
147212853Sgabeblack@google.com    const sc_unsigned &operator &= (uint64 v);
147312853Sgabeblack@google.com    const sc_unsigned &operator &= (long v);
147412853Sgabeblack@google.com    const sc_unsigned &operator &= (unsigned long v);
147512853Sgabeblack@google.com    const sc_unsigned &operator &= (int v) { return operator&=((long) v); }
147612853Sgabeblack@google.com    const sc_unsigned &
147712853Sgabeblack@google.com    operator &= (unsigned int v)
147812853Sgabeblack@google.com    {
147912853Sgabeblack@google.com        return operator &= ((unsigned long)v);
148012853Sgabeblack@google.com    }
148112853Sgabeblack@google.com
148212853Sgabeblack@google.com    friend sc_unsigned operator & (
148312853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
148412853Sgabeblack@google.com    friend sc_signed operator & (const sc_unsigned &u, const sc_int_base &v);
148512853Sgabeblack@google.com    friend sc_unsigned operator & (
148612853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
148712853Sgabeblack@google.com    friend sc_signed operator & (const sc_int_base &u, const sc_unsigned &v);
148812853Sgabeblack@google.com    const sc_unsigned &operator &= (const sc_int_base &v);
148912853Sgabeblack@google.com    const sc_unsigned &operator &= (const sc_uint_base &v);
149012853Sgabeblack@google.com
149112853Sgabeblack@google.com    // Bitwise OR operators:
149212853Sgabeblack@google.com    friend sc_signed operator | (const sc_unsigned &u, const sc_signed &v);
149312853Sgabeblack@google.com    friend sc_signed operator | (const sc_signed &u, const sc_unsigned &v);
149412853Sgabeblack@google.com
149512853Sgabeblack@google.com    friend sc_unsigned operator | (const sc_unsigned &u, const sc_unsigned &v);
149612853Sgabeblack@google.com    friend sc_signed operator | (const sc_unsigned &u, int64 v);
149712853Sgabeblack@google.com    friend sc_unsigned operator | (const sc_unsigned &u, uint64 v);
149812853Sgabeblack@google.com    friend sc_signed operator | (const sc_unsigned &u, long v);
149912853Sgabeblack@google.com    friend sc_unsigned operator | (const sc_unsigned &u, unsigned long v);
150012853Sgabeblack@google.com    friend sc_signed operator | (const sc_unsigned &u, int v);
150112853Sgabeblack@google.com    friend sc_unsigned
150212853Sgabeblack@google.com    operator | (const sc_unsigned &u, unsigned int v)
150312853Sgabeblack@google.com    {
150412853Sgabeblack@google.com        return operator | (u, (unsigned long)v);
150512853Sgabeblack@google.com    }
150612853Sgabeblack@google.com
150712853Sgabeblack@google.com    friend sc_signed operator | (int64 u, const sc_unsigned &v);
150812853Sgabeblack@google.com    friend sc_unsigned operator | (uint64 u, const sc_unsigned &v);
150912853Sgabeblack@google.com    friend sc_signed operator | (long u, const sc_unsigned &v);
151012853Sgabeblack@google.com    friend sc_unsigned operator | (unsigned long u, const sc_unsigned &v);
151112853Sgabeblack@google.com    friend sc_signed operator | (int u, const sc_unsigned &v);
151212853Sgabeblack@google.com    friend sc_unsigned
151312853Sgabeblack@google.com    operator | (unsigned int u, const sc_unsigned &v)
151412853Sgabeblack@google.com    {
151512853Sgabeblack@google.com        return operator | ((unsigned long)u, v);
151612853Sgabeblack@google.com    }
151712853Sgabeblack@google.com
151812853Sgabeblack@google.com    const sc_unsigned &operator |= (const sc_signed &v);
151912853Sgabeblack@google.com    const sc_unsigned &operator |= (const sc_unsigned &v);
152012853Sgabeblack@google.com    const sc_unsigned &operator |= (int64 v);
152112853Sgabeblack@google.com    const sc_unsigned &operator |= (uint64 v);
152212853Sgabeblack@google.com    const sc_unsigned &operator |= (long v);
152312853Sgabeblack@google.com    const sc_unsigned &operator |= (unsigned long v);
152412853Sgabeblack@google.com    const sc_unsigned &operator |= (int v) { return operator|=((long) v); }
152512853Sgabeblack@google.com    const sc_unsigned &
152612853Sgabeblack@google.com    operator |= (unsigned int v)
152712853Sgabeblack@google.com    {
152812853Sgabeblack@google.com        return operator |= ((unsigned long)v);
152912853Sgabeblack@google.com    }
153012853Sgabeblack@google.com
153112853Sgabeblack@google.com    friend sc_unsigned operator | (
153212853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
153312853Sgabeblack@google.com    friend sc_signed operator | (const sc_unsigned &u, const sc_int_base &v);
153412853Sgabeblack@google.com    friend sc_unsigned operator | (
153512853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
153612853Sgabeblack@google.com    friend sc_signed operator | (const sc_int_base &u, const sc_unsigned &v);
153712853Sgabeblack@google.com    const sc_unsigned &operator |= (const sc_int_base &v);
153812853Sgabeblack@google.com    const sc_unsigned &operator |= (const sc_uint_base &v);
153912853Sgabeblack@google.com
154012853Sgabeblack@google.com    // Bitwise XOR operators:
154112853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_unsigned &u, const sc_signed &v);
154212853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_signed &u, const sc_unsigned &v);
154312853Sgabeblack@google.com
154412853Sgabeblack@google.com    friend sc_unsigned operator ^ (const sc_unsigned &u, const sc_unsigned &v);
154512853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_unsigned &u, int64 v);
154612853Sgabeblack@google.com    friend sc_unsigned operator ^ (const sc_unsigned &u, uint64 v);
154712853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_unsigned &u, long v);
154812853Sgabeblack@google.com    friend sc_unsigned operator ^ (const sc_unsigned &u, unsigned long v);
154912853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_unsigned &u, int v);
155012853Sgabeblack@google.com    friend sc_unsigned
155112853Sgabeblack@google.com    operator ^ (const sc_unsigned &u, unsigned int v)
155212853Sgabeblack@google.com    {
155312853Sgabeblack@google.com        return operator ^ (u, (unsigned long)v);
155412853Sgabeblack@google.com    }
155512853Sgabeblack@google.com
155612853Sgabeblack@google.com    friend sc_signed operator ^ (int64 u, const sc_unsigned &v);
155712853Sgabeblack@google.com    friend sc_unsigned operator ^ (uint64 u, const sc_unsigned &v);
155812853Sgabeblack@google.com    friend sc_signed operator ^ (long u, const sc_unsigned &v);
155912853Sgabeblack@google.com    friend sc_unsigned operator ^ (unsigned long u, const sc_unsigned &v);
156012853Sgabeblack@google.com    friend sc_signed operator ^ (int u, const sc_unsigned &v);
156112853Sgabeblack@google.com    friend sc_unsigned
156212853Sgabeblack@google.com    operator ^ (unsigned int u, const sc_unsigned &v)
156312853Sgabeblack@google.com    {
156412853Sgabeblack@google.com        return operator ^ ((unsigned long)u, v);
156512853Sgabeblack@google.com    }
156612853Sgabeblack@google.com
156712853Sgabeblack@google.com    const sc_unsigned &operator ^= (const sc_signed &v);
156812853Sgabeblack@google.com    const sc_unsigned &operator ^= (const sc_unsigned &v);
156912853Sgabeblack@google.com    const sc_unsigned &operator ^= (int64 v);
157012853Sgabeblack@google.com    const sc_unsigned &operator ^= (uint64 v);
157112853Sgabeblack@google.com    const sc_unsigned &operator ^= (long v);
157212853Sgabeblack@google.com    const sc_unsigned &operator ^= (unsigned long v);
157312853Sgabeblack@google.com    const sc_unsigned &
157412853Sgabeblack@google.com    operator ^= (int v)
157512853Sgabeblack@google.com    {
157612853Sgabeblack@google.com        return operator ^= ((long)v);
157712853Sgabeblack@google.com    }
157812853Sgabeblack@google.com    const sc_unsigned &
157912853Sgabeblack@google.com    operator ^= (unsigned int v)
158012853Sgabeblack@google.com    {
158112853Sgabeblack@google.com        return operator ^= ((unsigned long)v);
158212853Sgabeblack@google.com    }
158312853Sgabeblack@google.com
158412853Sgabeblack@google.com    friend sc_unsigned operator ^ (
158512853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
158612853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_unsigned &u, const sc_int_base &v);
158712853Sgabeblack@google.com    friend sc_unsigned operator ^ (
158812853Sgabeblack@google.com            const sc_uint_base &u, const sc_unsigned &v);
158912853Sgabeblack@google.com    friend sc_signed operator ^ (const sc_int_base &u, const sc_unsigned &v);
159012853Sgabeblack@google.com    const sc_unsigned &operator ^= (const sc_int_base &v);
159112853Sgabeblack@google.com    const sc_unsigned &operator ^= (const sc_uint_base &v);
159212853Sgabeblack@google.com
159312853Sgabeblack@google.com    // SHIFT OPERATORS:
159412853Sgabeblack@google.com
159512853Sgabeblack@google.com    // LEFT SHIFT operators:
159612853Sgabeblack@google.com    friend sc_unsigned operator << (const sc_unsigned &u, const sc_signed &v);
159712853Sgabeblack@google.com    friend sc_signed operator << (const sc_signed &u, const sc_unsigned &v);
159812853Sgabeblack@google.com
159912853Sgabeblack@google.com    friend sc_unsigned operator << (
160012853Sgabeblack@google.com            const sc_unsigned &u, const sc_unsigned &v);
160112853Sgabeblack@google.com    friend sc_unsigned operator << (const sc_unsigned &u, int64 v);
160212853Sgabeblack@google.com    friend sc_unsigned operator << (const sc_unsigned &u, uint64 v);
160312853Sgabeblack@google.com    friend sc_unsigned operator << (const sc_unsigned &u, long v);
160412853Sgabeblack@google.com    friend sc_unsigned operator << (const sc_unsigned &u, unsigned long v);
160512853Sgabeblack@google.com    friend sc_unsigned
160612853Sgabeblack@google.com    operator << (const sc_unsigned &u, int v)
160712853Sgabeblack@google.com    {
160812853Sgabeblack@google.com        return operator << (u, (long)v);
160912853Sgabeblack@google.com    }
161012853Sgabeblack@google.com    friend sc_unsigned
161112853Sgabeblack@google.com    operator << (const sc_unsigned &u, unsigned int v)
161212853Sgabeblack@google.com    {
161312853Sgabeblack@google.com        return operator << (u, (unsigned long)v);
161412853Sgabeblack@google.com    }
161512853Sgabeblack@google.com
161612853Sgabeblack@google.com    const sc_unsigned &operator <<= (const sc_signed &v);
161712853Sgabeblack@google.com    const sc_unsigned &operator <<= (const sc_unsigned &v);
161812853Sgabeblack@google.com    const sc_unsigned &operator <<= (int64 v);
161912853Sgabeblack@google.com    const sc_unsigned &operator <<= (uint64 v);
162012853Sgabeblack@google.com    const sc_unsigned &operator <<= (long v);
162112853Sgabeblack@google.com    const sc_unsigned &operator <<= (unsigned long v);
162212853Sgabeblack@google.com    const sc_unsigned &operator <<= (int v) { return operator <<= ((long)v); }
162312853Sgabeblack@google.com    const sc_unsigned &
162412853Sgabeblack@google.com    operator <<= (unsigned int v)
162512853Sgabeblack@google.com    {
162612853Sgabeblack@google.com        return operator <<= ((unsigned long)v);
162712853Sgabeblack@google.com    }
162812853Sgabeblack@google.com
162912853Sgabeblack@google.com    friend sc_unsigned operator << (
163012853Sgabeblack@google.com            const sc_unsigned &u, const sc_uint_base &v);
163112853Sgabeblack@google.com    friend sc_unsigned operator << (
163212853Sgabeblack@google.com            const sc_unsigned &u, const sc_int_base &v);
163312853Sgabeblack@google.com    const sc_unsigned &operator <<= (const sc_int_base &v);
163412853Sgabeblack@google.com    const sc_unsigned &operator <<= (const sc_uint_base &v);
163512853Sgabeblack@google.com
163612853Sgabeblack@google.com    // RIGHT SHIFT operators:
163712853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &u, const sc_signed &v);
163812853Sgabeblack@google.com    friend sc_signed operator >> (const sc_signed &u, const sc_unsigned &v);
163912853Sgabeblack@google.com
164012853Sgabeblack@google.com    friend sc_unsigned operator >> (
164112853Sgabeblack@google.com            const sc_unsigned &u, const sc_unsigned &v);
164212853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &u, int64 v);
164312853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &u, uint64 v);
164412853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &u, long v);
164512853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &u, unsigned long v);
164612853Sgabeblack@google.com    friend sc_unsigned
164712853Sgabeblack@google.com    operator >> (const sc_unsigned &u, int v)
164812853Sgabeblack@google.com    {
164912853Sgabeblack@google.com        return operator >> (u, (long)v);
165012853Sgabeblack@google.com    }
165112853Sgabeblack@google.com    friend sc_unsigned
165212853Sgabeblack@google.com    operator >> (const sc_unsigned &u, unsigned int v)
165312853Sgabeblack@google.com    {
165412853Sgabeblack@google.com        return operator >> (u, (unsigned long)v);
165512853Sgabeblack@google.com    }
165612853Sgabeblack@google.com
165712853Sgabeblack@google.com    const sc_unsigned &operator >>= (const sc_signed &v);
165812853Sgabeblack@google.com    const sc_unsigned &operator >>= (const sc_unsigned &v);
165912853Sgabeblack@google.com    const sc_unsigned &operator >>= (int64 v);
166012853Sgabeblack@google.com    const sc_unsigned &operator >>= (uint64 v);
166112853Sgabeblack@google.com    const sc_unsigned &operator >>= (long v);
166212853Sgabeblack@google.com    const sc_unsigned &operator >>= (unsigned long v);
166312853Sgabeblack@google.com    const sc_unsigned &operator >>= (int v) { return operator >>= ((long)v); }
166412853Sgabeblack@google.com    const sc_unsigned &
166512853Sgabeblack@google.com    operator >>= (unsigned int v)
166612853Sgabeblack@google.com    {
166712853Sgabeblack@google.com        return operator >>= ((unsigned long)v);
166812853Sgabeblack@google.com    }
166912853Sgabeblack@google.com
167012853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned &, const sc_uint_base &);
167112853Sgabeblack@google.com    friend sc_unsigned operator >> (const sc_unsigned&, const sc_int_base &);
167212853Sgabeblack@google.com    const sc_unsigned &operator >>= (const sc_int_base &v);
167312853Sgabeblack@google.com    const sc_unsigned &operator >>= (const sc_uint_base &v);
167412853Sgabeblack@google.com
167512853Sgabeblack@google.com    // Unary arithmetic operators
167612853Sgabeblack@google.com    friend sc_unsigned operator + (const sc_unsigned &u);
167712853Sgabeblack@google.com    friend sc_signed operator - (const sc_unsigned &u);
167812853Sgabeblack@google.com
167912853Sgabeblack@google.com    // LOGICAL OPERATORS:
168012853Sgabeblack@google.com
168112853Sgabeblack@google.com    // Logical EQUAL operators:
168212853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, const sc_signed &v);
168312853Sgabeblack@google.com    friend bool operator == (const sc_signed &u, const sc_unsigned &v);
168412853Sgabeblack@google.com
168512853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, const sc_unsigned &v);
168612853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, int64 v);
168712853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, uint64 v);
168812853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, long v);
168912853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, unsigned long v);
169012853Sgabeblack@google.com    friend bool
169112853Sgabeblack@google.com    operator == (const sc_unsigned &u, int v)
169212853Sgabeblack@google.com    {
169312853Sgabeblack@google.com        return operator == (u, (long)v);
169412853Sgabeblack@google.com    }
169512853Sgabeblack@google.com    friend bool
169612853Sgabeblack@google.com    operator == (const sc_unsigned &u, unsigned int v)
169712853Sgabeblack@google.com    {
169812853Sgabeblack@google.com        return operator == (u, (unsigned long)v);
169912853Sgabeblack@google.com    }
170012853Sgabeblack@google.com
170112853Sgabeblack@google.com    friend bool operator == (int64 u, const sc_unsigned &v);
170212853Sgabeblack@google.com    friend bool operator == (uint64 u, const sc_unsigned &v);
170312853Sgabeblack@google.com    friend bool operator == (long u, const sc_unsigned &v);
170412853Sgabeblack@google.com    friend bool operator == (unsigned long u, const sc_unsigned &v);
170512853Sgabeblack@google.com    friend bool
170612853Sgabeblack@google.com    operator == (int u, const sc_unsigned &v)
170712853Sgabeblack@google.com    {
170812853Sgabeblack@google.com        return operator == ((long)u, v);
170912853Sgabeblack@google.com    }
171012853Sgabeblack@google.com    friend bool
171112853Sgabeblack@google.com    operator == (unsigned int u, const sc_unsigned &v)
171212853Sgabeblack@google.com    {
171312853Sgabeblack@google.com        return operator == ((unsigned long)u, v);
171412853Sgabeblack@google.com    }
171512853Sgabeblack@google.com
171612853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, const sc_uint_base &v);
171712853Sgabeblack@google.com    friend bool operator == (const sc_unsigned &u, const sc_int_base &v);
171812853Sgabeblack@google.com    friend bool operator == (const sc_uint_base &u, const sc_unsigned &v);
171912853Sgabeblack@google.com    friend bool operator == (const sc_int_base &u, const sc_unsigned &v);
172012853Sgabeblack@google.com
172112853Sgabeblack@google.com    // Logical NOT_EQUAL operators:
172212853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, const sc_signed &v);
172312853Sgabeblack@google.com    friend bool operator != (const sc_signed &u, const sc_unsigned &v);
172412853Sgabeblack@google.com
172512853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, const sc_unsigned &v);
172612853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, int64 v);
172712853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, uint64 v);
172812853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, long v);
172912853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, unsigned long v);
173012853Sgabeblack@google.com    friend bool
173112853Sgabeblack@google.com    operator != (const sc_unsigned &u, int v)
173212853Sgabeblack@google.com    {
173312853Sgabeblack@google.com        return operator != (u, (long)v);
173412853Sgabeblack@google.com    }
173512853Sgabeblack@google.com    friend bool
173612853Sgabeblack@google.com    operator != (const sc_unsigned &u, unsigned int v)
173712853Sgabeblack@google.com    {
173812853Sgabeblack@google.com        return operator != (u, (unsigned long)v);
173912853Sgabeblack@google.com    }
174012853Sgabeblack@google.com
174112853Sgabeblack@google.com    friend bool operator != (int64 u, const sc_unsigned &v);
174212853Sgabeblack@google.com    friend bool operator != (uint64 u, const sc_unsigned &v);
174312853Sgabeblack@google.com    friend bool operator != (long u, const sc_unsigned &v);
174412853Sgabeblack@google.com    friend bool operator != (unsigned long u, const sc_unsigned &v);
174512853Sgabeblack@google.com    friend bool
174612853Sgabeblack@google.com    operator != (int u, const sc_unsigned &v)
174712853Sgabeblack@google.com    {
174812853Sgabeblack@google.com        return operator != ((long)u, v);
174912853Sgabeblack@google.com    }
175012853Sgabeblack@google.com    friend bool
175112853Sgabeblack@google.com    operator != (unsigned int u, const sc_unsigned &v)
175212853Sgabeblack@google.com    {
175312853Sgabeblack@google.com        return operator != ((unsigned long)u, v);
175412853Sgabeblack@google.com    }
175512853Sgabeblack@google.com
175612853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, const sc_uint_base &v);
175712853Sgabeblack@google.com    friend bool operator != (const sc_unsigned &u, const sc_int_base &v);
175812853Sgabeblack@google.com    friend bool operator != (const sc_uint_base &u, const sc_unsigned &v);
175912853Sgabeblack@google.com    friend bool operator != (const sc_int_base &u, const sc_unsigned &v);
176012853Sgabeblack@google.com
176112853Sgabeblack@google.com    // Logical LESS_THAN operators:
176212853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, const sc_signed &v);
176312853Sgabeblack@google.com    friend bool operator < (const sc_signed &u, const sc_unsigned &v);
176412853Sgabeblack@google.com
176512853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, const sc_unsigned &v);
176612853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, int64 v);
176712853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, uint64 v);
176812853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, long v);
176912853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, unsigned long v);
177012853Sgabeblack@google.com    friend bool
177112853Sgabeblack@google.com    operator < (const sc_unsigned &u, int v)
177212853Sgabeblack@google.com    {
177312853Sgabeblack@google.com        return operator < (u, (long)v);
177412853Sgabeblack@google.com    }
177512853Sgabeblack@google.com    friend bool
177612853Sgabeblack@google.com    operator < (const sc_unsigned &u, unsigned int v)
177712853Sgabeblack@google.com    {
177812853Sgabeblack@google.com        return operator < (u, (unsigned long)v);
177912853Sgabeblack@google.com    }
178012853Sgabeblack@google.com
178112853Sgabeblack@google.com    friend bool operator < (int64 u, const sc_unsigned &v);
178212853Sgabeblack@google.com    friend bool operator < (uint64 u, const sc_unsigned &v);
178312853Sgabeblack@google.com    friend bool operator < (long u, const sc_unsigned &v);
178412853Sgabeblack@google.com    friend bool operator < (unsigned long u, const sc_unsigned &v);
178512853Sgabeblack@google.com    friend bool
178612853Sgabeblack@google.com    operator < (int u, const sc_unsigned &v)
178712853Sgabeblack@google.com    {
178812853Sgabeblack@google.com        return operator < ((long)u, v);
178912853Sgabeblack@google.com    }
179012853Sgabeblack@google.com    friend bool
179112853Sgabeblack@google.com    operator < (unsigned int u, const sc_unsigned &v)
179212853Sgabeblack@google.com    {
179312853Sgabeblack@google.com        return operator < ((unsigned long)u, v);
179412853Sgabeblack@google.com    }
179512853Sgabeblack@google.com
179612853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, const sc_uint_base &v);
179712853Sgabeblack@google.com    friend bool operator < (const sc_unsigned &u, const sc_int_base &v);
179812853Sgabeblack@google.com    friend bool operator < (const sc_uint_base &u, const sc_unsigned &v);
179912853Sgabeblack@google.com    friend bool operator < (const sc_int_base &u, const sc_unsigned &v);
180012853Sgabeblack@google.com
180112853Sgabeblack@google.com    // Logical LESS_THAN_AND_EQUAL operators:
180212853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, const sc_signed &v);
180312853Sgabeblack@google.com    friend bool operator <= (const sc_signed &u, const sc_unsigned &v);
180412853Sgabeblack@google.com
180512853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, const sc_unsigned &v);
180612853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, int64 v);
180712853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, uint64 v);
180812853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, long v);
180912853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, unsigned long v);
181012853Sgabeblack@google.com    friend bool
181112853Sgabeblack@google.com    operator <= (const sc_unsigned &u, int v)
181212853Sgabeblack@google.com    {
181312853Sgabeblack@google.com        return operator <= (u, (long)v);
181412853Sgabeblack@google.com    }
181512853Sgabeblack@google.com    friend bool
181612853Sgabeblack@google.com    operator <= (const sc_unsigned &u, unsigned int v)
181712853Sgabeblack@google.com    {
181812853Sgabeblack@google.com        return operator <= (u, (unsigned long)v);
181912853Sgabeblack@google.com    }
182012853Sgabeblack@google.com
182112853Sgabeblack@google.com    friend bool operator <= (int64 u, const sc_unsigned &v);
182212853Sgabeblack@google.com    friend bool operator <= (uint64 u, const sc_unsigned &v);
182312853Sgabeblack@google.com    friend bool operator <= (long u, const sc_unsigned &v);
182412853Sgabeblack@google.com    friend bool operator <= (unsigned long u, const sc_unsigned &v);
182512853Sgabeblack@google.com    friend bool
182612853Sgabeblack@google.com    operator <= (int u, const sc_unsigned &v)
182712853Sgabeblack@google.com    {
182812853Sgabeblack@google.com        return operator <= ((long)u, v);
182912853Sgabeblack@google.com    }
183012853Sgabeblack@google.com    friend bool
183112853Sgabeblack@google.com    operator <= (unsigned int u, const sc_unsigned &v)
183212853Sgabeblack@google.com    {
183312853Sgabeblack@google.com        return operator <= ((unsigned long)u, v);
183412853Sgabeblack@google.com    }
183512853Sgabeblack@google.com
183612853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, const sc_uint_base &v);
183712853Sgabeblack@google.com    friend bool operator <= (const sc_unsigned &u, const sc_int_base &v);
183812853Sgabeblack@google.com    friend bool operator <= (const sc_uint_base &u, const sc_unsigned &v);
183912853Sgabeblack@google.com    friend bool operator <= (const sc_int_base &u, const sc_unsigned &v);
184012853Sgabeblack@google.com
184112853Sgabeblack@google.com    // Logical GREATER_THAN operators:
184212853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, const sc_signed &v);
184312853Sgabeblack@google.com    friend bool operator > (const sc_signed &u, const sc_unsigned &v);
184412853Sgabeblack@google.com
184512853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, const sc_unsigned &v);
184612853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, int64 v);
184712853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, uint64 v);
184812853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, long v);
184912853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, unsigned long v);
185012853Sgabeblack@google.com    friend bool
185112853Sgabeblack@google.com    operator > (const sc_unsigned &u, int v)
185212853Sgabeblack@google.com    {
185312853Sgabeblack@google.com        return operator > (u, (long)v);
185412853Sgabeblack@google.com    }
185512853Sgabeblack@google.com    friend bool
185612853Sgabeblack@google.com    operator > (const sc_unsigned &u, unsigned int v)
185712853Sgabeblack@google.com    {
185812853Sgabeblack@google.com        return operator > (u, (unsigned long)v);
185912853Sgabeblack@google.com    }
186012853Sgabeblack@google.com
186112853Sgabeblack@google.com    friend bool operator > (int64 u, const sc_unsigned &v);
186212853Sgabeblack@google.com    friend bool operator > (uint64 u, const sc_unsigned &v);
186312853Sgabeblack@google.com    friend bool operator > (long u, const sc_unsigned &v);
186412853Sgabeblack@google.com    friend bool operator > (unsigned long u, const sc_unsigned &v);
186512853Sgabeblack@google.com    friend bool
186612853Sgabeblack@google.com    operator > (int u, const sc_unsigned &v)
186712853Sgabeblack@google.com    {
186812853Sgabeblack@google.com        return operator > ((long)u, v);
186912853Sgabeblack@google.com    }
187012853Sgabeblack@google.com    friend bool
187112853Sgabeblack@google.com    operator > (unsigned int u, const sc_unsigned &v)
187212853Sgabeblack@google.com    {
187312853Sgabeblack@google.com        return operator > ((unsigned long)u, v);
187412853Sgabeblack@google.com    }
187512853Sgabeblack@google.com
187612853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, const sc_uint_base &v);
187712853Sgabeblack@google.com    friend bool operator > (const sc_unsigned &u, const sc_int_base &v);
187812853Sgabeblack@google.com    friend bool operator > (const sc_uint_base &u, const sc_unsigned &v);
187912853Sgabeblack@google.com    friend bool operator > (const sc_int_base &u, const sc_unsigned &v);
188012853Sgabeblack@google.com
188112853Sgabeblack@google.com    // Logical GREATER_THAN_AND_EQUAL operators:
188212853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, const sc_signed &v);
188312853Sgabeblack@google.com    friend bool operator >= (const sc_signed &u, const sc_unsigned &v);
188412853Sgabeblack@google.com
188512853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, const sc_unsigned &v);
188612853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, int64 v);
188712853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, uint64 v);
188812853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, long v);
188912853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, unsigned long v);
189012853Sgabeblack@google.com    friend bool
189112853Sgabeblack@google.com    operator >= (const sc_unsigned &u, int v)
189212853Sgabeblack@google.com    {
189312853Sgabeblack@google.com        return operator >= (u, (long)v);
189412853Sgabeblack@google.com    }
189512853Sgabeblack@google.com    friend bool
189612853Sgabeblack@google.com    operator >= (const sc_unsigned &u, unsigned int v)
189712853Sgabeblack@google.com    {
189812853Sgabeblack@google.com        return operator >= (u, (unsigned long)v);
189912853Sgabeblack@google.com    }
190012853Sgabeblack@google.com
190112853Sgabeblack@google.com    friend bool operator >= (int64 u, const sc_unsigned &v);
190212853Sgabeblack@google.com    friend bool operator >= (uint64 u, const sc_unsigned &v);
190312853Sgabeblack@google.com    friend bool operator >= (long u, const sc_unsigned &v);
190412853Sgabeblack@google.com    friend bool operator >= (unsigned long u, const sc_unsigned &v);
190512853Sgabeblack@google.com    friend bool
190612853Sgabeblack@google.com    operator >= (int u, const sc_unsigned &v)
190712853Sgabeblack@google.com    {
190812853Sgabeblack@google.com        return operator >= ((long)u, v);
190912853Sgabeblack@google.com    }
191012853Sgabeblack@google.com    friend bool
191112853Sgabeblack@google.com    operator >= (unsigned int u, const sc_unsigned &v)
191212853Sgabeblack@google.com    {
191312853Sgabeblack@google.com        return operator >= ((unsigned long)u, v);
191412853Sgabeblack@google.com    }
191512853Sgabeblack@google.com
191612853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, const sc_uint_base &v);
191712853Sgabeblack@google.com    friend bool operator >= (const sc_unsigned &u, const sc_int_base &v);
191812853Sgabeblack@google.com    friend bool operator >= (const sc_uint_base &u, const sc_unsigned &v);
191912853Sgabeblack@google.com    friend bool operator >= (const sc_int_base &u, const sc_unsigned &v);
192012853Sgabeblack@google.com
192112853Sgabeblack@google.com    // Bitwise NOT operator (unary).
192212853Sgabeblack@google.com    friend sc_unsigned operator ~ (const sc_unsigned &u);
192312853Sgabeblack@google.com
192412853Sgabeblack@google.com    // Helper functions.
192512853Sgabeblack@google.com    friend int compare_unsigned(
192612853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
192712853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd,
192812853Sgabeblack@google.com            small_type if_u_signed, small_type if_v_signed);
192912853Sgabeblack@google.com
193012853Sgabeblack@google.com    friend sc_unsigned add_unsigned_friend(
193112853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
193212853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd);
193312853Sgabeblack@google.com
193412853Sgabeblack@google.com    friend sc_unsigned sub_unsigned_friend(
193512853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
193612853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd);
193712853Sgabeblack@google.com
193812853Sgabeblack@google.com    friend sc_unsigned mul_unsigned_friend(
193912853Sgabeblack@google.com            small_type s, int unb, int und, const sc_digit *ud,
194012853Sgabeblack@google.com            int vnb, int vnd, const sc_digit *vd);
194112853Sgabeblack@google.com
194212853Sgabeblack@google.com    friend sc_unsigned div_unsigned_friend(
194312853Sgabeblack@google.com            small_type s, int unb, int und, const sc_digit *ud,
194412853Sgabeblack@google.com            int vnb, int vnd, const sc_digit *vd);
194512853Sgabeblack@google.com
194612853Sgabeblack@google.com    friend sc_unsigned mod_unsigned_friend(
194712853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
194812853Sgabeblack@google.com            int vnb, int vnd, const sc_digit *vd);
194912853Sgabeblack@google.com
195012853Sgabeblack@google.com    friend sc_unsigned and_unsigned_friend(
195112853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
195212853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd);
195312853Sgabeblack@google.com
195412853Sgabeblack@google.com    friend sc_unsigned or_unsigned_friend(
195512853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
195612853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd);
195712853Sgabeblack@google.com
195812853Sgabeblack@google.com    friend sc_unsigned xor_unsigned_friend(
195912853Sgabeblack@google.com            small_type us, int unb, int und, const sc_digit *ud,
196012853Sgabeblack@google.com            small_type vs, int vnb, int vnd, const sc_digit *vd);
196112853Sgabeblack@google.com
196212853Sgabeblack@google.com  public:
196312853Sgabeblack@google.com    static sc_core::sc_vpool<sc_unsigned> m_pool;
196412853Sgabeblack@google.com
196512853Sgabeblack@google.com  private:
196612853Sgabeblack@google.com    small_type sgn; // Shortened as s.
196712853Sgabeblack@google.com    int nbits; // Shortened as nb.
196812853Sgabeblack@google.com    int ndigits; // Shortened as nd.
196912853Sgabeblack@google.com
197012853Sgabeblack@google.com#ifdef SC_MAX_NBITS
197112853Sgabeblack@google.com    sc_digit digit[DIV_CEIL(SC_MAX_NBITS)]; // Shortened as d.
197212853Sgabeblack@google.com#else
197312853Sgabeblack@google.com    sc_digit *digit; // Shortened as d.
197412853Sgabeblack@google.com#endif
197512853Sgabeblack@google.com
197612853Sgabeblack@google.com    // Private constructors:
197712853Sgabeblack@google.com
197812853Sgabeblack@google.com    // Create a copy of v with sign s.
197912853Sgabeblack@google.com    sc_unsigned(const sc_unsigned &v, small_type s);
198012853Sgabeblack@google.com    sc_unsigned(const sc_signed &v, small_type s);
198112853Sgabeblack@google.com
198212853Sgabeblack@google.com    // Create an unsigned number with the given attributes.
198312853Sgabeblack@google.com    sc_unsigned(small_type s, int nb, int nd, sc_digit *d, bool alloc=true);
198412853Sgabeblack@google.com
198512853Sgabeblack@google.com    // Create an unsigned number using the bits u[l..r].
198612853Sgabeblack@google.com    sc_unsigned(const sc_signed *u, int l, int r);
198712853Sgabeblack@google.com    sc_unsigned(const sc_unsigned *u, int l, int r);
198812853Sgabeblack@google.com
198912853Sgabeblack@google.com    // Private member functions. The called functions are inline functions.
199012853Sgabeblack@google.com
199112853Sgabeblack@google.com    small_type default_sign() const { return SC_POS; }
199212853Sgabeblack@google.com
199312853Sgabeblack@google.com    int num_bits(int nb) const { return nb + 1; }
199412853Sgabeblack@google.com
199512853Sgabeblack@google.com    bool check_if_outside(int bit_num) const;
199612853Sgabeblack@google.com
199712853Sgabeblack@google.com    void
199812853Sgabeblack@google.com    copy_digits(int nb, int nd, const sc_digit *d)
199912853Sgabeblack@google.com    {
200012853Sgabeblack@google.com        copy_digits_unsigned(sgn, nbits, ndigits, digit, nb, nd, d);
200112853Sgabeblack@google.com    }
200212853Sgabeblack@google.com
200312853Sgabeblack@google.com    void makezero() { sgn = make_zero(ndigits, digit); }
200412853Sgabeblack@google.com
200512853Sgabeblack@google.com    // Conversion functions between 2's complement (2C) and
200612853Sgabeblack@google.com    // sign-magnitude (SM):
200712853Sgabeblack@google.com    void
200812853Sgabeblack@google.com    convert_2C_to_SM()
200912853Sgabeblack@google.com    {
201012853Sgabeblack@google.com        sgn = convert_unsigned_2C_to_SM(nbits, ndigits, digit);
201112853Sgabeblack@google.com    }
201212853Sgabeblack@google.com
201312853Sgabeblack@google.com    void
201412853Sgabeblack@google.com    convert_SM_to_2C_to_SM()
201512853Sgabeblack@google.com    {
201612853Sgabeblack@google.com        sgn = convert_unsigned_SM_to_2C_to_SM(sgn, nbits, ndigits, digit);
201712853Sgabeblack@google.com    }
201812853Sgabeblack@google.com
201912853Sgabeblack@google.com    void convert_SM_to_2C() { convert_unsigned_SM_to_2C(sgn, ndigits, digit); }
202012853Sgabeblack@google.com};
202112853Sgabeblack@google.com
202212853Sgabeblack@google.cominline ::std::ostream &operator << (::std::ostream &, const sc_unsigned &);
202312853Sgabeblack@google.com
202412853Sgabeblack@google.cominline ::std::istream &operator >> (::std::istream &, sc_unsigned &);
202512853Sgabeblack@google.com
202612853Sgabeblack@google.com
202712853Sgabeblack@google.com// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
202812853Sgabeblack@google.com
202912853Sgabeblack@google.com// ----------------------------------------------------------------------------
203012853Sgabeblack@google.com//  CLASS : sc_unsigned_bitref_r
203112853Sgabeblack@google.com//
203212853Sgabeblack@google.com//  Proxy class for sc_unsigned bit selection (r-value only).
203312853Sgabeblack@google.com// ----------------------------------------------------------------------------
203412853Sgabeblack@google.com
203512853Sgabeblack@google.com
203612853Sgabeblack@google.cominline ::std::ostream &
203712853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_unsigned_bitref_r &a)
203812853Sgabeblack@google.com{
203912853Sgabeblack@google.com    a.print(os);
204012853Sgabeblack@google.com    return os;
204112853Sgabeblack@google.com}
204212853Sgabeblack@google.com
204312853Sgabeblack@google.com
204412853Sgabeblack@google.com// ----------------------------------------------------------------------------
204512853Sgabeblack@google.com//  CLASS : sc_unsigned_bitref
204612853Sgabeblack@google.com//
204712853Sgabeblack@google.com//  Proxy class for sc_unsigned bit selection (r-value and l-value).
204812853Sgabeblack@google.com// ----------------------------------------------------------------------------
204912853Sgabeblack@google.com
205012853Sgabeblack@google.comtemplate<class T>
205112853Sgabeblack@google.cominline const sc_unsigned_subref &
205212853Sgabeblack@google.comsc_unsigned_subref::operator = (const sc_generic_base<T> &a)
205312853Sgabeblack@google.com{
205412853Sgabeblack@google.com    sc_unsigned temp(length());
205512853Sgabeblack@google.com    a->to_sc_unsigned(temp);
205612853Sgabeblack@google.com    return *this = temp;
205712853Sgabeblack@google.com}
205812853Sgabeblack@google.com
205912853Sgabeblack@google.cominline ::std::istream &
206012853Sgabeblack@google.comoperator >> (::std::istream &is, sc_unsigned_bitref &a)
206112853Sgabeblack@google.com{
206212853Sgabeblack@google.com    a.scan(is);
206312853Sgabeblack@google.com    return is;
206412853Sgabeblack@google.com}
206512853Sgabeblack@google.com
206612853Sgabeblack@google.com
206712853Sgabeblack@google.com// ----------------------------------------------------------------------------
206812853Sgabeblack@google.com//  CLASS : sc_unsigned_subref_r
206912853Sgabeblack@google.com//
207012853Sgabeblack@google.com//  Proxy class for sc_unsigned part selection (r-value only).
207112853Sgabeblack@google.com// ----------------------------------------------------------------------------
207212853Sgabeblack@google.com
207312853Sgabeblack@google.com// reduce methods
207412853Sgabeblack@google.com
207512853Sgabeblack@google.cominline bool
207612853Sgabeblack@google.comsc_unsigned_subref_r::and_reduce() const
207712853Sgabeblack@google.com{
207812853Sgabeblack@google.com    const sc_unsigned *target_p = m_obj_p;
207912853Sgabeblack@google.com    for (int i = m_right; i <= m_left; i++)
208012853Sgabeblack@google.com        if (!target_p->test(i))
208112853Sgabeblack@google.com            return false;
208212853Sgabeblack@google.com    return true;
208312853Sgabeblack@google.com}
208412853Sgabeblack@google.com
208512853Sgabeblack@google.cominline bool
208612853Sgabeblack@google.comsc_unsigned_subref_r::nand_reduce() const
208712853Sgabeblack@google.com{
208812853Sgabeblack@google.com    return !and_reduce();
208912853Sgabeblack@google.com}
209012853Sgabeblack@google.com
209112853Sgabeblack@google.cominline bool
209212853Sgabeblack@google.comsc_unsigned_subref_r::or_reduce() const
209312853Sgabeblack@google.com{
209412853Sgabeblack@google.com    const sc_unsigned *target_p = m_obj_p;
209512853Sgabeblack@google.com    for (int i = m_right; i <= m_left; i++)
209612853Sgabeblack@google.com        if (target_p->test(i))
209712853Sgabeblack@google.com            return true;
209812853Sgabeblack@google.com    return false;
209912853Sgabeblack@google.com}
210012853Sgabeblack@google.com
210112853Sgabeblack@google.cominline bool
210212853Sgabeblack@google.comsc_unsigned_subref_r::nor_reduce() const
210312853Sgabeblack@google.com{
210412853Sgabeblack@google.com    return !or_reduce();
210512853Sgabeblack@google.com}
210612853Sgabeblack@google.com
210712853Sgabeblack@google.cominline bool
210812853Sgabeblack@google.comsc_unsigned_subref_r::xor_reduce() const
210912853Sgabeblack@google.com{
211012853Sgabeblack@google.com    int odd;
211112853Sgabeblack@google.com    const sc_unsigned *target_p = m_obj_p;
211212853Sgabeblack@google.com    odd = 0;
211312853Sgabeblack@google.com    for (int i = m_right; i <= m_left; i++)
211412853Sgabeblack@google.com        if (target_p->test(i)) odd = ~odd;
211512853Sgabeblack@google.com    return odd ? true : false;
211612853Sgabeblack@google.com}
211712853Sgabeblack@google.com
211812853Sgabeblack@google.cominline bool sc_unsigned_subref_r::xnor_reduce() const { return !xor_reduce(); }
211912853Sgabeblack@google.com
212012853Sgabeblack@google.cominline ::std::ostream &
212112853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_unsigned_subref_r &a)
212212853Sgabeblack@google.com{
212312853Sgabeblack@google.com    a.print(os);
212412853Sgabeblack@google.com    return os;
212512853Sgabeblack@google.com}
212612853Sgabeblack@google.com
212712853Sgabeblack@google.com
212812853Sgabeblack@google.com// ----------------------------------------------------------------------------
212912853Sgabeblack@google.com//  CLASS : sc_unsigned_subref
213012853Sgabeblack@google.com//
213112853Sgabeblack@google.com//  Proxy class for sc_unsigned part selection (r-value and l-value).
213212853Sgabeblack@google.com// ----------------------------------------------------------------------------
213312853Sgabeblack@google.com
213412853Sgabeblack@google.com// assignment operators
213512853Sgabeblack@google.com
213612853Sgabeblack@google.cominline const sc_unsigned_subref &
213712853Sgabeblack@google.comsc_unsigned_subref::operator = (const char *a)
213812853Sgabeblack@google.com{
213912853Sgabeblack@google.com    sc_unsigned aa(length());
214012853Sgabeblack@google.com    return (*this = aa = a);
214112853Sgabeblack@google.com}
214212853Sgabeblack@google.com
214312853Sgabeblack@google.com
214412853Sgabeblack@google.cominline ::std::istream &
214512853Sgabeblack@google.comoperator >> (::std::istream &is, sc_unsigned_subref &a)
214612853Sgabeblack@google.com{
214712853Sgabeblack@google.com    a.scan(is);
214812853Sgabeblack@google.com    return is;
214912853Sgabeblack@google.com}
215012853Sgabeblack@google.com
215112853Sgabeblack@google.com
215212853Sgabeblack@google.com// ----------------------------------------------------------------------------
215312853Sgabeblack@google.com//  CLASS : sc_unsigned
215412853Sgabeblack@google.com//
215512853Sgabeblack@google.com//  Arbitrary precision signed number.
215612853Sgabeblack@google.com// ----------------------------------------------------------------------------
215712853Sgabeblack@google.com
215812853Sgabeblack@google.comtemplate<class T>
215912853Sgabeblack@google.comsc_unsigned::sc_unsigned( const sc_generic_base<T> &v)
216012853Sgabeblack@google.com{
216112853Sgabeblack@google.com    int nb = v->length();
216212853Sgabeblack@google.com    sgn = default_sign();
216312853Sgabeblack@google.com    if (nb > 0) {
216412853Sgabeblack@google.com        nbits = num_bits(nb);
216512853Sgabeblack@google.com    } else {
216612853Sgabeblack@google.com        invalid_init("sc_generic_base<T>", nb);
216712853Sgabeblack@google.com        sc_core::sc_abort(); // can't recover from here
216812853Sgabeblack@google.com    }
216912853Sgabeblack@google.com    ndigits = DIV_CEIL(nbits);
217012853Sgabeblack@google.com#   ifdef SC_MAX_NBITS
217112853Sgabeblack@google.com        test_bound(nb);
217212853Sgabeblack@google.com#   else
217312853Sgabeblack@google.com        digit = new sc_digit[ndigits];
217412853Sgabeblack@google.com#   endif
217512853Sgabeblack@google.com    makezero();
217612853Sgabeblack@google.com    v->to_sc_unsigned(*this);
217712853Sgabeblack@google.com}
217812853Sgabeblack@google.com
217912853Sgabeblack@google.cominline ::std::ostream &
218012853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_unsigned &a)
218112853Sgabeblack@google.com{
218212853Sgabeblack@google.com    a.print(os);
218312853Sgabeblack@google.com    return os;
218412853Sgabeblack@google.com}
218512853Sgabeblack@google.com
218612853Sgabeblack@google.cominline ::std::istream &
218712853Sgabeblack@google.comoperator >> (::std::istream &is, sc_unsigned &a)
218812853Sgabeblack@google.com{
218912853Sgabeblack@google.com    a.scan(is);
219012853Sgabeblack@google.com    return is;
219112853Sgabeblack@google.com}
219212853Sgabeblack@google.com
219312853Sgabeblack@google.com} // namespace sc_dt
219412853Sgabeblack@google.com
219512853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_INT_SC_UNSIGNED_HH__
2196