sc_fxnum.hh revision 13245
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_fxnum.h - 2312853Sgabeblack@google.com 2412853Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc. 2512853Sgabeblack@google.com 2612853Sgabeblack@google.com *****************************************************************************/ 2712853Sgabeblack@google.com 2812853Sgabeblack@google.com/***************************************************************************** 2912853Sgabeblack@google.com 3012853Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112853Sgabeblack@google.com changes you are making here. 3212853Sgabeblack@google.com 3312853Sgabeblack@google.com Name, Affiliation, Date: 3412853Sgabeblack@google.com Description of Modification: 3512853Sgabeblack@google.com 3612853Sgabeblack@google.com *****************************************************************************/ 3712853Sgabeblack@google.com 3812853Sgabeblack@google.com// $Log: sc_fxnum.h,v $ 3912853Sgabeblack@google.com// Revision 1.5 2011/08/29 18:04:32 acg 4012853Sgabeblack@google.com// Philipp A. Hartmann: miscellaneous clean ups. 4112853Sgabeblack@google.com// 4212853Sgabeblack@google.com// Revision 1.4 2011/08/24 22:05:43 acg 4312853Sgabeblack@google.com// Torsten Maehne: initialization changes to remove warnings. 4412853Sgabeblack@google.com// 4512853Sgabeblack@google.com// Revision 1.3 2011/01/19 18:57:40 acg 4612853Sgabeblack@google.com// Andy Goodrich: changes for IEEE_1666_2011. 4712853Sgabeblack@google.com// 4812853Sgabeblack@google.com// Revision 1.2 2009/03/09 17:26:46 acg 4912853Sgabeblack@google.com// Andy Goodrich: removed ; from namespace { } 5012853Sgabeblack@google.com// 5112853Sgabeblack@google.com// Revision 1.1.1.1 2006/12/15 20:20:04 acg 5212853Sgabeblack@google.com// SystemC 2.3 5312853Sgabeblack@google.com// 5412853Sgabeblack@google.com// Revision 1.3 2006/01/13 18:53:58 acg 5512853Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in 5612853Sgabeblack@google.com// the source. 5712853Sgabeblack@google.com// 5812853Sgabeblack@google.com 5912853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_FX_SC_FXNUM_HH__ 6012853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_FX_SC_FXNUM_HH__ 6112853Sgabeblack@google.com 6212853Sgabeblack@google.com#include <iostream> 6312853Sgabeblack@google.com 6412853Sgabeblack@google.com#include "../bit/sc_lv_base.hh" 6512853Sgabeblack@google.com#include "sc_fxnum_observer.hh" 6612853Sgabeblack@google.com#include "sc_fxval.hh" 6712853Sgabeblack@google.com#include "scfx_params.hh" 6812853Sgabeblack@google.com 6913245Sgabeblack@google.comnamespace sc_gem5 7012853Sgabeblack@google.com{ 7112853Sgabeblack@google.com 7213245Sgabeblack@google.comtemplate <typename T, typename B> 7313245Sgabeblack@google.comclass TraceValFxnumBase; 7412853Sgabeblack@google.com 7512853Sgabeblack@google.com} // namespace sc_core 7612853Sgabeblack@google.com 7712853Sgabeblack@google.com 7812853Sgabeblack@google.comnamespace sc_dt 7912853Sgabeblack@google.com{ 8012853Sgabeblack@google.com 8112853Sgabeblack@google.com// classes defined in this module 8212853Sgabeblack@google.comclass sc_fxnum_bitref; 8312853Sgabeblack@google.comclass sc_fxnum_fast_bitref; 8412853Sgabeblack@google.comclass sc_fxnum_subref; 8512853Sgabeblack@google.comclass sc_fxnum_fast_subref; 8612853Sgabeblack@google.comclass sc_fxnum; 8712853Sgabeblack@google.comclass sc_fxnum_fast; 8812853Sgabeblack@google.com 8912853Sgabeblack@google.com 9012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 9112853Sgabeblack@google.com// CLASS : sc_fxnum_bitref 9212853Sgabeblack@google.com// 9312853Sgabeblack@google.com// Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit. 9412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 9512853Sgabeblack@google.com 9612853Sgabeblack@google.comclass sc_fxnum_bitref 9712853Sgabeblack@google.com{ 9812853Sgabeblack@google.com friend class sc_fxnum; 9912853Sgabeblack@google.com friend class sc_fxnum_fast_bitref; 10012853Sgabeblack@google.com 10112853Sgabeblack@google.com bool get() const; 10212853Sgabeblack@google.com void set(bool); 10312853Sgabeblack@google.com 10412853Sgabeblack@google.com // constructor 10512853Sgabeblack@google.com sc_fxnum_bitref(sc_fxnum &, int); 10612853Sgabeblack@google.com 10712853Sgabeblack@google.com public: 10812853Sgabeblack@google.com // copy constructor 10912853Sgabeblack@google.com sc_fxnum_bitref(const sc_fxnum_bitref &); 11012853Sgabeblack@google.com 11112853Sgabeblack@google.com // assignment operators 11212853Sgabeblack@google.com#define DECL_ASN_OP_T(op, tp) \ 11312853Sgabeblack@google.com sc_fxnum_bitref &operator op (tp); 11412853Sgabeblack@google.com 11512853Sgabeblack@google.com#define DECL_ASN_OP(op) \ 11612853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_bitref &) \ 11712853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_fast_bitref &) \ 11812853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_bit &) \ 11912853Sgabeblack@google.com DECL_ASN_OP_T(op, bool) 12012853Sgabeblack@google.com 12112853Sgabeblack@google.com DECL_ASN_OP(=) 12212853Sgabeblack@google.com 12312853Sgabeblack@google.com DECL_ASN_OP(&=) 12412853Sgabeblack@google.com DECL_ASN_OP(|=) 12512853Sgabeblack@google.com DECL_ASN_OP(^=) 12612853Sgabeblack@google.com 12712853Sgabeblack@google.com#undef DECL_ASN_OP_T 12812853Sgabeblack@google.com#undef DECL_ASN_OP 12912853Sgabeblack@google.com 13012853Sgabeblack@google.com // implicit conversion 13112853Sgabeblack@google.com operator bool() const; 13212853Sgabeblack@google.com 13312853Sgabeblack@google.com // print or dump content 13412853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 13512853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 13612853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 13712853Sgabeblack@google.com 13812853Sgabeblack@google.com private: 13912853Sgabeblack@google.com sc_fxnum &m_num; 14012853Sgabeblack@google.com int m_idx; 14112853Sgabeblack@google.com 14212853Sgabeblack@google.com private: 14312853Sgabeblack@google.com // disabled 14412853Sgabeblack@google.com sc_fxnum_bitref(); 14512853Sgabeblack@google.com}; 14612853Sgabeblack@google.com 14712853Sgabeblack@google.com 14812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 14912853Sgabeblack@google.com// CLASS : sc_fxnum_fast_bitref 15012853Sgabeblack@google.com// 15112853Sgabeblack@google.com// Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit. 15212853Sgabeblack@google.com// ---------------------------------------------------------------------------- 15312853Sgabeblack@google.com 15412853Sgabeblack@google.comclass sc_fxnum_fast_bitref 15512853Sgabeblack@google.com{ 15612853Sgabeblack@google.com friend class sc_fxnum_fast; 15712853Sgabeblack@google.com friend class sc_fxnum_bitref; 15812853Sgabeblack@google.com 15912853Sgabeblack@google.com bool get() const; 16012853Sgabeblack@google.com void set(bool); 16112853Sgabeblack@google.com 16212853Sgabeblack@google.com // constructor 16312853Sgabeblack@google.com sc_fxnum_fast_bitref(sc_fxnum_fast &, int); 16412853Sgabeblack@google.com 16512853Sgabeblack@google.com public: 16612853Sgabeblack@google.com // copy constructor 16712853Sgabeblack@google.com sc_fxnum_fast_bitref(const sc_fxnum_fast_bitref &); 16812853Sgabeblack@google.com 16912853Sgabeblack@google.com // assignment operators 17012853Sgabeblack@google.com#define DECL_ASN_OP_T(op, tp) sc_fxnum_fast_bitref &operator op (tp); 17112853Sgabeblack@google.com 17212853Sgabeblack@google.com#define DECL_ASN_OP(op) \ 17312853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_bitref &) \ 17412853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_fast_bitref &) \ 17512853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_bit &) \ 17612853Sgabeblack@google.com DECL_ASN_OP_T(op, bool) 17712853Sgabeblack@google.com 17812853Sgabeblack@google.com DECL_ASN_OP(=) 17912853Sgabeblack@google.com 18012853Sgabeblack@google.com DECL_ASN_OP(&=) 18112853Sgabeblack@google.com DECL_ASN_OP(|=) 18212853Sgabeblack@google.com DECL_ASN_OP(^=) 18312853Sgabeblack@google.com 18412853Sgabeblack@google.com#undef DECL_ASN_OP_T 18512853Sgabeblack@google.com#undef DECL_ASN_OP 18612853Sgabeblack@google.com 18712853Sgabeblack@google.com // implicit conversion 18812853Sgabeblack@google.com operator bool() const; 18912853Sgabeblack@google.com 19012853Sgabeblack@google.com // print or dump content 19112853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 19212853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 19312853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 19412853Sgabeblack@google.com 19512853Sgabeblack@google.com private: 19612853Sgabeblack@google.com sc_fxnum_fast &m_num; 19712853Sgabeblack@google.com int m_idx; 19812853Sgabeblack@google.com 19912853Sgabeblack@google.com private: 20012853Sgabeblack@google.com // Disabled 20112853Sgabeblack@google.com sc_fxnum_fast_bitref(); 20212853Sgabeblack@google.com}; 20312853Sgabeblack@google.com 20412853Sgabeblack@google.com 20512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 20612853Sgabeblack@google.com// CLASS : sc_fxnum_subref 20712853Sgabeblack@google.com// 20812853Sgabeblack@google.com// Proxy class for part-selection in class sc_fxnum, 20912853Sgabeblack@google.com// behaves like sc_bv_base. 21012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 21112853Sgabeblack@google.com 21212853Sgabeblack@google.comclass sc_fxnum_subref 21312853Sgabeblack@google.com{ 21412853Sgabeblack@google.com friend class sc_fxnum; 21512853Sgabeblack@google.com friend class sc_fxnum_fast_subref; 21612853Sgabeblack@google.com 21712853Sgabeblack@google.com bool get() const; 21812853Sgabeblack@google.com bool set(); 21912853Sgabeblack@google.com 22012853Sgabeblack@google.com // constructor 22112853Sgabeblack@google.com sc_fxnum_subref(sc_fxnum &, int, int); 22212853Sgabeblack@google.com 22312853Sgabeblack@google.com public: 22412853Sgabeblack@google.com // copy constructor 22512853Sgabeblack@google.com sc_fxnum_subref(const sc_fxnum_subref &); 22612853Sgabeblack@google.com 22712853Sgabeblack@google.com // destructor 22812853Sgabeblack@google.com ~sc_fxnum_subref(); 22912853Sgabeblack@google.com 23012853Sgabeblack@google.com // assignment operators 23112853Sgabeblack@google.com#define DECL_ASN_OP_T(tp) \ 23212853Sgabeblack@google.com sc_fxnum_subref &operator = (tp); 23312853Sgabeblack@google.com 23412853Sgabeblack@google.com DECL_ASN_OP_T(const sc_fxnum_subref &) 23512853Sgabeblack@google.com DECL_ASN_OP_T(const sc_fxnum_fast_subref &) 23612853Sgabeblack@google.com DECL_ASN_OP_T(const sc_bv_base &) 23712853Sgabeblack@google.com DECL_ASN_OP_T(const sc_lv_base &) 23812853Sgabeblack@google.com DECL_ASN_OP_T(const char *) 23912853Sgabeblack@google.com DECL_ASN_OP_T(const bool *) 24012853Sgabeblack@google.com DECL_ASN_OP_T(const sc_signed &) 24112853Sgabeblack@google.com DECL_ASN_OP_T(const sc_unsigned &) 24212853Sgabeblack@google.com DECL_ASN_OP_T(const sc_int_base &) 24312853Sgabeblack@google.com DECL_ASN_OP_T(const sc_uint_base &) 24412853Sgabeblack@google.com DECL_ASN_OP_T(int64) 24512853Sgabeblack@google.com DECL_ASN_OP_T(uint64) 24612853Sgabeblack@google.com DECL_ASN_OP_T(int) 24712853Sgabeblack@google.com DECL_ASN_OP_T(unsigned int) 24812853Sgabeblack@google.com DECL_ASN_OP_T(long) 24912853Sgabeblack@google.com DECL_ASN_OP_T(unsigned long) 25012853Sgabeblack@google.com DECL_ASN_OP_T(char) 25112853Sgabeblack@google.com 25212853Sgabeblack@google.com#undef DECL_ASN_OP_T 25312853Sgabeblack@google.com 25412853Sgabeblack@google.com#define DECL_ASN_OP_T_A(op, tp) \ 25512853Sgabeblack@google.com sc_fxnum_subref &operator op ## = (tp); 25612853Sgabeblack@google.com 25712853Sgabeblack@google.com#define DECL_ASN_OP_A(op) \ 25812853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_fxnum_subref &) \ 25912853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_fxnum_fast_subref &) \ 26012853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_bv_base &) \ 26112853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_lv_base &) 26212853Sgabeblack@google.com 26312853Sgabeblack@google.com DECL_ASN_OP_A( &) 26412853Sgabeblack@google.com DECL_ASN_OP_A(|) 26512853Sgabeblack@google.com DECL_ASN_OP_A(^) 26612853Sgabeblack@google.com 26712853Sgabeblack@google.com#undef DECL_ASN_OP_T_A 26812853Sgabeblack@google.com#undef DECL_ASN_OP_A 26912853Sgabeblack@google.com 27012853Sgabeblack@google.com // relational operators 27112853Sgabeblack@google.com#define DECL_REL_OP_T(op, tp) \ 27212853Sgabeblack@google.com friend bool operator op (const sc_fxnum_subref &, tp); \ 27312853Sgabeblack@google.com friend bool operator op (tp, const sc_fxnum_subref &); 27412853Sgabeblack@google.com 27512853Sgabeblack@google.com#define DECL_REL_OP(op) \ 27612853Sgabeblack@google.com friend bool operator op (const sc_fxnum_subref &, \ 27712853Sgabeblack@google.com const sc_fxnum_subref &); \ 27812853Sgabeblack@google.com friend bool operator op (const sc_fxnum_subref &, \ 27912853Sgabeblack@google.com const sc_fxnum_fast_subref &); \ 28012853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_bv_base &) \ 28112853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_lv_base &) \ 28212853Sgabeblack@google.com DECL_REL_OP_T(op, const char *) \ 28312853Sgabeblack@google.com DECL_REL_OP_T(op, const bool *) \ 28412853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_signed &) \ 28512853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_unsigned &) \ 28612853Sgabeblack@google.com DECL_REL_OP_T(op, int) \ 28712853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned int) \ 28812853Sgabeblack@google.com DECL_REL_OP_T(op, long) \ 28912853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned long) 29012853Sgabeblack@google.com 29112853Sgabeblack@google.com DECL_REL_OP(==) 29212853Sgabeblack@google.com DECL_REL_OP(!=) 29312853Sgabeblack@google.com 29412853Sgabeblack@google.com#undef DECL_REL_OP_T 29512853Sgabeblack@google.com#undef DECL_REL_OP 29612853Sgabeblack@google.com 29712853Sgabeblack@google.com // reduce functions 29812853Sgabeblack@google.com bool and_reduce() const; 29912853Sgabeblack@google.com bool nand_reduce() const; 30012853Sgabeblack@google.com bool or_reduce() const; 30112853Sgabeblack@google.com bool nor_reduce() const; 30212853Sgabeblack@google.com bool xor_reduce() const; 30312853Sgabeblack@google.com bool xnor_reduce() const; 30412853Sgabeblack@google.com 30512853Sgabeblack@google.com // query parameter 30612853Sgabeblack@google.com int length() const; 30712853Sgabeblack@google.com 30812853Sgabeblack@google.com // explicit conversions 30912853Sgabeblack@google.com int to_int() const; 31012853Sgabeblack@google.com unsigned int to_uint() const; 31112853Sgabeblack@google.com long to_long() const; 31212853Sgabeblack@google.com unsigned long to_ulong() const; 31312853Sgabeblack@google.com int64 to_int64() const; 31412853Sgabeblack@google.com uint64 to_uint64() const; 31512853Sgabeblack@google.com 31612853Sgabeblack@google.com const std::string to_string() const; 31712853Sgabeblack@google.com const std::string to_string(sc_numrep) const; 31812853Sgabeblack@google.com const std::string to_string(sc_numrep, bool) const; 31912853Sgabeblack@google.com 32012853Sgabeblack@google.com // implicit conversion 32112853Sgabeblack@google.com operator sc_bv_base() const; 32212853Sgabeblack@google.com 32312853Sgabeblack@google.com // print or dump content 32412853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 32512853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 32612853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 32712853Sgabeblack@google.com 32812853Sgabeblack@google.com private: 32912853Sgabeblack@google.com sc_fxnum &m_num; 33012853Sgabeblack@google.com int m_from; 33112853Sgabeblack@google.com int m_to; 33212853Sgabeblack@google.com 33312853Sgabeblack@google.com sc_bv_base &m_bv; 33412853Sgabeblack@google.com 33512853Sgabeblack@google.com private: 33612853Sgabeblack@google.com // Disabled 33712853Sgabeblack@google.com sc_fxnum_subref(); 33812853Sgabeblack@google.com}; 33912853Sgabeblack@google.com 34012853Sgabeblack@google.com 34112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 34212853Sgabeblack@google.com// CLASS : sc_fxnum_fast_subref 34312853Sgabeblack@google.com// 34412853Sgabeblack@google.com// Proxy class for part-selection in class sc_fxnum_fast, 34512853Sgabeblack@google.com// behaves like sc_bv_base. 34612853Sgabeblack@google.com// ---------------------------------------------------------------------------- 34712853Sgabeblack@google.com 34812853Sgabeblack@google.comclass sc_fxnum_fast_subref 34912853Sgabeblack@google.com{ 35012853Sgabeblack@google.com friend class sc_fxnum_fast; 35112853Sgabeblack@google.com friend class sc_fxnum_subref; 35212853Sgabeblack@google.com 35312853Sgabeblack@google.com bool get() const; 35412853Sgabeblack@google.com bool set(); 35512853Sgabeblack@google.com 35612853Sgabeblack@google.com // constructor 35712853Sgabeblack@google.com sc_fxnum_fast_subref(sc_fxnum_fast &, int, int); 35812853Sgabeblack@google.com 35912853Sgabeblack@google.com public: 36012853Sgabeblack@google.com // copy constructor 36112853Sgabeblack@google.com sc_fxnum_fast_subref(const sc_fxnum_fast_subref &); 36212853Sgabeblack@google.com 36312853Sgabeblack@google.com // destructor 36412853Sgabeblack@google.com ~sc_fxnum_fast_subref(); 36512853Sgabeblack@google.com 36612853Sgabeblack@google.com // assignment operators 36712853Sgabeblack@google.com#define DECL_ASN_OP_T(tp) \ 36812853Sgabeblack@google.com sc_fxnum_fast_subref &operator = (tp); 36912853Sgabeblack@google.com 37012853Sgabeblack@google.com DECL_ASN_OP_T(const sc_fxnum_subref &) 37112853Sgabeblack@google.com DECL_ASN_OP_T(const sc_fxnum_fast_subref &) 37212853Sgabeblack@google.com DECL_ASN_OP_T(const sc_bv_base &) 37312853Sgabeblack@google.com DECL_ASN_OP_T(const sc_lv_base &) 37412853Sgabeblack@google.com DECL_ASN_OP_T(const char *) 37512853Sgabeblack@google.com DECL_ASN_OP_T(const bool *) 37612853Sgabeblack@google.com DECL_ASN_OP_T(const sc_signed &) 37712853Sgabeblack@google.com DECL_ASN_OP_T(const sc_unsigned &) 37812853Sgabeblack@google.com DECL_ASN_OP_T(const sc_int_base &) 37912853Sgabeblack@google.com DECL_ASN_OP_T(const sc_uint_base &) 38012853Sgabeblack@google.com DECL_ASN_OP_T(int64) 38112853Sgabeblack@google.com DECL_ASN_OP_T(uint64) 38212853Sgabeblack@google.com DECL_ASN_OP_T(int) 38312853Sgabeblack@google.com DECL_ASN_OP_T(unsigned int) 38412853Sgabeblack@google.com DECL_ASN_OP_T(long) 38512853Sgabeblack@google.com DECL_ASN_OP_T(unsigned long) 38612853Sgabeblack@google.com DECL_ASN_OP_T(char) 38712853Sgabeblack@google.com 38812853Sgabeblack@google.com#undef DECL_ASN_OP_T 38912853Sgabeblack@google.com 39012853Sgabeblack@google.com#define DECL_ASN_OP_T_A(op, tp) sc_fxnum_fast_subref &operator op ## = (tp); 39112853Sgabeblack@google.com 39212853Sgabeblack@google.com#define DECL_ASN_OP_A(op) \ 39312853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_fxnum_subref &) \ 39412853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_fxnum_fast_subref &) \ 39512853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_bv_base &) \ 39612853Sgabeblack@google.com DECL_ASN_OP_T_A(op, const sc_lv_base &) 39712853Sgabeblack@google.com 39812853Sgabeblack@google.com DECL_ASN_OP_A(&) 39912853Sgabeblack@google.com DECL_ASN_OP_A(|) 40012853Sgabeblack@google.com DECL_ASN_OP_A(^) 40112853Sgabeblack@google.com 40212853Sgabeblack@google.com#undef DECL_ASN_OP_T_A 40312853Sgabeblack@google.com#undef DECL_ASN_OP_A 40412853Sgabeblack@google.com 40512853Sgabeblack@google.com // relational operators 40612853Sgabeblack@google.com#define DECL_REL_OP_T(op, tp) \ 40712853Sgabeblack@google.com friend bool operator op (const sc_fxnum_fast_subref &, tp); \ 40812853Sgabeblack@google.com friend bool operator op (tp, const sc_fxnum_fast_subref &); 40912853Sgabeblack@google.com 41012853Sgabeblack@google.com#define DECL_REL_OP(op) \ 41112853Sgabeblack@google.com friend bool operator op (const sc_fxnum_fast_subref &, \ 41212853Sgabeblack@google.com const sc_fxnum_fast_subref &); \ 41312853Sgabeblack@google.com friend bool operator op (const sc_fxnum_fast_subref &, \ 41412853Sgabeblack@google.com const sc_fxnum_subref &); \ 41512853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_bv_base &) \ 41612853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_lv_base &) \ 41712853Sgabeblack@google.com DECL_REL_OP_T(op, const char *) \ 41812853Sgabeblack@google.com DECL_REL_OP_T(op, const bool *) \ 41912853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_signed &) \ 42012853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_unsigned &) \ 42112853Sgabeblack@google.com DECL_REL_OP_T(op, int) \ 42212853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned int) \ 42312853Sgabeblack@google.com DECL_REL_OP_T(op, long) \ 42412853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned long) 42512853Sgabeblack@google.com 42612853Sgabeblack@google.com DECL_REL_OP(==) 42712853Sgabeblack@google.com DECL_REL_OP(!=) 42812853Sgabeblack@google.com 42912853Sgabeblack@google.com#undef DECL_REL_OP_T 43012853Sgabeblack@google.com#undef DECL_REL_OP 43112853Sgabeblack@google.com 43212853Sgabeblack@google.com // reduce functions 43312853Sgabeblack@google.com bool and_reduce() const; 43412853Sgabeblack@google.com bool nand_reduce() const; 43512853Sgabeblack@google.com bool or_reduce() const; 43612853Sgabeblack@google.com bool nor_reduce() const; 43712853Sgabeblack@google.com bool xor_reduce() const; 43812853Sgabeblack@google.com bool xnor_reduce() const; 43912853Sgabeblack@google.com 44012853Sgabeblack@google.com // query parameter 44112853Sgabeblack@google.com int length() const; 44212853Sgabeblack@google.com 44312853Sgabeblack@google.com // explicit conversions 44412853Sgabeblack@google.com int to_int() const; 44512853Sgabeblack@google.com unsigned int to_uint() const; 44612853Sgabeblack@google.com long to_long() const; 44712853Sgabeblack@google.com unsigned long to_ulong() const; 44812853Sgabeblack@google.com int64 to_int64() const; 44912853Sgabeblack@google.com uint64 to_uint64() const; 45012853Sgabeblack@google.com 45112853Sgabeblack@google.com const std::string to_string() const; 45212853Sgabeblack@google.com const std::string to_string(sc_numrep) const; 45312853Sgabeblack@google.com const std::string to_string(sc_numrep, bool) const; 45412853Sgabeblack@google.com 45512853Sgabeblack@google.com // implicit conversion 45612853Sgabeblack@google.com operator sc_bv_base() const; 45712853Sgabeblack@google.com 45812853Sgabeblack@google.com // print or dump content 45912853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 46012853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 46112853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 46212853Sgabeblack@google.com 46312853Sgabeblack@google.com private: 46412853Sgabeblack@google.com sc_fxnum_fast &m_num; 46512853Sgabeblack@google.com int m_from; 46612853Sgabeblack@google.com int m_to; 46712853Sgabeblack@google.com 46812853Sgabeblack@google.com sc_bv_base &m_bv; 46912853Sgabeblack@google.com 47012853Sgabeblack@google.com private: 47112853Sgabeblack@google.com // Disabled 47212853Sgabeblack@google.com sc_fxnum_fast_subref(); 47312853Sgabeblack@google.com}; 47412853Sgabeblack@google.com 47512853Sgabeblack@google.com 47612853Sgabeblack@google.com// ---------------------------------------------------------------------------- 47712853Sgabeblack@google.com// CLASS : sc_fxnum 47812853Sgabeblack@google.com// 47912853Sgabeblack@google.com// Base class for the fixed-point types; arbitrary precision. 48012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 48112853Sgabeblack@google.com 48212853Sgabeblack@google.comclass sc_fxnum 48312853Sgabeblack@google.com{ 48412853Sgabeblack@google.com friend class sc_fxval; 48512853Sgabeblack@google.com 48612853Sgabeblack@google.com friend class sc_fxnum_bitref; 48712853Sgabeblack@google.com friend class sc_fxnum_subref; 48812853Sgabeblack@google.com friend class sc_fxnum_fast_bitref; 48912853Sgabeblack@google.com friend class sc_fxnum_fast_subref; 49012853Sgabeblack@google.com 49113245Sgabeblack@google.com template <typename T, typename B> 49213245Sgabeblack@google.com friend class sc_gem5::TraceValFxnumBase; 49312853Sgabeblack@google.com 49412853Sgabeblack@google.com protected: 49512853Sgabeblack@google.com sc_fxnum_observer *observer() const; 49612853Sgabeblack@google.com 49712853Sgabeblack@google.com void cast(); 49812853Sgabeblack@google.com 49912853Sgabeblack@google.com // constructors 50012853Sgabeblack@google.com sc_fxnum(const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &, 50112853Sgabeblack@google.com sc_fxnum_observer *); 50212853Sgabeblack@google.com 50312853Sgabeblack@google.com#define DECL_CTOR_T(tp) \ 50412853Sgabeblack@google.com sc_fxnum(tp, const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &, \ 50512853Sgabeblack@google.com sc_fxnum_observer *); 50612853Sgabeblack@google.com 50712853Sgabeblack@google.com DECL_CTOR_T(int) 50812853Sgabeblack@google.com DECL_CTOR_T(unsigned int) 50912853Sgabeblack@google.com DECL_CTOR_T(long) 51012853Sgabeblack@google.com DECL_CTOR_T(unsigned long) 51112853Sgabeblack@google.com DECL_CTOR_T(float) 51212853Sgabeblack@google.com DECL_CTOR_T(double) 51312853Sgabeblack@google.com DECL_CTOR_T(const char *) 51412853Sgabeblack@google.com DECL_CTOR_T(const sc_fxval &) 51512853Sgabeblack@google.com DECL_CTOR_T(const sc_fxval_fast &) 51612853Sgabeblack@google.com DECL_CTOR_T(const sc_fxnum &) 51712853Sgabeblack@google.com DECL_CTOR_T(const sc_fxnum_fast &) 51812853Sgabeblack@google.com 51912853Sgabeblack@google.com DECL_CTOR_T(int64) 52012853Sgabeblack@google.com DECL_CTOR_T(uint64) 52112853Sgabeblack@google.com DECL_CTOR_T(const sc_int_base &) 52212853Sgabeblack@google.com DECL_CTOR_T(const sc_uint_base &) 52312853Sgabeblack@google.com DECL_CTOR_T(const sc_signed &) 52412853Sgabeblack@google.com DECL_CTOR_T(const sc_unsigned &) 52512853Sgabeblack@google.com 52612853Sgabeblack@google.com#undef DECL_CTOR_T 52712853Sgabeblack@google.com 52812853Sgabeblack@google.com ~sc_fxnum(); 52912853Sgabeblack@google.com 53012853Sgabeblack@google.com // internal use only; 53112853Sgabeblack@google.com const scfx_rep *get_rep() const; 53212853Sgabeblack@google.com 53312853Sgabeblack@google.com public: 53412853Sgabeblack@google.com // unary operators 53512853Sgabeblack@google.com const sc_fxval operator - () const; 53612853Sgabeblack@google.com const sc_fxval operator + () const; 53712853Sgabeblack@google.com 53812853Sgabeblack@google.com // unary functions 53912853Sgabeblack@google.com friend void neg(sc_fxval &, const sc_fxnum &); 54012853Sgabeblack@google.com friend void neg(sc_fxnum &, const sc_fxnum &); 54112853Sgabeblack@google.com 54212853Sgabeblack@google.com // binary operators 54312853Sgabeblack@google.com#define DECL_BIN_OP_T(op, tp) \ 54412853Sgabeblack@google.com friend const sc_fxval operator op (const sc_fxnum &, tp); \ 54512853Sgabeblack@google.com friend const sc_fxval operator op (tp, const sc_fxnum &); 54612853Sgabeblack@google.com 54712853Sgabeblack@google.com#define DECL_BIN_OP_OTHER(op) \ 54812853Sgabeblack@google.com DECL_BIN_OP_T(op, int64) \ 54912853Sgabeblack@google.com DECL_BIN_OP_T(op, uint64) \ 55012853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_int_base &) \ 55112853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_uint_base &) \ 55212853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_signed &) \ 55312853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_unsigned &) 55412853Sgabeblack@google.com 55512853Sgabeblack@google.com#define DECL_BIN_OP(op, dummy) \ 55612853Sgabeblack@google.com friend const sc_fxval operator op (const sc_fxnum &, const sc_fxnum &); \ 55712853Sgabeblack@google.com DECL_BIN_OP_T(op, int) \ 55812853Sgabeblack@google.com DECL_BIN_OP_T(op, unsigned int) \ 55912853Sgabeblack@google.com DECL_BIN_OP_T(op, long) \ 56012853Sgabeblack@google.com DECL_BIN_OP_T(op, unsigned long) \ 56112853Sgabeblack@google.com DECL_BIN_OP_T(op, float) \ 56212853Sgabeblack@google.com DECL_BIN_OP_T(op, double) \ 56312853Sgabeblack@google.com DECL_BIN_OP_T(op, const char *) \ 56412853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_fxval &) \ 56512853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_fxval_fast &) \ 56612853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_fxnum_fast &) \ 56712853Sgabeblack@google.com DECL_BIN_OP_OTHER(op) 56812853Sgabeblack@google.com 56912853Sgabeblack@google.com DECL_BIN_OP(*, mult) 57012853Sgabeblack@google.com DECL_BIN_OP(+, add) 57112853Sgabeblack@google.com DECL_BIN_OP(-, sub) 57212853Sgabeblack@google.com// don't use macros 57312853Sgabeblack@google.com// DECL_BIN_OP(/, div) 57412853Sgabeblack@google.com friend const sc_fxval operator / (const sc_fxnum &, const sc_fxnum &); 57512853Sgabeblack@google.com DECL_BIN_OP_T(/, int) 57612853Sgabeblack@google.com DECL_BIN_OP_T(/, unsigned int) 57712853Sgabeblack@google.com DECL_BIN_OP_T(/, long) 57812853Sgabeblack@google.com DECL_BIN_OP_T(/, unsigned long) 57912853Sgabeblack@google.com DECL_BIN_OP_T(/, float) 58012853Sgabeblack@google.com DECL_BIN_OP_T(/, double) 58112853Sgabeblack@google.com DECL_BIN_OP_T(/, const char *) 58212853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_fxval &) 58312853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_fxval_fast &) 58412853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_fxnum_fast &) 58512853Sgabeblack@google.com// DECL_BIN_OP_OTHER(op) 58612853Sgabeblack@google.com 58712853Sgabeblack@google.com DECL_BIN_OP_T(/, int64) 58812853Sgabeblack@google.com DECL_BIN_OP_T(/, uint64) 58912853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_int_base &) 59012853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_uint_base &) 59112853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_signed &) 59212853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_unsigned &) 59312853Sgabeblack@google.com 59412853Sgabeblack@google.com#undef DECL_BIN_OP_T 59512853Sgabeblack@google.com#undef DECL_BIN_OP_OTHER 59612853Sgabeblack@google.com#undef DECL_BIN_OP 59712853Sgabeblack@google.com 59812853Sgabeblack@google.com friend const sc_fxval operator << (const sc_fxnum &, int); 59912853Sgabeblack@google.com friend const sc_fxval operator >> (const sc_fxnum &, int); 60012853Sgabeblack@google.com 60112853Sgabeblack@google.com // binary functions 60212853Sgabeblack@google.com#define DECL_BIN_FNC_T(fnc, tp) \ 60312853Sgabeblack@google.com friend void fnc (sc_fxval &, const sc_fxnum &, tp); \ 60412853Sgabeblack@google.com friend void fnc (sc_fxval &, tp, const sc_fxnum &); \ 60512853Sgabeblack@google.com friend void fnc (sc_fxnum &, const sc_fxnum &, tp); \ 60612853Sgabeblack@google.com friend void fnc (sc_fxnum &, tp, const sc_fxnum &); 60712853Sgabeblack@google.com 60812853Sgabeblack@google.com#define DECL_BIN_FNC_OTHER(fnc) \ 60912853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, int64) \ 61012853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, uint64) \ 61112853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_int_base &) \ 61212853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_uint_base &) \ 61312853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_signed &) \ 61412853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_unsigned &) 61512853Sgabeblack@google.com 61612853Sgabeblack@google.com#define DECL_BIN_FNC(fnc) \ 61712853Sgabeblack@google.com friend void fnc (sc_fxval &, const sc_fxnum &, const sc_fxnum &); \ 61812853Sgabeblack@google.com friend void fnc (sc_fxnum &, const sc_fxnum &, const sc_fxnum &); \ 61912853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, int) \ 62012853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, unsigned int) \ 62112853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, long) \ 62212853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, unsigned long) \ 62312853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, float) \ 62412853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, double) \ 62512853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const char *) \ 62612853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxval &) \ 62712853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxval_fast &) \ 62812853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxnum_fast &) \ 62912853Sgabeblack@google.com DECL_BIN_FNC_OTHER(fnc) 63012853Sgabeblack@google.com 63112853Sgabeblack@google.com DECL_BIN_FNC(mult) 63212853Sgabeblack@google.com DECL_BIN_FNC(div) 63312853Sgabeblack@google.com DECL_BIN_FNC(add) 63412853Sgabeblack@google.com DECL_BIN_FNC(sub) 63512853Sgabeblack@google.com 63612853Sgabeblack@google.com#undef DECL_BIN_FNC_T 63712853Sgabeblack@google.com#undef DECL_BIN_FNC_OTHER 63812853Sgabeblack@google.com#undef DECL_BIN_FNC 63912853Sgabeblack@google.com 64012853Sgabeblack@google.com friend void lshift(sc_fxval &, const sc_fxnum &, int); 64112853Sgabeblack@google.com friend void rshift(sc_fxval &, const sc_fxnum &, int); 64212853Sgabeblack@google.com friend void lshift(sc_fxnum &, const sc_fxnum &, int); 64312853Sgabeblack@google.com friend void rshift(sc_fxnum &, const sc_fxnum &, int); 64412853Sgabeblack@google.com 64512853Sgabeblack@google.com // relational (including equality) operators 64612853Sgabeblack@google.com#define DECL_REL_OP_T(op, tp) \ 64712853Sgabeblack@google.com friend bool operator op (const sc_fxnum &, tp); \ 64812853Sgabeblack@google.com friend bool operator op (tp, const sc_fxnum &); 64912853Sgabeblack@google.com 65012853Sgabeblack@google.com#define DECL_REL_OP_OTHER(op) \ 65112853Sgabeblack@google.com DECL_REL_OP_T(op, int64) \ 65212853Sgabeblack@google.com DECL_REL_OP_T(op, uint64) \ 65312853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_int_base &) \ 65412853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_uint_base &) \ 65512853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_signed &) \ 65612853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_unsigned &) 65712853Sgabeblack@google.com 65812853Sgabeblack@google.com#define DECL_REL_OP(op) \ 65912853Sgabeblack@google.com friend bool operator op (const sc_fxnum &, const sc_fxnum &); \ 66012853Sgabeblack@google.com DECL_REL_OP_T(op, int) \ 66112853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned int) \ 66212853Sgabeblack@google.com DECL_REL_OP_T(op, long) \ 66312853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned long) \ 66412853Sgabeblack@google.com DECL_REL_OP_T(op, float) \ 66512853Sgabeblack@google.com DECL_REL_OP_T(op, double) \ 66612853Sgabeblack@google.com DECL_REL_OP_T(op, const char *) \ 66712853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_fxval &) \ 66812853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_fxval_fast &) \ 66912853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_fxnum_fast &) \ 67012853Sgabeblack@google.com DECL_REL_OP_OTHER(op) 67112853Sgabeblack@google.com 67212853Sgabeblack@google.com DECL_REL_OP(<) 67312853Sgabeblack@google.com DECL_REL_OP(<=) 67412853Sgabeblack@google.com DECL_REL_OP(>) 67512853Sgabeblack@google.com DECL_REL_OP(>=) 67612853Sgabeblack@google.com DECL_REL_OP(==) 67712853Sgabeblack@google.com DECL_REL_OP(!=) 67812853Sgabeblack@google.com 67912853Sgabeblack@google.com#undef DECL_REL_OP_T 68012853Sgabeblack@google.com#undef DECL_REL_OP_OTHER 68112853Sgabeblack@google.com#undef DECL_REL_OP 68212853Sgabeblack@google.com 68312853Sgabeblack@google.com // assignment operators 68412853Sgabeblack@google.com#define DECL_ASN_OP_T(op, tp) \ 68512853Sgabeblack@google.com sc_fxnum &operator op(tp); 68612853Sgabeblack@google.com 68712853Sgabeblack@google.com#define DECL_ASN_OP_OTHER(op) \ 68812853Sgabeblack@google.com DECL_ASN_OP_T(op, int64) \ 68912853Sgabeblack@google.com DECL_ASN_OP_T(op, uint64) \ 69012853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_int_base &) \ 69112853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_uint_base &) \ 69212853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_signed &) \ 69312853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_unsigned &) 69412853Sgabeblack@google.com 69512853Sgabeblack@google.com#define DECL_ASN_OP(op) \ 69612853Sgabeblack@google.com DECL_ASN_OP_T(op, int) \ 69712853Sgabeblack@google.com DECL_ASN_OP_T(op, unsigned int) \ 69812853Sgabeblack@google.com DECL_ASN_OP_T(op, long) \ 69912853Sgabeblack@google.com DECL_ASN_OP_T(op, unsigned long) \ 70012853Sgabeblack@google.com DECL_ASN_OP_T(op, float) \ 70112853Sgabeblack@google.com DECL_ASN_OP_T(op, double) \ 70212853Sgabeblack@google.com DECL_ASN_OP_T(op, const char *) \ 70312853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxval &) \ 70412853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxval_fast &) \ 70512853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum &) \ 70612853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_fast &) \ 70712853Sgabeblack@google.com DECL_ASN_OP_OTHER(op) 70812853Sgabeblack@google.com 70912853Sgabeblack@google.com DECL_ASN_OP(=) 71012853Sgabeblack@google.com 71112853Sgabeblack@google.com DECL_ASN_OP(*=) 71212853Sgabeblack@google.com DECL_ASN_OP(/=) 71312853Sgabeblack@google.com DECL_ASN_OP(+=) 71412853Sgabeblack@google.com DECL_ASN_OP(-=) 71512853Sgabeblack@google.com 71612853Sgabeblack@google.com DECL_ASN_OP_T(<<=, int) 71712853Sgabeblack@google.com DECL_ASN_OP_T(>>=, int) 71812853Sgabeblack@google.com 71912853Sgabeblack@google.com#undef DECL_ASN_OP_T 72012853Sgabeblack@google.com#undef DECL_ASN_OP_OTHER 72112853Sgabeblack@google.com#undef DECL_ASN_OP 72212853Sgabeblack@google.com 72312853Sgabeblack@google.com // auto-increment and auto-decrement 72412853Sgabeblack@google.com const sc_fxval operator ++ (int); 72512853Sgabeblack@google.com const sc_fxval operator -- (int); 72612853Sgabeblack@google.com 72712853Sgabeblack@google.com sc_fxnum &operator ++ (); 72812853Sgabeblack@google.com sc_fxnum &operator -- (); 72912853Sgabeblack@google.com 73012853Sgabeblack@google.com // bit selection 73112853Sgabeblack@google.com const sc_fxnum_bitref operator [] (int) const; 73212853Sgabeblack@google.com sc_fxnum_bitref operator [] (int); 73312853Sgabeblack@google.com 73412853Sgabeblack@google.com const sc_fxnum_bitref bit(int) const; 73512853Sgabeblack@google.com sc_fxnum_bitref bit(int); 73612853Sgabeblack@google.com 73712853Sgabeblack@google.com // part selection 73812853Sgabeblack@google.com const sc_fxnum_subref operator () (int, int) const; 73912853Sgabeblack@google.com sc_fxnum_subref operator () (int, int); 74012853Sgabeblack@google.com 74112853Sgabeblack@google.com const sc_fxnum_subref range(int, int) const; 74212853Sgabeblack@google.com sc_fxnum_subref range(int, int); 74312853Sgabeblack@google.com 74412853Sgabeblack@google.com const sc_fxnum_subref operator () () const; 74512853Sgabeblack@google.com sc_fxnum_subref operator () (); 74612853Sgabeblack@google.com 74712853Sgabeblack@google.com const sc_fxnum_subref range() const; 74812853Sgabeblack@google.com sc_fxnum_subref range(); 74912853Sgabeblack@google.com 75012853Sgabeblack@google.com // implicit conversion 75112853Sgabeblack@google.com operator double() const; // necessary evil! 75212853Sgabeblack@google.com 75312853Sgabeblack@google.com // explicit conversion to primitive types 75412853Sgabeblack@google.com short to_short() const; 75512853Sgabeblack@google.com unsigned short to_ushort() const; 75612853Sgabeblack@google.com int to_int() const; 75712853Sgabeblack@google.com unsigned int to_uint() const; 75812853Sgabeblack@google.com long to_long() const; 75912853Sgabeblack@google.com unsigned long to_ulong() const; 76012853Sgabeblack@google.com int64 to_int64() const; 76112853Sgabeblack@google.com uint64 to_uint64() const; 76212853Sgabeblack@google.com float to_float() const; 76312853Sgabeblack@google.com double to_double() const; 76412853Sgabeblack@google.com 76512853Sgabeblack@google.com // explicit conversion to character string 76612853Sgabeblack@google.com const std::string to_string() const; 76712853Sgabeblack@google.com const std::string to_string(sc_numrep) const; 76812853Sgabeblack@google.com const std::string to_string(sc_numrep, bool) const; 76912853Sgabeblack@google.com const std::string to_string(sc_fmt) const; 77012853Sgabeblack@google.com const std::string to_string(sc_numrep, sc_fmt) const; 77112853Sgabeblack@google.com const std::string to_string(sc_numrep, bool, sc_fmt) const; 77212853Sgabeblack@google.com 77312853Sgabeblack@google.com const std::string to_dec() const; 77412853Sgabeblack@google.com const std::string to_bin() const; 77512853Sgabeblack@google.com const std::string to_oct() const; 77612853Sgabeblack@google.com const std::string to_hex() const; 77712853Sgabeblack@google.com 77812853Sgabeblack@google.com // query value 77912853Sgabeblack@google.com bool is_neg() const; 78012853Sgabeblack@google.com bool is_zero() const; 78112853Sgabeblack@google.com 78212853Sgabeblack@google.com // internal use only; 78312853Sgabeblack@google.com bool is_normal() const; 78412853Sgabeblack@google.com 78512853Sgabeblack@google.com bool quantization_flag() const; 78612853Sgabeblack@google.com bool overflow_flag() const; 78712853Sgabeblack@google.com 78812853Sgabeblack@google.com const sc_fxval value() const; 78912853Sgabeblack@google.com 79012853Sgabeblack@google.com // query parameters 79112853Sgabeblack@google.com int wl() const; 79212853Sgabeblack@google.com int iwl() const; 79312853Sgabeblack@google.com sc_q_mode q_mode() const; 79412853Sgabeblack@google.com sc_o_mode o_mode() const; 79512853Sgabeblack@google.com int n_bits() const; 79612853Sgabeblack@google.com 79712853Sgabeblack@google.com const sc_fxtype_params &type_params() const; 79812853Sgabeblack@google.com 79912853Sgabeblack@google.com const sc_fxcast_switch &cast_switch() const; 80012853Sgabeblack@google.com 80112853Sgabeblack@google.com // print or dump content 80212853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 80312853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 80412853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 80512853Sgabeblack@google.com 80612853Sgabeblack@google.com // internal use only; 80712853Sgabeblack@google.com void observer_read() const; 80812853Sgabeblack@google.com 80912853Sgabeblack@google.com // internal use only; 81012853Sgabeblack@google.com bool get_bit(int) const; 81112853Sgabeblack@google.com 81212853Sgabeblack@google.com protected: 81312853Sgabeblack@google.com bool set_bit(int, bool); 81412853Sgabeblack@google.com 81512853Sgabeblack@google.com bool get_slice(int, int, sc_bv_base &) const; 81612853Sgabeblack@google.com bool set_slice(int, int, const sc_bv_base &); 81712853Sgabeblack@google.com 81812853Sgabeblack@google.com sc_fxnum_observer *lock_observer() const; 81912853Sgabeblack@google.com void unlock_observer(sc_fxnum_observer *) const; 82012853Sgabeblack@google.com 82112853Sgabeblack@google.com private: 82212853Sgabeblack@google.com scfx_rep *m_rep; 82312853Sgabeblack@google.com 82412853Sgabeblack@google.com scfx_params m_params; 82512853Sgabeblack@google.com bool m_q_flag; 82612853Sgabeblack@google.com bool m_o_flag; 82712853Sgabeblack@google.com 82812853Sgabeblack@google.com mutable sc_fxnum_observer *m_observer; 82912853Sgabeblack@google.com 83012853Sgabeblack@google.com private: 83112853Sgabeblack@google.com // disabled 83212853Sgabeblack@google.com sc_fxnum(); 83312853Sgabeblack@google.com sc_fxnum(const sc_fxnum &); 83412853Sgabeblack@google.com}; 83512853Sgabeblack@google.com 83612853Sgabeblack@google.com 83712853Sgabeblack@google.com// ---------------------------------------------------------------------------- 83812853Sgabeblack@google.com// CLASS : sc_fxnum_fast 83912853Sgabeblack@google.com// 84012853Sgabeblack@google.com// Base class for the fixed-point types; limited precision. 84112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 84212853Sgabeblack@google.com 84312853Sgabeblack@google.comclass sc_fxnum_fast 84412853Sgabeblack@google.com{ 84512853Sgabeblack@google.com friend class sc_fxval_fast; 84612853Sgabeblack@google.com 84712853Sgabeblack@google.com friend class sc_fxnum_bitref; 84812853Sgabeblack@google.com friend class sc_fxnum_subref; 84912853Sgabeblack@google.com friend class sc_fxnum_fast_bitref; 85012853Sgabeblack@google.com friend class sc_fxnum_fast_subref; 85112853Sgabeblack@google.com 85213245Sgabeblack@google.com template <typename T, typename B> 85313245Sgabeblack@google.com friend class sc_gem5::TraceValFxnumBase; 85412853Sgabeblack@google.com 85512853Sgabeblack@google.com protected: 85612853Sgabeblack@google.com sc_fxnum_fast_observer *observer() const; 85712853Sgabeblack@google.com 85812853Sgabeblack@google.com void cast(); 85912853Sgabeblack@google.com 86012853Sgabeblack@google.com // constructors 86112853Sgabeblack@google.com sc_fxnum_fast(const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &, 86212853Sgabeblack@google.com sc_fxnum_fast_observer *); 86312853Sgabeblack@google.com 86412853Sgabeblack@google.com#define DECL_CTOR_T(tp) \ 86512853Sgabeblack@google.com sc_fxnum_fast(tp, const sc_fxtype_params &, sc_enc, \ 86612853Sgabeblack@google.com const sc_fxcast_switch &, sc_fxnum_fast_observer *); 86712853Sgabeblack@google.com 86812853Sgabeblack@google.com DECL_CTOR_T(int) 86912853Sgabeblack@google.com DECL_CTOR_T(unsigned int) 87012853Sgabeblack@google.com DECL_CTOR_T(long) 87112853Sgabeblack@google.com DECL_CTOR_T(unsigned long) 87212853Sgabeblack@google.com DECL_CTOR_T(float) 87312853Sgabeblack@google.com DECL_CTOR_T(double) 87412853Sgabeblack@google.com DECL_CTOR_T(const char *) 87512853Sgabeblack@google.com DECL_CTOR_T(const sc_fxval &) 87612853Sgabeblack@google.com DECL_CTOR_T(const sc_fxval_fast &) 87712853Sgabeblack@google.com DECL_CTOR_T(const sc_fxnum &) 87812853Sgabeblack@google.com DECL_CTOR_T(const sc_fxnum_fast &) 87912853Sgabeblack@google.com 88012853Sgabeblack@google.com DECL_CTOR_T(int64) 88112853Sgabeblack@google.com DECL_CTOR_T(uint64) 88212853Sgabeblack@google.com DECL_CTOR_T(const sc_int_base &) 88312853Sgabeblack@google.com DECL_CTOR_T(const sc_uint_base &) 88412853Sgabeblack@google.com DECL_CTOR_T(const sc_signed &) 88512853Sgabeblack@google.com DECL_CTOR_T(const sc_unsigned &) 88612853Sgabeblack@google.com 88712853Sgabeblack@google.com#undef DECL_CTOR_T 88812853Sgabeblack@google.com ~sc_fxnum_fast(); 88912853Sgabeblack@google.com 89012853Sgabeblack@google.com // internal use only; 89112853Sgabeblack@google.com double get_val() const; 89212853Sgabeblack@google.com 89312853Sgabeblack@google.com public: 89412853Sgabeblack@google.com // unary operators 89512853Sgabeblack@google.com const sc_fxval_fast operator - () const; 89612853Sgabeblack@google.com const sc_fxval_fast operator + () const; 89712853Sgabeblack@google.com 89812853Sgabeblack@google.com // unary functions 89912853Sgabeblack@google.com friend void neg(sc_fxval_fast &, const sc_fxnum_fast &); 90012853Sgabeblack@google.com friend void neg(sc_fxnum_fast &, const sc_fxnum_fast &); 90112853Sgabeblack@google.com 90212853Sgabeblack@google.com 90312853Sgabeblack@google.com // binary operators 90412853Sgabeblack@google.com#define DECL_BIN_OP_T(op, tp) \ 90512853Sgabeblack@google.com friend const sc_fxval_fast operator op (const sc_fxnum_fast &, tp); \ 90612853Sgabeblack@google.com friend const sc_fxval_fast operator op (tp, const sc_fxnum_fast &); 90712853Sgabeblack@google.com 90812853Sgabeblack@google.com#define DECL_BIN_OP_OTHER(op) \ 90912853Sgabeblack@google.com DECL_BIN_OP_T(op, int64) \ 91012853Sgabeblack@google.com DECL_BIN_OP_T(op, uint64) \ 91112853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_int_base &) \ 91212853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_uint_base &) \ 91312853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_signed &) \ 91412853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_unsigned &) 91512853Sgabeblack@google.com 91612853Sgabeblack@google.com#define DECL_BIN_OP(op, dummy) \ 91712853Sgabeblack@google.com friend const sc_fxval_fast operator op (const sc_fxnum_fast &, \ 91812853Sgabeblack@google.com const sc_fxnum_fast &); \ 91912853Sgabeblack@google.com DECL_BIN_OP_T(op, int) \ 92012853Sgabeblack@google.com DECL_BIN_OP_T(op, unsigned int) \ 92112853Sgabeblack@google.com DECL_BIN_OP_T(op, long) \ 92212853Sgabeblack@google.com DECL_BIN_OP_T(op, unsigned long) \ 92312853Sgabeblack@google.com DECL_BIN_OP_T(op, float) \ 92412853Sgabeblack@google.com DECL_BIN_OP_T(op, double) \ 92512853Sgabeblack@google.com DECL_BIN_OP_T(op, const char *) \ 92612853Sgabeblack@google.com DECL_BIN_OP_T(op, const sc_fxval_fast &) \ 92712853Sgabeblack@google.com DECL_BIN_OP_OTHER(op) 92812853Sgabeblack@google.com 92912853Sgabeblack@google.com DECL_BIN_OP(*, mult) 93012853Sgabeblack@google.com DECL_BIN_OP(+, add) 93112853Sgabeblack@google.com DECL_BIN_OP(-, sub) 93212853Sgabeblack@google.com// DECL_BIN_OP(/, div) 93312853Sgabeblack@google.com friend const sc_fxval_fast operator / (const sc_fxnum_fast &, 93412853Sgabeblack@google.com const sc_fxnum_fast &); 93512853Sgabeblack@google.com DECL_BIN_OP_T(/, int) 93612853Sgabeblack@google.com DECL_BIN_OP_T(/, unsigned int) 93712853Sgabeblack@google.com DECL_BIN_OP_T(/, long) 93812853Sgabeblack@google.com DECL_BIN_OP_T(/, unsigned long) 93912853Sgabeblack@google.com DECL_BIN_OP_T(/, float) 94012853Sgabeblack@google.com DECL_BIN_OP_T(/, double) 94112853Sgabeblack@google.com DECL_BIN_OP_T(/, const char *) 94212853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_fxval_fast &) 94312853Sgabeblack@google.com// DECL_BIN_OP_OTHER(op) 94412853Sgabeblack@google.com 94512853Sgabeblack@google.com DECL_BIN_OP_T(/, int64) \ 94612853Sgabeblack@google.com DECL_BIN_OP_T(/, uint64) \ 94712853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_int_base &) \ 94812853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_uint_base &) \ 94912853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_signed &) \ 95012853Sgabeblack@google.com DECL_BIN_OP_T(/, const sc_unsigned &) 95112853Sgabeblack@google.com 95212853Sgabeblack@google.com#undef DECL_BIN_OP_T 95312853Sgabeblack@google.com#undef DECL_BIN_OP_OTHER 95412853Sgabeblack@google.com#undef DECL_BIN_OP 95512853Sgabeblack@google.com 95612853Sgabeblack@google.com friend const sc_fxval_fast operator << (const sc_fxnum_fast &, int); 95712853Sgabeblack@google.com friend const sc_fxval_fast operator >> (const sc_fxnum_fast &, int); 95812853Sgabeblack@google.com 95912853Sgabeblack@google.com // binary functions 96012853Sgabeblack@google.com#define DECL_BIN_FNC_T(fnc, tp) \ 96112853Sgabeblack@google.com friend void fnc (sc_fxval_fast &, const sc_fxnum_fast &, tp); \ 96212853Sgabeblack@google.com friend void fnc (sc_fxval_fast &, tp, const sc_fxnum_fast &); \ 96312853Sgabeblack@google.com friend void fnc (sc_fxnum_fast &, const sc_fxnum_fast &, tp); \ 96412853Sgabeblack@google.com friend void fnc (sc_fxnum_fast &, tp, const sc_fxnum_fast &); 96512853Sgabeblack@google.com 96612853Sgabeblack@google.com#define DECL_BIN_FNC_OTHER(fnc) \ 96712853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, int64) \ 96812853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, uint64) \ 96912853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_int_base &) \ 97012853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_uint_base &) \ 97112853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_signed &) \ 97212853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_unsigned &) 97312853Sgabeblack@google.com 97412853Sgabeblack@google.com#define DECL_BIN_FNC(fnc) \ 97512853Sgabeblack@google.com friend void fnc (sc_fxval_fast &, const sc_fxnum_fast &, \ 97612853Sgabeblack@google.com const sc_fxnum_fast &); \ 97712853Sgabeblack@google.com friend void fnc (sc_fxnum_fast &, const sc_fxnum_fast &, \ 97812853Sgabeblack@google.com const sc_fxnum_fast &); \ 97912853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, int) \ 98012853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, unsigned int) \ 98112853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, long) \ 98212853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, unsigned long) \ 98312853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, float) \ 98412853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, double) \ 98512853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const char *) \ 98612853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxval &) \ 98712853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxval_fast &) \ 98812853Sgabeblack@google.com DECL_BIN_FNC_T(fnc, const sc_fxnum &) \ 98912853Sgabeblack@google.com DECL_BIN_FNC_OTHER(fnc) 99012853Sgabeblack@google.com 99112853Sgabeblack@google.com DECL_BIN_FNC(mult) 99212853Sgabeblack@google.com DECL_BIN_FNC(div) 99312853Sgabeblack@google.com DECL_BIN_FNC(add) 99412853Sgabeblack@google.com DECL_BIN_FNC(sub) 99512853Sgabeblack@google.com 99612853Sgabeblack@google.com#undef DECL_BIN_FNC_T 99712853Sgabeblack@google.com#undef DECL_BIN_FNC_OTHER 99812853Sgabeblack@google.com#undef DECL_BIN_FNC 99912853Sgabeblack@google.com 100012853Sgabeblack@google.com friend void lshift(sc_fxval_fast &, const sc_fxnum_fast &, int); 100112853Sgabeblack@google.com friend void rshift(sc_fxval_fast &, const sc_fxnum_fast &, int); 100212853Sgabeblack@google.com friend void lshift(sc_fxnum_fast &, const sc_fxnum_fast &, int); 100312853Sgabeblack@google.com friend void rshift(sc_fxnum_fast &, const sc_fxnum_fast &, int); 100412853Sgabeblack@google.com 100512853Sgabeblack@google.com // relational (including equality) operators 100612853Sgabeblack@google.com#define DECL_REL_OP_T(op, tp) \ 100712853Sgabeblack@google.com friend bool operator op (const sc_fxnum_fast &, tp); \ 100812853Sgabeblack@google.com friend bool operator op (tp, const sc_fxnum_fast &); 100912853Sgabeblack@google.com 101012853Sgabeblack@google.com#define DECL_REL_OP_OTHER(op) \ 101112853Sgabeblack@google.com DECL_REL_OP_T(op, int64) \ 101212853Sgabeblack@google.com DECL_REL_OP_T(op, uint64) \ 101312853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_int_base &) \ 101412853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_uint_base &) \ 101512853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_signed &) \ 101612853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_unsigned &) 101712853Sgabeblack@google.com 101812853Sgabeblack@google.com#define DECL_REL_OP(op) \ 101912853Sgabeblack@google.com friend bool operator op (const sc_fxnum_fast &, const sc_fxnum_fast &); \ 102012853Sgabeblack@google.com DECL_REL_OP_T(op, int) \ 102112853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned int) \ 102212853Sgabeblack@google.com DECL_REL_OP_T(op, long) \ 102312853Sgabeblack@google.com DECL_REL_OP_T(op, unsigned long) \ 102412853Sgabeblack@google.com DECL_REL_OP_T(op, float) \ 102512853Sgabeblack@google.com DECL_REL_OP_T(op, double) \ 102612853Sgabeblack@google.com DECL_REL_OP_T(op, const char *) \ 102712853Sgabeblack@google.com DECL_REL_OP_T(op, const sc_fxval_fast &) \ 102812853Sgabeblack@google.com DECL_REL_OP_OTHER(op) 102912853Sgabeblack@google.com 103012853Sgabeblack@google.com DECL_REL_OP(<) 103112853Sgabeblack@google.com DECL_REL_OP(<=) 103212853Sgabeblack@google.com DECL_REL_OP(>) 103312853Sgabeblack@google.com DECL_REL_OP(>=) 103412853Sgabeblack@google.com DECL_REL_OP(==) 103512853Sgabeblack@google.com DECL_REL_OP(!=) 103612853Sgabeblack@google.com 103712853Sgabeblack@google.com#undef DECL_REL_OP_T 103812853Sgabeblack@google.com#undef DECL_REL_OP_OTHER 103912853Sgabeblack@google.com#undef DECL_REL_OP 104012853Sgabeblack@google.com 104112853Sgabeblack@google.com // assignment operators 104212853Sgabeblack@google.com#define DECL_ASN_OP_T(op, tp) sc_fxnum_fast &operator op(tp); 104312853Sgabeblack@google.com 104412853Sgabeblack@google.com#define DECL_ASN_OP_OTHER(op) \ 104512853Sgabeblack@google.com DECL_ASN_OP_T(op, int64) \ 104612853Sgabeblack@google.com DECL_ASN_OP_T(op, uint64) \ 104712853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_int_base &) \ 104812853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_uint_base &) \ 104912853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_signed &) \ 105012853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_unsigned &) 105112853Sgabeblack@google.com 105212853Sgabeblack@google.com#define DECL_ASN_OP(op) \ 105312853Sgabeblack@google.com DECL_ASN_OP_T(op, int) \ 105412853Sgabeblack@google.com DECL_ASN_OP_T(op, unsigned int) \ 105512853Sgabeblack@google.com DECL_ASN_OP_T(op, long) \ 105612853Sgabeblack@google.com DECL_ASN_OP_T(op, unsigned long) \ 105712853Sgabeblack@google.com DECL_ASN_OP_T(op, float) \ 105812853Sgabeblack@google.com DECL_ASN_OP_T(op, double) \ 105912853Sgabeblack@google.com DECL_ASN_OP_T(op, const char *) \ 106012853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxval &) \ 106112853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxval_fast &) \ 106212853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum &) \ 106312853Sgabeblack@google.com DECL_ASN_OP_T(op, const sc_fxnum_fast &) \ 106412853Sgabeblack@google.com DECL_ASN_OP_OTHER(op) 106512853Sgabeblack@google.com 106612853Sgabeblack@google.com DECL_ASN_OP(=) 106712853Sgabeblack@google.com 106812853Sgabeblack@google.com DECL_ASN_OP(*=) 106912853Sgabeblack@google.com DECL_ASN_OP(/=) 107012853Sgabeblack@google.com DECL_ASN_OP(+=) 107112853Sgabeblack@google.com DECL_ASN_OP(-=) 107212853Sgabeblack@google.com 107312853Sgabeblack@google.com DECL_ASN_OP_T(<<=, int) 107412853Sgabeblack@google.com DECL_ASN_OP_T(>>=, int) 107512853Sgabeblack@google.com 107612853Sgabeblack@google.com#undef DECL_ASN_OP_T 107712853Sgabeblack@google.com#undef DECL_ASN_OP_OTHER 107812853Sgabeblack@google.com#undef DECL_ASN_OP 107912853Sgabeblack@google.com 108012853Sgabeblack@google.com // auto-increment and auto-decrement 108112853Sgabeblack@google.com const sc_fxval_fast operator ++ (int); 108212853Sgabeblack@google.com const sc_fxval_fast operator -- (int); 108312853Sgabeblack@google.com 108412853Sgabeblack@google.com sc_fxnum_fast &operator ++ (); 108512853Sgabeblack@google.com sc_fxnum_fast &operator -- (); 108612853Sgabeblack@google.com 108712853Sgabeblack@google.com // bit selection 108812853Sgabeblack@google.com const sc_fxnum_fast_bitref operator [] (int) const; 108912853Sgabeblack@google.com sc_fxnum_fast_bitref operator [] (int); 109012853Sgabeblack@google.com 109112853Sgabeblack@google.com const sc_fxnum_fast_bitref bit(int) const; 109212853Sgabeblack@google.com sc_fxnum_fast_bitref bit(int); 109312853Sgabeblack@google.com 109412853Sgabeblack@google.com // part selection 109512853Sgabeblack@google.com const sc_fxnum_fast_subref operator () (int, int) const; 109612853Sgabeblack@google.com sc_fxnum_fast_subref operator () (int, int); 109712853Sgabeblack@google.com 109812853Sgabeblack@google.com const sc_fxnum_fast_subref range(int, int) const; 109912853Sgabeblack@google.com sc_fxnum_fast_subref range(int, int); 110012853Sgabeblack@google.com 110112853Sgabeblack@google.com 110212853Sgabeblack@google.com const sc_fxnum_fast_subref operator () () const; 110312853Sgabeblack@google.com sc_fxnum_fast_subref operator () (); 110412853Sgabeblack@google.com 110512853Sgabeblack@google.com const sc_fxnum_fast_subref range() const; 110612853Sgabeblack@google.com sc_fxnum_fast_subref range(); 110712853Sgabeblack@google.com 110812853Sgabeblack@google.com // implicit conversion 110912853Sgabeblack@google.com operator double() const; // necessary evil! 111012853Sgabeblack@google.com 111112853Sgabeblack@google.com // explicit conversion to primitive types 111212853Sgabeblack@google.com short to_short() const; 111312853Sgabeblack@google.com unsigned short to_ushort() const; 111412853Sgabeblack@google.com int to_int() const; 111512853Sgabeblack@google.com unsigned int to_uint() const; 111612853Sgabeblack@google.com long to_long() const; 111712853Sgabeblack@google.com unsigned long to_ulong() const; 111812853Sgabeblack@google.com int64 to_int64() const; 111912853Sgabeblack@google.com uint64 to_uint64() const; 112012853Sgabeblack@google.com float to_float() const; 112112853Sgabeblack@google.com double to_double() const; 112212853Sgabeblack@google.com 112312853Sgabeblack@google.com // explicit conversion to character string 112412853Sgabeblack@google.com const std::string to_string() const; 112512853Sgabeblack@google.com const std::string to_string(sc_numrep) const; 112612853Sgabeblack@google.com const std::string to_string(sc_numrep, bool) const; 112712853Sgabeblack@google.com const std::string to_string(sc_fmt) const; 112812853Sgabeblack@google.com const std::string to_string(sc_numrep, sc_fmt) const; 112912853Sgabeblack@google.com const std::string to_string(sc_numrep, bool, sc_fmt) const; 113012853Sgabeblack@google.com 113112853Sgabeblack@google.com const std::string to_dec() const; 113212853Sgabeblack@google.com const std::string to_bin() const; 113312853Sgabeblack@google.com const std::string to_oct() const; 113412853Sgabeblack@google.com const std::string to_hex() const; 113512853Sgabeblack@google.com 113612853Sgabeblack@google.com // query value 113712853Sgabeblack@google.com bool is_neg() const; 113812853Sgabeblack@google.com bool is_zero() const; 113912853Sgabeblack@google.com 114012853Sgabeblack@google.com // internal use only; 114112853Sgabeblack@google.com bool is_normal() const; 114212853Sgabeblack@google.com 114312853Sgabeblack@google.com bool quantization_flag() const; 114412853Sgabeblack@google.com bool overflow_flag() const; 114512853Sgabeblack@google.com 114612853Sgabeblack@google.com const sc_fxval_fast value() const; 114712853Sgabeblack@google.com 114812853Sgabeblack@google.com // query parameters 114912853Sgabeblack@google.com int wl() const; 115012853Sgabeblack@google.com int iwl() const; 115112853Sgabeblack@google.com sc_q_mode q_mode() const; 115212853Sgabeblack@google.com sc_o_mode o_mode() const; 115312853Sgabeblack@google.com int n_bits() const; 115412853Sgabeblack@google.com 115512853Sgabeblack@google.com const sc_fxtype_params &type_params() const; 115612853Sgabeblack@google.com 115712853Sgabeblack@google.com const sc_fxcast_switch &cast_switch() const; 115812853Sgabeblack@google.com 115912853Sgabeblack@google.com // print or dump content 116012853Sgabeblack@google.com void print(::std::ostream & =::std::cout) const; 116112853Sgabeblack@google.com void scan(::std::istream & =::std::cin); 116212853Sgabeblack@google.com void dump(::std::ostream & =::std::cout) const; 116312853Sgabeblack@google.com 116412853Sgabeblack@google.com // internal use only; 116512853Sgabeblack@google.com void observer_read() const; 116612853Sgabeblack@google.com 116712853Sgabeblack@google.com // internal use only; 116812853Sgabeblack@google.com bool get_bit(int) const; 116912853Sgabeblack@google.com 117012853Sgabeblack@google.com protected: 117112853Sgabeblack@google.com bool set_bit(int, bool); 117212853Sgabeblack@google.com 117312853Sgabeblack@google.com bool get_slice(int, int, sc_bv_base &) const; 117412853Sgabeblack@google.com bool set_slice(int, int, const sc_bv_base &); 117512853Sgabeblack@google.com 117612853Sgabeblack@google.com sc_fxnum_fast_observer *lock_observer() const; 117712853Sgabeblack@google.com void unlock_observer(sc_fxnum_fast_observer *) const; 117812853Sgabeblack@google.com 117912853Sgabeblack@google.com private: 118012853Sgabeblack@google.com double m_val; 118112853Sgabeblack@google.com 118212853Sgabeblack@google.com scfx_params m_params; 118312853Sgabeblack@google.com bool m_q_flag; 118412853Sgabeblack@google.com bool m_o_flag; 118512853Sgabeblack@google.com 118612853Sgabeblack@google.com mutable sc_fxnum_fast_observer *m_observer; 118712853Sgabeblack@google.com 118812853Sgabeblack@google.com private: 118912853Sgabeblack@google.com // Disabled 119012853Sgabeblack@google.com sc_fxnum_fast(); 119112853Sgabeblack@google.com sc_fxnum_fast(const sc_fxnum_fast &); 119212853Sgabeblack@google.com}; 119312853Sgabeblack@google.com 119412853Sgabeblack@google.com 119512853Sgabeblack@google.com// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 119612853Sgabeblack@google.com 119712853Sgabeblack@google.com// ---------------------------------------------------------------------------- 119812853Sgabeblack@google.com// CLASS : sc_fxnum_bitref 119912853Sgabeblack@google.com// 120012853Sgabeblack@google.com// Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit. 120112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 120212853Sgabeblack@google.com 120312853Sgabeblack@google.com// constructor 120412853Sgabeblack@google.com 120512853Sgabeblack@google.cominline 120612853Sgabeblack@google.comsc_fxnum_bitref::sc_fxnum_bitref(sc_fxnum &num_, int idx_) : 120712853Sgabeblack@google.com m_num(num_), m_idx(idx_) 120812853Sgabeblack@google.com{} 120912853Sgabeblack@google.com 121012853Sgabeblack@google.com// copy constructor 121112853Sgabeblack@google.cominline sc_fxnum_bitref::sc_fxnum_bitref(const sc_fxnum_bitref &a) : 121212853Sgabeblack@google.com m_num(a.m_num), m_idx(a.m_idx) 121312853Sgabeblack@google.com{} 121412853Sgabeblack@google.com 121512853Sgabeblack@google.com// assignment operators 121612853Sgabeblack@google.cominline sc_fxnum_bitref & 121712853Sgabeblack@google.comsc_fxnum_bitref::operator = (const sc_fxnum_bitref &a) 121812853Sgabeblack@google.com{ 121912853Sgabeblack@google.com if (&a != this) { 122012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a.m_num) 122112853Sgabeblack@google.com set(a.get()); 122212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 122312853Sgabeblack@google.com } 122412853Sgabeblack@google.com return *this; 122512853Sgabeblack@google.com} 122612853Sgabeblack@google.com 122712853Sgabeblack@google.cominline sc_fxnum_bitref & 122812853Sgabeblack@google.comsc_fxnum_bitref::operator = (const sc_fxnum_fast_bitref &a) 122912853Sgabeblack@google.com{ 123012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a.m_num) 123112853Sgabeblack@google.com set(a.get()); 123212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 123312853Sgabeblack@google.com return *this; 123412853Sgabeblack@google.com} 123512853Sgabeblack@google.com 123612853Sgabeblack@google.cominline sc_fxnum_bitref & 123712853Sgabeblack@google.comsc_fxnum_bitref::operator = (const sc_bit &a) 123812853Sgabeblack@google.com{ 123912853Sgabeblack@google.com set(static_cast<bool>(a)); 124012853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 124112853Sgabeblack@google.com return *this; 124212853Sgabeblack@google.com} 124312853Sgabeblack@google.com 124412853Sgabeblack@google.cominline sc_fxnum_bitref & 124512853Sgabeblack@google.comsc_fxnum_bitref::operator = (bool a) 124612853Sgabeblack@google.com{ 124712853Sgabeblack@google.com set(a); 124812853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 124912853Sgabeblack@google.com return *this; 125012853Sgabeblack@google.com} 125112853Sgabeblack@google.com 125212853Sgabeblack@google.cominline sc_fxnum_bitref & 125312853Sgabeblack@google.comsc_fxnum_bitref::operator &= (const sc_fxnum_bitref &b) 125412853Sgabeblack@google.com{ 125512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 125612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 125712853Sgabeblack@google.com set(get() && b.get()); 125812853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 125912853Sgabeblack@google.com return *this; 126012853Sgabeblack@google.com} 126112853Sgabeblack@google.com 126212853Sgabeblack@google.cominline sc_fxnum_bitref & 126312853Sgabeblack@google.comsc_fxnum_bitref::operator &= (const sc_fxnum_fast_bitref &b) 126412853Sgabeblack@google.com{ 126512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 126612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 126712853Sgabeblack@google.com set(get() && b.get()); 126812853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 126912853Sgabeblack@google.com return *this; 127012853Sgabeblack@google.com} 127112853Sgabeblack@google.com 127212853Sgabeblack@google.cominline sc_fxnum_bitref & 127312853Sgabeblack@google.comsc_fxnum_bitref::operator &= (const sc_bit &b) 127412853Sgabeblack@google.com{ 127512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 127612853Sgabeblack@google.com set(get() && static_cast<bool>(b)); 127712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 127812853Sgabeblack@google.com return *this; 127912853Sgabeblack@google.com} 128012853Sgabeblack@google.com 128112853Sgabeblack@google.cominline sc_fxnum_bitref & 128212853Sgabeblack@google.comsc_fxnum_bitref::operator &= (bool b) 128312853Sgabeblack@google.com{ 128412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 128512853Sgabeblack@google.com set(get() && b); 128612853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 128712853Sgabeblack@google.com return *this; 128812853Sgabeblack@google.com} 128912853Sgabeblack@google.com 129012853Sgabeblack@google.com 129112853Sgabeblack@google.cominline sc_fxnum_bitref & 129212853Sgabeblack@google.comsc_fxnum_bitref::operator |= (const sc_fxnum_bitref &b) 129312853Sgabeblack@google.com{ 129412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 129512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 129612853Sgabeblack@google.com set(get() || b.get()); 129712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 129812853Sgabeblack@google.com return *this; 129912853Sgabeblack@google.com} 130012853Sgabeblack@google.com 130112853Sgabeblack@google.cominline sc_fxnum_bitref & 130212853Sgabeblack@google.comsc_fxnum_bitref::operator |= (const sc_fxnum_fast_bitref &b) 130312853Sgabeblack@google.com{ 130412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 130512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 130612853Sgabeblack@google.com set(get() || b.get()); 130712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 130812853Sgabeblack@google.com return *this; 130912853Sgabeblack@google.com} 131012853Sgabeblack@google.com 131112853Sgabeblack@google.cominline sc_fxnum_bitref & 131212853Sgabeblack@google.comsc_fxnum_bitref::operator |= (const sc_bit &b) 131312853Sgabeblack@google.com{ 131412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 131512853Sgabeblack@google.com set(get() || static_cast<bool>(b)); 131612853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 131712853Sgabeblack@google.com return *this; 131812853Sgabeblack@google.com} 131912853Sgabeblack@google.com 132012853Sgabeblack@google.cominline sc_fxnum_bitref & 132112853Sgabeblack@google.comsc_fxnum_bitref::operator |= (bool b) 132212853Sgabeblack@google.com{ 132312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 132412853Sgabeblack@google.com set(get() || b); 132512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 132612853Sgabeblack@google.com return *this; 132712853Sgabeblack@google.com} 132812853Sgabeblack@google.com 132912853Sgabeblack@google.com 133012853Sgabeblack@google.cominline sc_fxnum_bitref & 133112853Sgabeblack@google.comsc_fxnum_bitref::operator ^= (const sc_fxnum_bitref &b) 133212853Sgabeblack@google.com{ 133312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 133412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 133512853Sgabeblack@google.com set(get() != b.get()); 133612853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 133712853Sgabeblack@google.com return *this; 133812853Sgabeblack@google.com} 133912853Sgabeblack@google.com 134012853Sgabeblack@google.cominline sc_fxnum_bitref & 134112853Sgabeblack@google.comsc_fxnum_bitref::operator ^= (const sc_fxnum_fast_bitref &b) 134212853Sgabeblack@google.com{ 134312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 134412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 134512853Sgabeblack@google.com set(get() != b.get()); 134612853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 134712853Sgabeblack@google.com return *this; 134812853Sgabeblack@google.com} 134912853Sgabeblack@google.com 135012853Sgabeblack@google.cominline sc_fxnum_bitref & 135112853Sgabeblack@google.comsc_fxnum_bitref::operator ^= (const sc_bit &b) 135212853Sgabeblack@google.com{ 135312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 135412853Sgabeblack@google.com set(get() != static_cast<bool>(b)); 135512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 135612853Sgabeblack@google.com return *this; 135712853Sgabeblack@google.com} 135812853Sgabeblack@google.com 135912853Sgabeblack@google.cominline sc_fxnum_bitref & 136012853Sgabeblack@google.comsc_fxnum_bitref::operator ^= (bool b) 136112853Sgabeblack@google.com{ 136212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 136312853Sgabeblack@google.com set(get() != b); 136412853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 136512853Sgabeblack@google.com return *this; 136612853Sgabeblack@google.com} 136712853Sgabeblack@google.com 136812853Sgabeblack@google.com// implicit conversion 136912853Sgabeblack@google.cominline sc_fxnum_bitref::operator bool() const 137012853Sgabeblack@google.com{ 137112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 137212853Sgabeblack@google.com return get(); 137312853Sgabeblack@google.com} 137412853Sgabeblack@google.com 137512853Sgabeblack@google.cominline ::std::ostream & 137612853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum_bitref &a) 137712853Sgabeblack@google.com{ 137812853Sgabeblack@google.com a.print(os); 137912853Sgabeblack@google.com return os; 138012853Sgabeblack@google.com} 138112853Sgabeblack@google.com 138212853Sgabeblack@google.cominline ::std::istream & 138312853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum_bitref &a) 138412853Sgabeblack@google.com{ 138512853Sgabeblack@google.com a.scan(is); 138612853Sgabeblack@google.com return is; 138712853Sgabeblack@google.com} 138812853Sgabeblack@google.com 138912853Sgabeblack@google.com 139012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 139112853Sgabeblack@google.com// CLASS : sc_fxnum_fast_bitref 139212853Sgabeblack@google.com// 139312853Sgabeblack@google.com// Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit. 139412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 139512853Sgabeblack@google.com 139612853Sgabeblack@google.com// constructor 139712853Sgabeblack@google.cominline sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( 139812853Sgabeblack@google.com sc_fxnum_fast &num_, int idx_) : m_num(num_), m_idx(idx_) 139912853Sgabeblack@google.com{} 140012853Sgabeblack@google.com 140112853Sgabeblack@google.com// copy constructor 140212853Sgabeblack@google.cominline sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( 140312853Sgabeblack@google.com const sc_fxnum_fast_bitref &a) : m_num(a.m_num), m_idx(a.m_idx) 140412853Sgabeblack@google.com{} 140512853Sgabeblack@google.com 140612853Sgabeblack@google.com// assignment operators 140712853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 140812853Sgabeblack@google.comsc_fxnum_fast_bitref::operator = (const sc_fxnum_bitref &a) 140912853Sgabeblack@google.com{ 141012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a.m_num) 141112853Sgabeblack@google.com set(a.get()); 141212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 141312853Sgabeblack@google.com return *this; 141412853Sgabeblack@google.com} 141512853Sgabeblack@google.com 141612853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 141712853Sgabeblack@google.comsc_fxnum_fast_bitref::operator = (const sc_fxnum_fast_bitref &a) 141812853Sgabeblack@google.com{ 141912853Sgabeblack@google.com if (&a != this) { 142012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a.m_num) 142112853Sgabeblack@google.com set(a.get()); 142212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 142312853Sgabeblack@google.com } 142412853Sgabeblack@google.com return *this; 142512853Sgabeblack@google.com} 142612853Sgabeblack@google.com 142712853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 142812853Sgabeblack@google.comsc_fxnum_fast_bitref::operator = (const sc_bit &a) 142912853Sgabeblack@google.com{ 143012853Sgabeblack@google.com set(static_cast<bool>(a)); 143112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 143212853Sgabeblack@google.com return *this; 143312853Sgabeblack@google.com} 143412853Sgabeblack@google.com 143512853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 143612853Sgabeblack@google.comsc_fxnum_fast_bitref::operator = (bool a) 143712853Sgabeblack@google.com{ 143812853Sgabeblack@google.com set(a); 143912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 144012853Sgabeblack@google.com return *this; 144112853Sgabeblack@google.com} 144212853Sgabeblack@google.com 144312853Sgabeblack@google.com 144412853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 144512853Sgabeblack@google.comsc_fxnum_fast_bitref::operator &= (const sc_fxnum_bitref &b) 144612853Sgabeblack@google.com{ 144712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 144812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 144912853Sgabeblack@google.com set(get() && b.get()); 145012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 145112853Sgabeblack@google.com return *this; 145212853Sgabeblack@google.com} 145312853Sgabeblack@google.com 145412853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 145512853Sgabeblack@google.comsc_fxnum_fast_bitref::operator &= (const sc_fxnum_fast_bitref &b) 145612853Sgabeblack@google.com{ 145712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 145812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 145912853Sgabeblack@google.com set(get() && b.get()); 146012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 146112853Sgabeblack@google.com return *this; 146212853Sgabeblack@google.com} 146312853Sgabeblack@google.com 146412853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 146512853Sgabeblack@google.comsc_fxnum_fast_bitref::operator &= (const sc_bit &b) 146612853Sgabeblack@google.com{ 146712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 146812853Sgabeblack@google.com set(get() && static_cast<bool>(b)); 146912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 147012853Sgabeblack@google.com return *this; 147112853Sgabeblack@google.com} 147212853Sgabeblack@google.com 147312853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 147412853Sgabeblack@google.comsc_fxnum_fast_bitref::operator &= (bool b) 147512853Sgabeblack@google.com{ 147612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 147712853Sgabeblack@google.com set(get() && b); 147812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 147912853Sgabeblack@google.com return *this; 148012853Sgabeblack@google.com} 148112853Sgabeblack@google.com 148212853Sgabeblack@google.com 148312853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 148412853Sgabeblack@google.comsc_fxnum_fast_bitref::operator |= (const sc_fxnum_bitref &b) 148512853Sgabeblack@google.com{ 148612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 148712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 148812853Sgabeblack@google.com set(get() || b.get()); 148912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 149012853Sgabeblack@google.com return *this; 149112853Sgabeblack@google.com} 149212853Sgabeblack@google.com 149312853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 149412853Sgabeblack@google.comsc_fxnum_fast_bitref::operator |= (const sc_fxnum_fast_bitref &b) 149512853Sgabeblack@google.com{ 149612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 149712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 149812853Sgabeblack@google.com set(get() || b.get()); 149912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 150012853Sgabeblack@google.com return *this; 150112853Sgabeblack@google.com} 150212853Sgabeblack@google.com 150312853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 150412853Sgabeblack@google.comsc_fxnum_fast_bitref::operator |= (const sc_bit &b) 150512853Sgabeblack@google.com{ 150612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 150712853Sgabeblack@google.com set(get() || static_cast<bool>(b)); 150812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 150912853Sgabeblack@google.com return *this; 151012853Sgabeblack@google.com} 151112853Sgabeblack@google.com 151212853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 151312853Sgabeblack@google.comsc_fxnum_fast_bitref::operator |= (bool b) 151412853Sgabeblack@google.com{ 151512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 151612853Sgabeblack@google.com set(get() || b); 151712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 151812853Sgabeblack@google.com return *this; 151912853Sgabeblack@google.com} 152012853Sgabeblack@google.com 152112853Sgabeblack@google.com 152212853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 152312853Sgabeblack@google.comsc_fxnum_fast_bitref::operator ^= (const sc_fxnum_bitref &b) 152412853Sgabeblack@google.com{ 152512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 152612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b.m_num) 152712853Sgabeblack@google.com set(get() != b.get()); 152812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 152912853Sgabeblack@google.com return *this; 153012853Sgabeblack@google.com} 153112853Sgabeblack@google.com 153212853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 153312853Sgabeblack@google.comsc_fxnum_fast_bitref::operator ^= (const sc_fxnum_fast_bitref &b) 153412853Sgabeblack@google.com{ 153512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 153612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b.m_num) 153712853Sgabeblack@google.com set(get() != b.get()); 153812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 153912853Sgabeblack@google.com return *this; 154012853Sgabeblack@google.com} 154112853Sgabeblack@google.com 154212853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 154312853Sgabeblack@google.comsc_fxnum_fast_bitref::operator ^= (const sc_bit &b) 154412853Sgabeblack@google.com{ 154512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 154612853Sgabeblack@google.com set(get() != static_cast<bool>(b)); 154712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 154812853Sgabeblack@google.com return *this; 154912853Sgabeblack@google.com} 155012853Sgabeblack@google.com 155112853Sgabeblack@google.cominline sc_fxnum_fast_bitref & 155212853Sgabeblack@google.comsc_fxnum_fast_bitref::operator ^= (bool b) 155312853Sgabeblack@google.com{ 155412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 155512853Sgabeblack@google.com set(get() != b); 155612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 155712853Sgabeblack@google.com return *this; 155812853Sgabeblack@google.com} 155912853Sgabeblack@google.com 156012853Sgabeblack@google.com 156112853Sgabeblack@google.com// implicit conversion 156212853Sgabeblack@google.cominline sc_fxnum_fast_bitref::operator bool() const 156312853Sgabeblack@google.com{ 156412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 156512853Sgabeblack@google.com return get(); 156612853Sgabeblack@google.com} 156712853Sgabeblack@google.com 156812853Sgabeblack@google.cominline ::std::ostream & 156912853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum_fast_bitref &a) 157012853Sgabeblack@google.com{ 157112853Sgabeblack@google.com a.print(os); 157212853Sgabeblack@google.com return os; 157312853Sgabeblack@google.com} 157412853Sgabeblack@google.com 157512853Sgabeblack@google.cominline ::std::istream & 157612853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum_fast_bitref &a) 157712853Sgabeblack@google.com{ 157812853Sgabeblack@google.com a.scan(is); 157912853Sgabeblack@google.com return is; 158012853Sgabeblack@google.com} 158112853Sgabeblack@google.com 158212853Sgabeblack@google.com 158312853Sgabeblack@google.com// ---------------------------------------------------------------------------- 158412853Sgabeblack@google.com// CLASS : sc_fxnum_subref 158512853Sgabeblack@google.com// 158612853Sgabeblack@google.com// Proxy class for part-selection in class sc_fxnum, 158712853Sgabeblack@google.com// behaves like sc_bv_base. 158812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 158912853Sgabeblack@google.com 159012853Sgabeblack@google.com// constructor 159112853Sgabeblack@google.cominline sc_fxnum_subref::sc_fxnum_subref(sc_fxnum &num_, int from_, int to_) : 159212853Sgabeblack@google.com m_num(num_), m_from(from_), m_to(to_), 159312853Sgabeblack@google.com m_bv(*new sc_bv_base(sc_max(m_from, m_to) - sc_min(m_from, m_to) + 1)) 159412853Sgabeblack@google.com{} 159512853Sgabeblack@google.com 159612853Sgabeblack@google.com// copy constructor 159712853Sgabeblack@google.cominline sc_fxnum_subref::sc_fxnum_subref(const sc_fxnum_subref &a) : 159812853Sgabeblack@google.com m_num(a.m_num), m_from(a.m_from), m_to(a.m_to), 159912853Sgabeblack@google.com m_bv(*new sc_bv_base(a.m_bv)) 160012853Sgabeblack@google.com{} 160112853Sgabeblack@google.com 160212853Sgabeblack@google.com// destructor 160312853Sgabeblack@google.cominline sc_fxnum_subref::~sc_fxnum_subref() 160412853Sgabeblack@google.com{ 160512853Sgabeblack@google.com delete &m_bv; 160612853Sgabeblack@google.com} 160712853Sgabeblack@google.com 160812853Sgabeblack@google.com// assignment operators 160912853Sgabeblack@google.cominline sc_fxnum_subref & 161012853Sgabeblack@google.comsc_fxnum_subref::operator = (const sc_fxnum_subref &a) 161112853Sgabeblack@google.com{ 161212853Sgabeblack@google.com if (&a != this) { 161312853Sgabeblack@google.com m_bv = static_cast<sc_bv_base>(a); 161412853Sgabeblack@google.com set(); 161512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 161612853Sgabeblack@google.com } 161712853Sgabeblack@google.com return *this; 161812853Sgabeblack@google.com} 161912853Sgabeblack@google.com 162012853Sgabeblack@google.cominline sc_fxnum_subref & 162112853Sgabeblack@google.comsc_fxnum_subref::operator = (const sc_fxnum_fast_subref &a) 162212853Sgabeblack@google.com{ 162312853Sgabeblack@google.com m_bv = static_cast<sc_bv_base>(a); 162412853Sgabeblack@google.com set(); 162512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) 162612853Sgabeblack@google.com return *this; 162712853Sgabeblack@google.com} 162812853Sgabeblack@google.com 162912853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 163012853Sgabeblack@google.cominline sc_fxnum_subref & \ 163112853Sgabeblack@google.comsc_fxnum_subref::operator = (tp a) \ 163212853Sgabeblack@google.com{ \ 163312853Sgabeblack@google.com m_bv = a; \ 163412853Sgabeblack@google.com set(); \ 163512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) \ 163612853Sgabeblack@google.com return *this; \ 163712853Sgabeblack@google.com} 163812853Sgabeblack@google.com 163912853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_bv_base &) 164012853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_lv_base &) 164112853Sgabeblack@google.comDEFN_ASN_OP_T(const char *) 164212853Sgabeblack@google.comDEFN_ASN_OP_T(const bool *) 164312853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_signed &) 164412853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_unsigned &) 164512853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_int_base &) 164612853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_uint_base &) 164712853Sgabeblack@google.comDEFN_ASN_OP_T(int64) 164812853Sgabeblack@google.comDEFN_ASN_OP_T(uint64) 164912853Sgabeblack@google.comDEFN_ASN_OP_T(int) 165012853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned int) 165112853Sgabeblack@google.comDEFN_ASN_OP_T(long) 165212853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned long) 165312853Sgabeblack@google.comDEFN_ASN_OP_T(char) 165412853Sgabeblack@google.com 165512853Sgabeblack@google.com#undef DEFN_ASN_OP_T 165612853Sgabeblack@google.com 165712853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, tp) \ 165812853Sgabeblack@google.cominline sc_fxnum_subref & \ 165912853Sgabeblack@google.comsc_fxnum_subref::operator op ## = (tp a) \ 166012853Sgabeblack@google.com{ \ 166112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) \ 166212853Sgabeblack@google.com get(); \ 166312853Sgabeblack@google.com m_bv = m_bv op a; \ 166412853Sgabeblack@google.com set(); \ 166512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) \ 166612853Sgabeblack@google.com return *this; \ 166712853Sgabeblack@google.com} 166812853Sgabeblack@google.com 166912853Sgabeblack@google.com#define DEFN_ASN_OP(op) \ 167012853Sgabeblack@google.cominline sc_fxnum_subref & \ 167112853Sgabeblack@google.comsc_fxnum_subref::operator op ## = (const sc_fxnum_subref &a) \ 167212853Sgabeblack@google.com{ \ 167312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) \ 167412853Sgabeblack@google.com get(); \ 167512853Sgabeblack@google.com m_bv = m_bv op static_cast<sc_bv_base>(a); \ 167612853Sgabeblack@google.com set(); \ 167712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) \ 167812853Sgabeblack@google.com return *this; \ 167912853Sgabeblack@google.com} \ 168012853Sgabeblack@google.com \ 168112853Sgabeblack@google.cominline sc_fxnum_subref & \ 168212853Sgabeblack@google.comsc_fxnum_subref::operator op ## = (const sc_fxnum_fast_subref &a) \ 168312853Sgabeblack@google.com{ \ 168412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) \ 168512853Sgabeblack@google.com get(); \ 168612853Sgabeblack@google.com m_bv = m_bv op static_cast<sc_bv_base>(a); \ 168712853Sgabeblack@google.com set(); \ 168812853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(m_num) \ 168912853Sgabeblack@google.com return *this; \ 169012853Sgabeblack@google.com} \ 169112853Sgabeblack@google.com \ 169212853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_bv_base &) \ 169312853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_lv_base &) 169412853Sgabeblack@google.com 169512853Sgabeblack@google.comDEFN_ASN_OP( &) 169612853Sgabeblack@google.comDEFN_ASN_OP(|) 169712853Sgabeblack@google.comDEFN_ASN_OP(^) 169812853Sgabeblack@google.com 169912853Sgabeblack@google.com#undef DEFN_ASN_OP_T 170012853Sgabeblack@google.com#undef DEFN_ASN_OP 170112853Sgabeblack@google.com 170212853Sgabeblack@google.com// relational operators 170312853Sgabeblack@google.com#define DEFN_REL_OP_T(op, tp) \ 170412853Sgabeblack@google.cominline bool \ 170512853Sgabeblack@google.comoperator op (const sc_fxnum_subref &a, tp b) \ 170612853Sgabeblack@google.com{ \ 170712853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op b); \ 170812853Sgabeblack@google.com} \ 170912853Sgabeblack@google.com \ 171012853Sgabeblack@google.cominline bool \ 171112853Sgabeblack@google.comoperator op (tp a, const sc_fxnum_subref &b) \ 171212853Sgabeblack@google.com{ \ 171312853Sgabeblack@google.com return (static_cast<sc_bv_base>(b) op a); \ 171412853Sgabeblack@google.com} 171512853Sgabeblack@google.com 171612853Sgabeblack@google.com#define DEFN_REL_OP(op) \ 171712853Sgabeblack@google.cominline bool \ 171812853Sgabeblack@google.comoperator op (const sc_fxnum_subref &a, const sc_fxnum_subref &b) \ 171912853Sgabeblack@google.com{ \ 172012853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op static_cast<sc_bv_base>(b)); \ 172112853Sgabeblack@google.com} \ 172212853Sgabeblack@google.com \ 172312853Sgabeblack@google.cominline bool \ 172412853Sgabeblack@google.comoperator op (const sc_fxnum_subref &a, const sc_fxnum_fast_subref &b) \ 172512853Sgabeblack@google.com{ \ 172612853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op static_cast<sc_bv_base>(b)); \ 172712853Sgabeblack@google.com} \ 172812853Sgabeblack@google.com \ 172912853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_bv_base &) \ 173012853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_lv_base &) \ 173112853Sgabeblack@google.comDEFN_REL_OP_T(op, const char *) \ 173212853Sgabeblack@google.comDEFN_REL_OP_T(op, const bool *) \ 173312853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_signed &) \ 173412853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_unsigned &) \ 173512853Sgabeblack@google.comDEFN_REL_OP_T(op, int) \ 173612853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned int) \ 173712853Sgabeblack@google.comDEFN_REL_OP_T(op, long) \ 173812853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned long) 173912853Sgabeblack@google.com 174012853Sgabeblack@google.comDEFN_REL_OP(==) 174112853Sgabeblack@google.comDEFN_REL_OP(!=) 174212853Sgabeblack@google.com 174312853Sgabeblack@google.com#undef DEFN_REL_OP_T 174412853Sgabeblack@google.com#undef DEFN_REL_OP 174512853Sgabeblack@google.com 174612853Sgabeblack@google.com 174712853Sgabeblack@google.com// reduce functions 174812853Sgabeblack@google.com 174912853Sgabeblack@google.com#define DEFN_RED_FNC(fnc) \ 175012853Sgabeblack@google.cominline bool \ 175112853Sgabeblack@google.comsc_fxnum_subref::fnc() const \ 175212853Sgabeblack@google.com{ \ 175312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) \ 175412853Sgabeblack@google.com get(); \ 175512853Sgabeblack@google.com return static_cast<bool>(m_bv.fnc()); \ 175612853Sgabeblack@google.com} 175712853Sgabeblack@google.com 175812853Sgabeblack@google.comDEFN_RED_FNC(and_reduce) 175912853Sgabeblack@google.comDEFN_RED_FNC(nand_reduce) 176012853Sgabeblack@google.comDEFN_RED_FNC(or_reduce) 176112853Sgabeblack@google.comDEFN_RED_FNC(nor_reduce) 176212853Sgabeblack@google.comDEFN_RED_FNC(xor_reduce) 176312853Sgabeblack@google.comDEFN_RED_FNC(xnor_reduce) 176412853Sgabeblack@google.com 176512853Sgabeblack@google.com#undef DEFN_RED_FNC 176612853Sgabeblack@google.com 176712853Sgabeblack@google.com// query parameter 176812853Sgabeblack@google.cominline int 176912853Sgabeblack@google.comsc_fxnum_subref::length() const 177012853Sgabeblack@google.com{ 177112853Sgabeblack@google.com return m_bv.length(); 177212853Sgabeblack@google.com} 177312853Sgabeblack@google.com 177412853Sgabeblack@google.com// explicit conversions 177512853Sgabeblack@google.cominline int 177612853Sgabeblack@google.comsc_fxnum_subref::to_int() const 177712853Sgabeblack@google.com{ 177812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 177912853Sgabeblack@google.com get(); 178012853Sgabeblack@google.com return m_bv.to_int(); 178112853Sgabeblack@google.com} 178212853Sgabeblack@google.com 178312853Sgabeblack@google.cominline int64 178412853Sgabeblack@google.comsc_fxnum_subref::to_int64() const 178512853Sgabeblack@google.com{ 178612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 178712853Sgabeblack@google.com get(); 178812853Sgabeblack@google.com return m_bv.to_int64(); 178912853Sgabeblack@google.com} 179012853Sgabeblack@google.com 179112853Sgabeblack@google.cominline unsigned int 179212853Sgabeblack@google.comsc_fxnum_subref::to_uint() const 179312853Sgabeblack@google.com{ 179412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 179512853Sgabeblack@google.com get(); 179612853Sgabeblack@google.com return m_bv.to_uint(); 179712853Sgabeblack@google.com} 179812853Sgabeblack@google.com 179912853Sgabeblack@google.cominline uint64 180012853Sgabeblack@google.comsc_fxnum_subref::to_uint64() const 180112853Sgabeblack@google.com{ 180212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 180312853Sgabeblack@google.com get(); 180412853Sgabeblack@google.com return m_bv.to_uint64(); 180512853Sgabeblack@google.com} 180612853Sgabeblack@google.com 180712853Sgabeblack@google.cominline long 180812853Sgabeblack@google.comsc_fxnum_subref::to_long() const 180912853Sgabeblack@google.com{ 181012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 181112853Sgabeblack@google.com get(); 181212853Sgabeblack@google.com return m_bv.to_long(); 181312853Sgabeblack@google.com} 181412853Sgabeblack@google.com 181512853Sgabeblack@google.cominline unsigned long 181612853Sgabeblack@google.comsc_fxnum_subref::to_ulong() const 181712853Sgabeblack@google.com{ 181812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 181912853Sgabeblack@google.com get(); 182012853Sgabeblack@google.com return m_bv.to_ulong(); 182112853Sgabeblack@google.com} 182212853Sgabeblack@google.com 182312853Sgabeblack@google.com 182412853Sgabeblack@google.cominline const std::string 182512853Sgabeblack@google.comsc_fxnum_subref::to_string() const 182612853Sgabeblack@google.com{ 182712853Sgabeblack@google.com get(); 182812853Sgabeblack@google.com return m_bv.to_string(); 182912853Sgabeblack@google.com} 183012853Sgabeblack@google.com 183112853Sgabeblack@google.cominline const std::string 183212853Sgabeblack@google.comsc_fxnum_subref::to_string(sc_numrep numrep) const 183312853Sgabeblack@google.com{ 183412853Sgabeblack@google.com get(); 183512853Sgabeblack@google.com return m_bv.to_string(numrep); 183612853Sgabeblack@google.com} 183712853Sgabeblack@google.com 183812853Sgabeblack@google.cominline const std::string 183912853Sgabeblack@google.comsc_fxnum_subref::to_string(sc_numrep numrep, bool w_prefix) const 184012853Sgabeblack@google.com{ 184112853Sgabeblack@google.com get(); 184212853Sgabeblack@google.com return m_bv.to_string(numrep, w_prefix); 184312853Sgabeblack@google.com} 184412853Sgabeblack@google.com 184512853Sgabeblack@google.com 184612853Sgabeblack@google.com// implicit conversion 184712853Sgabeblack@google.cominline sc_fxnum_subref::operator sc_bv_base () const 184812853Sgabeblack@google.com{ 184912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(m_num) 185012853Sgabeblack@google.com get(); 185112853Sgabeblack@google.com return m_bv; 185212853Sgabeblack@google.com} 185312853Sgabeblack@google.com 185412853Sgabeblack@google.com 185512853Sgabeblack@google.cominline ::std::ostream & 185612853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum_subref &a) 185712853Sgabeblack@google.com{ 185812853Sgabeblack@google.com a.print(os); 185912853Sgabeblack@google.com return os; 186012853Sgabeblack@google.com} 186112853Sgabeblack@google.com 186212853Sgabeblack@google.cominline ::std::istream & 186312853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum_subref &a) 186412853Sgabeblack@google.com{ 186512853Sgabeblack@google.com a.scan(is); 186612853Sgabeblack@google.com return is; 186712853Sgabeblack@google.com} 186812853Sgabeblack@google.com 186912853Sgabeblack@google.com 187012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 187112853Sgabeblack@google.com// CLASS : sc_fxnum_fast_subref 187212853Sgabeblack@google.com// 187312853Sgabeblack@google.com// Proxy class for part-selection in class sc_fxnum_fast, 187412853Sgabeblack@google.com// behaves like sc_bv_base. 187512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 187612853Sgabeblack@google.com 187712853Sgabeblack@google.com// constructor 187812853Sgabeblack@google.com 187912853Sgabeblack@google.cominline sc_fxnum_fast_subref::sc_fxnum_fast_subref( 188012853Sgabeblack@google.com sc_fxnum_fast &num_, int from_, int to_) : 188112853Sgabeblack@google.com m_num(num_), m_from(from_), m_to(to_), 188212853Sgabeblack@google.com m_bv(*new sc_bv_base(sc_max(m_from, m_to) - sc_min(m_from, m_to) + 1)) 188312853Sgabeblack@google.com{} 188412853Sgabeblack@google.com 188512853Sgabeblack@google.com 188612853Sgabeblack@google.com// copy constructor 188712853Sgabeblack@google.cominline sc_fxnum_fast_subref::sc_fxnum_fast_subref( 188812853Sgabeblack@google.com const sc_fxnum_fast_subref &a) : 188912853Sgabeblack@google.com m_num(a.m_num), m_from(a.m_from), m_to(a.m_to), 189012853Sgabeblack@google.com m_bv(*new sc_bv_base(a.m_bv)) 189112853Sgabeblack@google.com{} 189212853Sgabeblack@google.com 189312853Sgabeblack@google.com 189412853Sgabeblack@google.com// destructor 189512853Sgabeblack@google.cominline sc_fxnum_fast_subref::~sc_fxnum_fast_subref() 189612853Sgabeblack@google.com{ 189712853Sgabeblack@google.com delete &m_bv; 189812853Sgabeblack@google.com} 189912853Sgabeblack@google.com 190012853Sgabeblack@google.com 190112853Sgabeblack@google.com// assignment operators 190212853Sgabeblack@google.cominline sc_fxnum_fast_subref & 190312853Sgabeblack@google.comsc_fxnum_fast_subref::operator = (const sc_fxnum_subref &a) 190412853Sgabeblack@google.com{ 190512853Sgabeblack@google.com m_bv = static_cast<sc_bv_base>(a); 190612853Sgabeblack@google.com set(); 190712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 190812853Sgabeblack@google.com return *this; 190912853Sgabeblack@google.com} 191012853Sgabeblack@google.com 191112853Sgabeblack@google.cominline sc_fxnum_fast_subref & 191212853Sgabeblack@google.comsc_fxnum_fast_subref::operator = (const sc_fxnum_fast_subref &a) 191312853Sgabeblack@google.com{ 191412853Sgabeblack@google.com if (&a != this) { 191512853Sgabeblack@google.com m_bv = static_cast<sc_bv_base>(a); 191612853Sgabeblack@google.com set(); 191712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) 191812853Sgabeblack@google.com } 191912853Sgabeblack@google.com return *this; 192012853Sgabeblack@google.com} 192112853Sgabeblack@google.com 192212853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 192312853Sgabeblack@google.cominline sc_fxnum_fast_subref & \ 192412853Sgabeblack@google.comsc_fxnum_fast_subref::operator = (tp a) \ 192512853Sgabeblack@google.com{ \ 192612853Sgabeblack@google.com m_bv = a; \ 192712853Sgabeblack@google.com set(); \ 192812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) \ 192912853Sgabeblack@google.com return *this; \ 193012853Sgabeblack@google.com} 193112853Sgabeblack@google.com 193212853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_bv_base &) 193312853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_lv_base &) 193412853Sgabeblack@google.comDEFN_ASN_OP_T(const char *) 193512853Sgabeblack@google.comDEFN_ASN_OP_T(const bool *) 193612853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_signed &) 193712853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_unsigned &) 193812853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_int_base &) 193912853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_uint_base &) 194012853Sgabeblack@google.comDEFN_ASN_OP_T(int64) 194112853Sgabeblack@google.comDEFN_ASN_OP_T(uint64) 194212853Sgabeblack@google.comDEFN_ASN_OP_T(int) 194312853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned int) 194412853Sgabeblack@google.comDEFN_ASN_OP_T(long) 194512853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned long) 194612853Sgabeblack@google.comDEFN_ASN_OP_T(char) 194712853Sgabeblack@google.com 194812853Sgabeblack@google.com#undef DEFN_ASN_OP_T 194912853Sgabeblack@google.com 195012853Sgabeblack@google.com 195112853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, tp) \ 195212853Sgabeblack@google.cominline sc_fxnum_fast_subref & \ 195312853Sgabeblack@google.comsc_fxnum_fast_subref::operator op ## = (tp a) \ 195412853Sgabeblack@google.com{ \ 195512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) \ 195612853Sgabeblack@google.com get(); \ 195712853Sgabeblack@google.com m_bv = m_bv op a; \ 195812853Sgabeblack@google.com set(); \ 195912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) \ 196012853Sgabeblack@google.com return *this; \ 196112853Sgabeblack@google.com} 196212853Sgabeblack@google.com 196312853Sgabeblack@google.com#define DEFN_ASN_OP(op) \ 196412853Sgabeblack@google.cominline sc_fxnum_fast_subref & \ 196512853Sgabeblack@google.comsc_fxnum_fast_subref::operator op ## = (const sc_fxnum_subref &a) \ 196612853Sgabeblack@google.com{ \ 196712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) \ 196812853Sgabeblack@google.com get(); \ 196912853Sgabeblack@google.com m_bv = m_bv op static_cast<sc_bv_base>(a); \ 197012853Sgabeblack@google.com set(); \ 197112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) \ 197212853Sgabeblack@google.com return *this; \ 197312853Sgabeblack@google.com} \ 197412853Sgabeblack@google.com \ 197512853Sgabeblack@google.cominline sc_fxnum_fast_subref & \ 197612853Sgabeblack@google.comsc_fxnum_fast_subref::operator op ## = (const sc_fxnum_fast_subref &a) \ 197712853Sgabeblack@google.com{ \ 197812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) \ 197912853Sgabeblack@google.com get(); \ 198012853Sgabeblack@google.com m_bv = m_bv op static_cast<sc_bv_base>(a); \ 198112853Sgabeblack@google.com set(); \ 198212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(m_num) \ 198312853Sgabeblack@google.com return *this; \ 198412853Sgabeblack@google.com} \ 198512853Sgabeblack@google.com \ 198612853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_bv_base &) \ 198712853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_lv_base &) 198812853Sgabeblack@google.com 198912853Sgabeblack@google.comDEFN_ASN_OP(&) 199012853Sgabeblack@google.comDEFN_ASN_OP(|) 199112853Sgabeblack@google.comDEFN_ASN_OP(^) 199212853Sgabeblack@google.com 199312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 199412853Sgabeblack@google.com#undef DEFN_ASN_OP 199512853Sgabeblack@google.com 199612853Sgabeblack@google.com 199712853Sgabeblack@google.com// relational operators 199812853Sgabeblack@google.com 199912853Sgabeblack@google.com#define DEFN_REL_OP_T(op, tp) \ 200012853Sgabeblack@google.cominline bool \ 200112853Sgabeblack@google.comoperator op (const sc_fxnum_fast_subref &a, tp b) \ 200212853Sgabeblack@google.com{ \ 200312853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op b); \ 200412853Sgabeblack@google.com} \ 200512853Sgabeblack@google.com \ 200612853Sgabeblack@google.cominline bool \ 200712853Sgabeblack@google.comoperator op (tp a, const sc_fxnum_fast_subref &b) \ 200812853Sgabeblack@google.com{ \ 200912853Sgabeblack@google.com return (static_cast<sc_bv_base>(b) op a); \ 201012853Sgabeblack@google.com} 201112853Sgabeblack@google.com 201212853Sgabeblack@google.com#define DEFN_REL_OP(op) \ 201312853Sgabeblack@google.cominline bool \ 201412853Sgabeblack@google.comoperator op (const sc_fxnum_fast_subref &a, const sc_fxnum_fast_subref &b) \ 201512853Sgabeblack@google.com{ \ 201612853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op static_cast<sc_bv_base>(b)); \ 201712853Sgabeblack@google.com} \ 201812853Sgabeblack@google.com \ 201912853Sgabeblack@google.cominline bool \ 202012853Sgabeblack@google.comoperator op (const sc_fxnum_fast_subref &a, const sc_fxnum_subref &b) \ 202112853Sgabeblack@google.com{ \ 202212853Sgabeblack@google.com return (static_cast<sc_bv_base>(a) op static_cast<sc_bv_base>(b)); \ 202312853Sgabeblack@google.com} \ 202412853Sgabeblack@google.com \ 202512853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_bv_base &) \ 202612853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_lv_base &) \ 202712853Sgabeblack@google.comDEFN_REL_OP_T(op, const char *) \ 202812853Sgabeblack@google.comDEFN_REL_OP_T(op, const bool *) \ 202912853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_signed &) \ 203012853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_unsigned &) \ 203112853Sgabeblack@google.comDEFN_REL_OP_T(op, int) \ 203212853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned int) \ 203312853Sgabeblack@google.comDEFN_REL_OP_T(op, long) \ 203412853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned long) 203512853Sgabeblack@google.com 203612853Sgabeblack@google.comDEFN_REL_OP(==) 203712853Sgabeblack@google.comDEFN_REL_OP(!=) 203812853Sgabeblack@google.com 203912853Sgabeblack@google.com#undef DEFN_REL_OP_T 204012853Sgabeblack@google.com#undef DEFN_REL_OP 204112853Sgabeblack@google.com 204212853Sgabeblack@google.com// reduce functions 204312853Sgabeblack@google.com#define DEFN_RED_FNC(fnc) \ 204412853Sgabeblack@google.cominline bool \ 204512853Sgabeblack@google.comsc_fxnum_fast_subref::fnc() const \ 204612853Sgabeblack@google.com{ \ 204712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) \ 204812853Sgabeblack@google.com get(); \ 204912853Sgabeblack@google.com return static_cast<bool>(m_bv.fnc()); \ 205012853Sgabeblack@google.com} 205112853Sgabeblack@google.com 205212853Sgabeblack@google.comDEFN_RED_FNC(and_reduce) 205312853Sgabeblack@google.comDEFN_RED_FNC(nand_reduce) 205412853Sgabeblack@google.comDEFN_RED_FNC(or_reduce) 205512853Sgabeblack@google.comDEFN_RED_FNC(nor_reduce) 205612853Sgabeblack@google.comDEFN_RED_FNC(xor_reduce) 205712853Sgabeblack@google.comDEFN_RED_FNC(xnor_reduce) 205812853Sgabeblack@google.com 205912853Sgabeblack@google.com#undef DEFN_RED_FNC 206012853Sgabeblack@google.com 206112853Sgabeblack@google.com// query parameter 206212853Sgabeblack@google.cominline int 206312853Sgabeblack@google.comsc_fxnum_fast_subref::length() const 206412853Sgabeblack@google.com{ 206512853Sgabeblack@google.com return m_bv.length(); 206612853Sgabeblack@google.com} 206712853Sgabeblack@google.com 206812853Sgabeblack@google.com// explicit conversions 206912853Sgabeblack@google.cominline int 207012853Sgabeblack@google.comsc_fxnum_fast_subref::to_int() const 207112853Sgabeblack@google.com{ 207212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 207312853Sgabeblack@google.com get(); 207412853Sgabeblack@google.com return m_bv.to_int(); 207512853Sgabeblack@google.com} 207612853Sgabeblack@google.com 207712853Sgabeblack@google.cominline int64 207812853Sgabeblack@google.comsc_fxnum_fast_subref::to_int64() const 207912853Sgabeblack@google.com{ 208012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 208112853Sgabeblack@google.com get(); 208212853Sgabeblack@google.com return m_bv.to_int64(); 208312853Sgabeblack@google.com} 208412853Sgabeblack@google.com 208512853Sgabeblack@google.cominline unsigned int 208612853Sgabeblack@google.comsc_fxnum_fast_subref::to_uint() const 208712853Sgabeblack@google.com{ 208812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 208912853Sgabeblack@google.com get(); 209012853Sgabeblack@google.com return m_bv.to_uint(); 209112853Sgabeblack@google.com} 209212853Sgabeblack@google.com 209312853Sgabeblack@google.cominline uint64 209412853Sgabeblack@google.comsc_fxnum_fast_subref::to_uint64() const 209512853Sgabeblack@google.com{ 209612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 209712853Sgabeblack@google.com get(); 209812853Sgabeblack@google.com return m_bv.to_uint64(); 209912853Sgabeblack@google.com} 210012853Sgabeblack@google.com 210112853Sgabeblack@google.cominline long 210212853Sgabeblack@google.comsc_fxnum_fast_subref::to_long() const 210312853Sgabeblack@google.com{ 210412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 210512853Sgabeblack@google.com get(); 210612853Sgabeblack@google.com return m_bv.to_long(); 210712853Sgabeblack@google.com} 210812853Sgabeblack@google.com 210912853Sgabeblack@google.cominline unsigned long 211012853Sgabeblack@google.comsc_fxnum_fast_subref::to_ulong() const 211112853Sgabeblack@google.com{ 211212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 211312853Sgabeblack@google.com get(); 211412853Sgabeblack@google.com return m_bv.to_ulong(); 211512853Sgabeblack@google.com} 211612853Sgabeblack@google.com 211712853Sgabeblack@google.cominline const std::string 211812853Sgabeblack@google.comsc_fxnum_fast_subref::to_string() const 211912853Sgabeblack@google.com{ 212012853Sgabeblack@google.com get(); 212112853Sgabeblack@google.com return m_bv.to_string(); 212212853Sgabeblack@google.com} 212312853Sgabeblack@google.com 212412853Sgabeblack@google.cominline const std::string 212512853Sgabeblack@google.comsc_fxnum_fast_subref::to_string(sc_numrep numrep) const 212612853Sgabeblack@google.com{ 212712853Sgabeblack@google.com get(); 212812853Sgabeblack@google.com return m_bv.to_string(numrep); 212912853Sgabeblack@google.com} 213012853Sgabeblack@google.com 213112853Sgabeblack@google.cominline const std::string 213212853Sgabeblack@google.comsc_fxnum_fast_subref::to_string(sc_numrep numrep, bool w_prefix) const 213312853Sgabeblack@google.com{ 213412853Sgabeblack@google.com get(); 213512853Sgabeblack@google.com return m_bv.to_string(numrep, w_prefix); 213612853Sgabeblack@google.com} 213712853Sgabeblack@google.com 213812853Sgabeblack@google.com 213912853Sgabeblack@google.com// implicit conversion 214012853Sgabeblack@google.cominline sc_fxnum_fast_subref::operator sc_bv_base () const 214112853Sgabeblack@google.com{ 214212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(m_num) 214312853Sgabeblack@google.com get(); 214412853Sgabeblack@google.com return m_bv; 214512853Sgabeblack@google.com} 214612853Sgabeblack@google.com 214712853Sgabeblack@google.cominline ::std::ostream & 214812853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum_fast_subref &a) 214912853Sgabeblack@google.com{ 215012853Sgabeblack@google.com a.print(os); 215112853Sgabeblack@google.com return os; 215212853Sgabeblack@google.com} 215312853Sgabeblack@google.com 215412853Sgabeblack@google.cominline ::std::istream & 215512853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum_fast_subref &a) 215612853Sgabeblack@google.com{ 215712853Sgabeblack@google.com a.scan(is); 215812853Sgabeblack@google.com return is; 215912853Sgabeblack@google.com} 216012853Sgabeblack@google.com 216112853Sgabeblack@google.com 216212853Sgabeblack@google.com// ---------------------------------------------------------------------------- 216312853Sgabeblack@google.com// CLASS : sc_fxnum 216412853Sgabeblack@google.com// 216512853Sgabeblack@google.com// Base class for the fixed-point types; arbitrary precision. 216612853Sgabeblack@google.com// ---------------------------------------------------------------------------- 216712853Sgabeblack@google.com 216812853Sgabeblack@google.cominline sc_fxnum_observer * 216912853Sgabeblack@google.comsc_fxnum::observer() const 217012853Sgabeblack@google.com{ 217112853Sgabeblack@google.com return m_observer; 217212853Sgabeblack@google.com} 217312853Sgabeblack@google.com 217412853Sgabeblack@google.cominline void 217512853Sgabeblack@google.comsc_fxnum::cast() 217612853Sgabeblack@google.com{ 217712853Sgabeblack@google.com SC_ERROR_IF_(!m_rep->is_normal(), "invalid fixed-point value"); 217812853Sgabeblack@google.com 217912853Sgabeblack@google.com if (m_params.cast_switch() == SC_ON) 218012853Sgabeblack@google.com m_rep->cast(m_params, m_q_flag, m_o_flag); 218112853Sgabeblack@google.com} 218212853Sgabeblack@google.com 218312853Sgabeblack@google.com// constructors 218412853Sgabeblack@google.cominline sc_fxnum::sc_fxnum(const sc_fxtype_params &type_params_, 218512853Sgabeblack@google.com sc_enc enc_, const sc_fxcast_switch &cast_sw, 218612853Sgabeblack@google.com sc_fxnum_observer *observer_) : 218712853Sgabeblack@google.com m_rep(new scfx_rep), m_params(type_params_, enc_, cast_sw), 218812853Sgabeblack@google.com m_q_flag(false), m_o_flag(false), m_observer(observer_) 218912853Sgabeblack@google.com{ 219012853Sgabeblack@google.com SC_FXNUM_OBSERVER_DEFAULT_ 219112853Sgabeblack@google.com SC_FXNUM_OBSERVER_CONSTRUCT_(*this) 219212853Sgabeblack@google.com} 219312853Sgabeblack@google.com 219412853Sgabeblack@google.com#define DEFN_CTOR_T(tp, arg) \ 219512853Sgabeblack@google.cominline sc_fxnum::sc_fxnum(tp a, const sc_fxtype_params &type_params_, \ 219612853Sgabeblack@google.com sc_enc enc_, const sc_fxcast_switch &cast_sw, \ 219712853Sgabeblack@google.com sc_fxnum_observer *observer_) : \ 219812853Sgabeblack@google.com m_rep(new scfx_rep(arg)), m_params(type_params_, enc_, cast_sw), \ 219912853Sgabeblack@google.com m_q_flag(false), m_o_flag(false), m_observer(observer_) \ 220012853Sgabeblack@google.com{ \ 220112853Sgabeblack@google.com SC_FXNUM_OBSERVER_DEFAULT_ \ 220212853Sgabeblack@google.com cast(); \ 220312853Sgabeblack@google.com SC_FXNUM_OBSERVER_CONSTRUCT_(*this) \ 220412853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) \ 220512853Sgabeblack@google.com} 220612853Sgabeblack@google.com 220712853Sgabeblack@google.com#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp, a) 220812853Sgabeblack@google.com#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp, *a.m_rep) 220912853Sgabeblack@google.com#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp, a.to_double()) 221012853Sgabeblack@google.com#define DEFN_CTOR_T_D(tp) DEFN_CTOR_T(tp, a.value()) 221112853Sgabeblack@google.com 221212853Sgabeblack@google.comDEFN_CTOR_T_A(int) 221312853Sgabeblack@google.comDEFN_CTOR_T_A(unsigned int) 221412853Sgabeblack@google.comDEFN_CTOR_T_A(long) 221512853Sgabeblack@google.comDEFN_CTOR_T_A(unsigned long) 221612853Sgabeblack@google.comDEFN_CTOR_T_A(float) 221712853Sgabeblack@google.comDEFN_CTOR_T_A(double) 221812853Sgabeblack@google.comDEFN_CTOR_T_A(const char *) 221912853Sgabeblack@google.comDEFN_CTOR_T_B(const sc_fxval &) 222012853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_fxval_fast &) 222112853Sgabeblack@google.comDEFN_CTOR_T_B(const sc_fxnum &) 222212853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_fxnum_fast &) 222312853Sgabeblack@google.com#ifndef SC_FX_EXCLUDE_OTHER 222412853Sgabeblack@google.comDEFN_CTOR_T_A(int64) 222512853Sgabeblack@google.comDEFN_CTOR_T_A(uint64) 222612853Sgabeblack@google.comDEFN_CTOR_T_D(const sc_int_base &) 222712853Sgabeblack@google.comDEFN_CTOR_T_D(const sc_uint_base &) 222812853Sgabeblack@google.comDEFN_CTOR_T_A(const sc_signed &) 222912853Sgabeblack@google.comDEFN_CTOR_T_A(const sc_unsigned &) 223012853Sgabeblack@google.com#endif 223112853Sgabeblack@google.com 223212853Sgabeblack@google.com#undef DEFN_CTOR_T 223312853Sgabeblack@google.com#undef DEFN_CTOR_T_A 223412853Sgabeblack@google.com#undef DEFN_CTOR_T_B 223512853Sgabeblack@google.com#undef DEFN_CTOR_T_C 223612853Sgabeblack@google.com#undef DEFN_CTOR_T_D 223712853Sgabeblack@google.com 223812853Sgabeblack@google.cominline sc_fxnum::~sc_fxnum() 223912853Sgabeblack@google.com{ 224012853Sgabeblack@google.com SC_FXNUM_OBSERVER_DESTRUCT_(*this) 224112853Sgabeblack@google.com delete m_rep; 224212853Sgabeblack@google.com} 224312853Sgabeblack@google.com 224412853Sgabeblack@google.com// internal use only; 224512853Sgabeblack@google.cominline const scfx_rep * 224612853Sgabeblack@google.comsc_fxnum::get_rep() const 224712853Sgabeblack@google.com{ 224812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 224912853Sgabeblack@google.com return m_rep; 225012853Sgabeblack@google.com} 225112853Sgabeblack@google.com 225212853Sgabeblack@google.com// unary operators 225312853Sgabeblack@google.cominline const sc_fxval 225412853Sgabeblack@google.comsc_fxnum::operator - () const 225512853Sgabeblack@google.com{ 225612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 225712853Sgabeblack@google.com return sc_fxval(sc_dt::neg_scfx_rep(*m_rep)); 225812853Sgabeblack@google.com} 225912853Sgabeblack@google.com 226012853Sgabeblack@google.cominline const sc_fxval 226112853Sgabeblack@google.comsc_fxnum::operator + () const 226212853Sgabeblack@google.com{ 226312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 226412853Sgabeblack@google.com return sc_fxval(new scfx_rep(*m_rep)); 226512853Sgabeblack@google.com} 226612853Sgabeblack@google.com 226712853Sgabeblack@google.com// unary functions 226812853Sgabeblack@google.cominline void 226912853Sgabeblack@google.comneg(sc_fxval &c, const sc_fxnum &a) 227012853Sgabeblack@google.com{ 227112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 227212853Sgabeblack@google.com c.set_rep(sc_dt::neg_scfx_rep(*a.m_rep)); 227312853Sgabeblack@google.com} 227412853Sgabeblack@google.com 227512853Sgabeblack@google.cominline void 227612853Sgabeblack@google.comneg(sc_fxnum &c, const sc_fxnum &a) 227712853Sgabeblack@google.com{ 227812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 227912853Sgabeblack@google.com delete c.m_rep; 228012853Sgabeblack@google.com c.m_rep = sc_dt::neg_scfx_rep(*a.m_rep); 228112853Sgabeblack@google.com c.cast(); 228212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) 228312853Sgabeblack@google.com} 228412853Sgabeblack@google.com 228512853Sgabeblack@google.com// binary operators 228612853Sgabeblack@google.com#define DEFN_BIN_OP_T(op, fnc, tp) \ 228712853Sgabeblack@google.cominline const sc_fxval \ 228812853Sgabeblack@google.comoperator op (const sc_fxnum &a, tp b) \ 228912853Sgabeblack@google.com{ \ 229012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 229112853Sgabeblack@google.com sc_fxval tmp(b); \ 229212853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*a.m_rep, *tmp.get_rep())); \ 229312853Sgabeblack@google.com} \ 229412853Sgabeblack@google.com \ 229512853Sgabeblack@google.cominline const sc_fxval \ 229612853Sgabeblack@google.comoperator op (tp a, const sc_fxnum &b) \ 229712853Sgabeblack@google.com{ \ 229812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 229912853Sgabeblack@google.com sc_fxval tmp(a); \ 230012853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*tmp.get_rep(), *b.m_rep)); \ 230112853Sgabeblack@google.com} 230212853Sgabeblack@google.com 230312853Sgabeblack@google.com#ifndef SC_FX_EXCLUDE_OTHER 230412853Sgabeblack@google.com#define DEFN_BIN_OP_OTHER(op, fnc) \ 230512853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, int64) \ 230612853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, uint64) \ 230712853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_int_base &) \ 230812853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_uint_base &) \ 230912853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_signed &) \ 231012853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_unsigned &) 231112853Sgabeblack@google.com#else 231212853Sgabeblack@google.com#define DEFN_BIN_OP_OTHER(op, fnc) 231312853Sgabeblack@google.com#endif 231412853Sgabeblack@google.com 231512853Sgabeblack@google.com#define DEFN_BIN_OP(op, fnc) \ 231612853Sgabeblack@google.cominline const sc_fxval \ 231712853Sgabeblack@google.comoperator op (const sc_fxnum &a, const sc_fxnum &b) \ 231812853Sgabeblack@google.com{ \ 231912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 232012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 232112853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.m_rep)); \ 232212853Sgabeblack@google.com} \ 232312853Sgabeblack@google.com \ 232412853Sgabeblack@google.cominline const sc_fxval \ 232512853Sgabeblack@google.comoperator op (const sc_fxnum &a, const sc_fxval &b) \ 232612853Sgabeblack@google.com{ \ 232712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 232812853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.get_rep())); \ 232912853Sgabeblack@google.com} \ 233012853Sgabeblack@google.com \ 233112853Sgabeblack@google.cominline const sc_fxval \ 233212853Sgabeblack@google.comoperator op (const sc_fxval &a, const sc_fxnum &b) \ 233312853Sgabeblack@google.com{ \ 233412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 233512853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*a.get_rep(), *b.m_rep)); \ 233612853Sgabeblack@google.com} \ 233712853Sgabeblack@google.com \ 233812853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, int) \ 233912853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, unsigned int) \ 234012853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, long) \ 234112853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, unsigned long) \ 234212853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, float) \ 234312853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, double) \ 234412853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const char *) \ 234512853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_fxval_fast &) \ 234612853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_fxnum_fast &) \ 234712853Sgabeblack@google.comDEFN_BIN_OP_OTHER(op, fnc) 234812853Sgabeblack@google.com 234912853Sgabeblack@google.comDEFN_BIN_OP(*, mult) 235012853Sgabeblack@google.comDEFN_BIN_OP(+, add) 235112853Sgabeblack@google.comDEFN_BIN_OP(-, sub) 235212853Sgabeblack@google.com// don't use macros 235312853Sgabeblack@google.com//DEFN_BIN_OP(/, div) 235412853Sgabeblack@google.cominline const sc_fxval 235512853Sgabeblack@google.comoperator / (const sc_fxnum &a, const sc_fxnum &b) 235612853Sgabeblack@google.com{ 235712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 235812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) 235912853Sgabeblack@google.com return sc_fxval(sc_dt::div_scfx_rep(*a.m_rep, *b.m_rep)); 236012853Sgabeblack@google.com} 236112853Sgabeblack@google.com 236212853Sgabeblack@google.cominline const sc_fxval 236312853Sgabeblack@google.comoperator / (const sc_fxnum &a, const sc_fxval &b) 236412853Sgabeblack@google.com{ 236512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 236612853Sgabeblack@google.com return sc_fxval(sc_dt::div_scfx_rep(*a.m_rep, *b.get_rep())); 236712853Sgabeblack@google.com} 236812853Sgabeblack@google.com 236912853Sgabeblack@google.cominline const sc_fxval 237012853Sgabeblack@google.comoperator / (const sc_fxval &a, const sc_fxnum &b) 237112853Sgabeblack@google.com{ 237212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) 237312853Sgabeblack@google.com return sc_fxval(sc_dt::div_scfx_rep(*a.get_rep(), *b.m_rep)); 237412853Sgabeblack@google.com} 237512853Sgabeblack@google.com 237612853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, int) 237712853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, unsigned int) 237812853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, long) 237912853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, unsigned long) 238012853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, float) 238112853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, double) 238212853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const char *) 238312853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_fxval_fast &) 238412853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_fxnum_fast &) 238512853Sgabeblack@google.com//DEFN_BIN_OP_OTHER(/, div) 238612853Sgabeblack@google.com 238712853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, int64) 238812853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, uint64) 238912853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_int_base &) 239012853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_uint_base &) 239112853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_signed &) 239212853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_unsigned &) 239312853Sgabeblack@google.com 239412853Sgabeblack@google.com#undef DEFN_BIN_OP_T 239512853Sgabeblack@google.com#undef DEFN_BIN_OP_OTHER 239612853Sgabeblack@google.com#undef DEFN_BIN_OP 239712853Sgabeblack@google.com 239812853Sgabeblack@google.cominline const sc_fxval 239912853Sgabeblack@google.comoperator << (const sc_fxnum &a, int b) 240012853Sgabeblack@google.com{ 240112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 240212853Sgabeblack@google.com return sc_fxval(sc_dt::lsh_scfx_rep(*a.m_rep, b)); 240312853Sgabeblack@google.com} 240412853Sgabeblack@google.com 240512853Sgabeblack@google.cominline const sc_fxval 240612853Sgabeblack@google.comoperator >> (const sc_fxnum &a, int b) 240712853Sgabeblack@google.com{ 240812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 240912853Sgabeblack@google.com return sc_fxval(sc_dt::rsh_scfx_rep(*a.m_rep, b)); 241012853Sgabeblack@google.com} 241112853Sgabeblack@google.com 241212853Sgabeblack@google.com// binary functions 241312853Sgabeblack@google.com#define DEFN_BIN_FNC_T(fnc, tp) \ 241412853Sgabeblack@google.cominline void \ 241512853Sgabeblack@google.comfnc (sc_fxval &c, const sc_fxnum &a, tp b) \ 241612853Sgabeblack@google.com{ \ 241712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 241812853Sgabeblack@google.com sc_fxval tmp(b); \ 241912853Sgabeblack@google.com c.set_rep(sc_dt::fnc ## _scfx_rep(*a.m_rep, *tmp.get_rep())); \ 242012853Sgabeblack@google.com} \ 242112853Sgabeblack@google.com \ 242212853Sgabeblack@google.cominline void \ 242312853Sgabeblack@google.comfnc (sc_fxval &c, tp a, const sc_fxnum &b) \ 242412853Sgabeblack@google.com{ \ 242512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 242612853Sgabeblack@google.com sc_fxval tmp(a); \ 242712853Sgabeblack@google.com c.set_rep(sc_dt::fnc ## _scfx_rep(*tmp.get_rep(), *b.m_rep)); \ 242812853Sgabeblack@google.com} \ 242912853Sgabeblack@google.com \ 243012853Sgabeblack@google.cominline void \ 243112853Sgabeblack@google.comfnc (sc_fxnum &c, const sc_fxnum &a, tp b) \ 243212853Sgabeblack@google.com{ \ 243312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 243412853Sgabeblack@google.com sc_fxval tmp(b); \ 243512853Sgabeblack@google.com delete c.m_rep; \ 243612853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*a.m_rep, *tmp.get_rep()); \ 243712853Sgabeblack@google.com c.cast(); \ 243812853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) \ 243912853Sgabeblack@google.com} \ 244012853Sgabeblack@google.com \ 244112853Sgabeblack@google.cominline void \ 244212853Sgabeblack@google.comfnc (sc_fxnum &c, tp a, const sc_fxnum &b) \ 244312853Sgabeblack@google.com{ \ 244412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 244512853Sgabeblack@google.com sc_fxval tmp(a); \ 244612853Sgabeblack@google.com delete c.m_rep; \ 244712853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*tmp.get_rep(), *b.m_rep); \ 244812853Sgabeblack@google.com c.cast(); \ 244912853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) \ 245012853Sgabeblack@google.com} 245112853Sgabeblack@google.com 245212853Sgabeblack@google.com#define DEFN_BIN_FNC_OTHER(fnc) \ 245312853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, int64) \ 245412853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, uint64) \ 245512853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_int_base &) \ 245612853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_uint_base &) \ 245712853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_signed &) \ 245812853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_unsigned &) 245912853Sgabeblack@google.com 246012853Sgabeblack@google.com#define DEFN_BIN_FNC(fnc) \ 246112853Sgabeblack@google.cominline void \ 246212853Sgabeblack@google.comfnc (sc_fxval &c, const sc_fxnum &a, const sc_fxnum &b) \ 246312853Sgabeblack@google.com{ \ 246412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 246512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 246612853Sgabeblack@google.com c.set_rep(sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.m_rep)); \ 246712853Sgabeblack@google.com} \ 246812853Sgabeblack@google.com \ 246912853Sgabeblack@google.cominline void \ 247012853Sgabeblack@google.comfnc (sc_fxnum &c, const sc_fxnum &a, const sc_fxnum &b) \ 247112853Sgabeblack@google.com{ \ 247212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 247312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 247412853Sgabeblack@google.com delete c.m_rep; \ 247512853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.m_rep); \ 247612853Sgabeblack@google.com c.cast(); \ 247712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) \ 247812853Sgabeblack@google.com} \ 247912853Sgabeblack@google.com \ 248012853Sgabeblack@google.cominline void \ 248112853Sgabeblack@google.comfnc (sc_fxval &c, const sc_fxnum &a, const sc_fxval &b) \ 248212853Sgabeblack@google.com{ \ 248312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 248412853Sgabeblack@google.com c.set_rep(sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.get_rep())); \ 248512853Sgabeblack@google.com} \ 248612853Sgabeblack@google.com \ 248712853Sgabeblack@google.cominline void \ 248812853Sgabeblack@google.comfnc (sc_fxval &c, const sc_fxval &a, const sc_fxnum &b) \ 248912853Sgabeblack@google.com{ \ 249012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 249112853Sgabeblack@google.com c.set_rep(sc_dt::fnc ## _scfx_rep(*a.get_rep(), *b.m_rep)); \ 249212853Sgabeblack@google.com} \ 249312853Sgabeblack@google.com \ 249412853Sgabeblack@google.cominline void \ 249512853Sgabeblack@google.comfnc (sc_fxnum &c, const sc_fxnum &a, const sc_fxval &b) \ 249612853Sgabeblack@google.com{ \ 249712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 249812853Sgabeblack@google.com delete c.m_rep; \ 249912853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*a.m_rep, *b.get_rep()); \ 250012853Sgabeblack@google.com c.cast(); \ 250112853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) \ 250212853Sgabeblack@google.com} \ 250312853Sgabeblack@google.com \ 250412853Sgabeblack@google.cominline void \ 250512853Sgabeblack@google.comfnc (sc_fxnum &c, const sc_fxval &a, const sc_fxnum &b) \ 250612853Sgabeblack@google.com{ \ 250712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 250812853Sgabeblack@google.com delete c.m_rep; \ 250912853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*a.get_rep(), *b.m_rep); \ 251012853Sgabeblack@google.com c.cast(); \ 251112853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) \ 251212853Sgabeblack@google.com} \ 251312853Sgabeblack@google.com \ 251412853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, int) \ 251512853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, unsigned int) \ 251612853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, long) \ 251712853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, unsigned long) \ 251812853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, float) \ 251912853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, double) \ 252012853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const char *) \ 252112853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_fxval_fast &) \ 252212853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_fxnum_fast &) \ 252312853Sgabeblack@google.comDEFN_BIN_FNC_OTHER(fnc) 252412853Sgabeblack@google.com 252512853Sgabeblack@google.comDEFN_BIN_FNC(mult) 252612853Sgabeblack@google.comDEFN_BIN_FNC(div) 252712853Sgabeblack@google.comDEFN_BIN_FNC(add) 252812853Sgabeblack@google.comDEFN_BIN_FNC(sub) 252912853Sgabeblack@google.com 253012853Sgabeblack@google.com#undef DEFN_BIN_FNC_T 253112853Sgabeblack@google.com#undef DEFN_BIN_FNC_OTHER 253212853Sgabeblack@google.com#undef DEFN_BIN_FNC 253312853Sgabeblack@google.com 253412853Sgabeblack@google.cominline void 253512853Sgabeblack@google.comlshift(sc_fxval &c, const sc_fxnum &a, int b) 253612853Sgabeblack@google.com{ 253712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 253812853Sgabeblack@google.com c.set_rep(sc_dt::lsh_scfx_rep(*a.m_rep, b)); 253912853Sgabeblack@google.com} 254012853Sgabeblack@google.com 254112853Sgabeblack@google.cominline void 254212853Sgabeblack@google.comrshift(sc_fxval &c, const sc_fxnum &a, int b) 254312853Sgabeblack@google.com{ 254412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 254512853Sgabeblack@google.com c.set_rep(sc_dt::rsh_scfx_rep(*a.m_rep, b)); 254612853Sgabeblack@google.com} 254712853Sgabeblack@google.com 254812853Sgabeblack@google.cominline void 254912853Sgabeblack@google.comlshift(sc_fxnum &c, const sc_fxnum &a, int b) 255012853Sgabeblack@google.com{ 255112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 255212853Sgabeblack@google.com delete c.m_rep; 255312853Sgabeblack@google.com c.m_rep = sc_dt::lsh_scfx_rep(*a.m_rep, b); 255412853Sgabeblack@google.com c.cast(); 255512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) 255612853Sgabeblack@google.com} 255712853Sgabeblack@google.com 255812853Sgabeblack@google.cominline void 255912853Sgabeblack@google.comrshift(sc_fxnum &c, const sc_fxnum &a, int b) 256012853Sgabeblack@google.com{ 256112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 256212853Sgabeblack@google.com delete c.m_rep; 256312853Sgabeblack@google.com c.m_rep = sc_dt::rsh_scfx_rep(*a.m_rep, b); 256412853Sgabeblack@google.com c.cast(); 256512853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(c) 256612853Sgabeblack@google.com} 256712853Sgabeblack@google.com 256812853Sgabeblack@google.com// relational (including equality) operators 256912853Sgabeblack@google.com#define DEFN_REL_OP_T(op, ret, tp) \ 257012853Sgabeblack@google.cominline bool \ 257112853Sgabeblack@google.comoperator op (const sc_fxnum &a, tp b) \ 257212853Sgabeblack@google.com{ \ 257312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 257412853Sgabeblack@google.com sc_fxval tmp(b); \ 257512853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*a.m_rep, *tmp.get_rep()); \ 257612853Sgabeblack@google.com return (ret); \ 257712853Sgabeblack@google.com} \ 257812853Sgabeblack@google.com \ 257912853Sgabeblack@google.cominline bool \ 258012853Sgabeblack@google.comoperator op (tp a, const sc_fxnum &b) \ 258112853Sgabeblack@google.com{ \ 258212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 258312853Sgabeblack@google.com sc_fxval tmp(a); \ 258412853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*tmp.get_rep(), *b.m_rep); \ 258512853Sgabeblack@google.com return (ret); \ 258612853Sgabeblack@google.com} 258712853Sgabeblack@google.com 258812853Sgabeblack@google.com#define DEFN_REL_OP_OTHER(op, ret) \ 258912853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, int64) \ 259012853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, uint64) \ 259112853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_int_base &) \ 259212853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_uint_base &) \ 259312853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_signed &) \ 259412853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_unsigned &) 259512853Sgabeblack@google.com 259612853Sgabeblack@google.com#define DEFN_REL_OP(op, ret) \ 259712853Sgabeblack@google.cominline bool \ 259812853Sgabeblack@google.comoperator op (const sc_fxnum &a, const sc_fxnum &b) \ 259912853Sgabeblack@google.com{ \ 260012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 260112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 260212853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*a.m_rep, *b.m_rep); \ 260312853Sgabeblack@google.com return (ret); \ 260412853Sgabeblack@google.com} \ 260512853Sgabeblack@google.com \ 260612853Sgabeblack@google.cominline bool \ 260712853Sgabeblack@google.comoperator op (const sc_fxnum &a, const sc_fxval &b) \ 260812853Sgabeblack@google.com{ \ 260912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) \ 261012853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*a.m_rep, *b.get_rep()); \ 261112853Sgabeblack@google.com return (ret); \ 261212853Sgabeblack@google.com} \ 261312853Sgabeblack@google.com \ 261412853Sgabeblack@google.cominline bool \ 261512853Sgabeblack@google.comoperator op (const sc_fxval &a, const sc_fxnum &b) \ 261612853Sgabeblack@google.com{ \ 261712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 261812853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*a.get_rep(), *b.m_rep); \ 261912853Sgabeblack@google.com return (ret); \ 262012853Sgabeblack@google.com} \ 262112853Sgabeblack@google.com \ 262212853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, int) \ 262312853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, unsigned int) \ 262412853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, long) \ 262512853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, unsigned long) \ 262612853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, float) \ 262712853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, double) \ 262812853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const char *) \ 262912853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_fxval_fast &) \ 263012853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_fxnum_fast &) \ 263112853Sgabeblack@google.comDEFN_REL_OP_OTHER(op, ret) 263212853Sgabeblack@google.com 263312853Sgabeblack@google.comDEFN_REL_OP(<, result < 0) 263412853Sgabeblack@google.comDEFN_REL_OP(<=, result <= 0) 263512853Sgabeblack@google.comDEFN_REL_OP(>, result > 0 && result != 2) 263612853Sgabeblack@google.comDEFN_REL_OP(>=, result >= 0 && result != 2) 263712853Sgabeblack@google.comDEFN_REL_OP(==, result == 0) 263812853Sgabeblack@google.comDEFN_REL_OP(!=, result != 0) 263912853Sgabeblack@google.com 264012853Sgabeblack@google.com#undef DEFN_REL_OP_T 264112853Sgabeblack@google.com#undef DEFN_REL_OP_OTHER 264212853Sgabeblack@google.com#undef DEFN_REL_OP 264312853Sgabeblack@google.com 264412853Sgabeblack@google.com// assignment operators 264512853Sgabeblack@google.cominline sc_fxnum & 264612853Sgabeblack@google.comsc_fxnum::operator = (const sc_fxnum &a) 264712853Sgabeblack@google.com{ 264812853Sgabeblack@google.com if (&a != this) { 264912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(a) 265012853Sgabeblack@google.com *m_rep = *a.m_rep; 265112853Sgabeblack@google.com cast(); 265212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) 265312853Sgabeblack@google.com } 265412853Sgabeblack@google.com return *this; 265512853Sgabeblack@google.com} 265612853Sgabeblack@google.com 265712853Sgabeblack@google.cominline sc_fxnum & 265812853Sgabeblack@google.comsc_fxnum::operator = (const sc_fxval &a) 265912853Sgabeblack@google.com{ 266012853Sgabeblack@google.com *m_rep = *a.get_rep(); 266112853Sgabeblack@google.com cast(); 266212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) 266312853Sgabeblack@google.com return *this; 266412853Sgabeblack@google.com} 266512853Sgabeblack@google.com 266612853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 266712853Sgabeblack@google.cominline sc_fxnum & \ 266812853Sgabeblack@google.comsc_fxnum::operator = (tp a) \ 266912853Sgabeblack@google.com{ \ 267012853Sgabeblack@google.com sc_fxval tmp(a); \ 267112853Sgabeblack@google.com *m_rep = *tmp.get_rep(); \ 267212853Sgabeblack@google.com cast(); \ 267312853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) \ 267412853Sgabeblack@google.com return *this; \ 267512853Sgabeblack@google.com} 267612853Sgabeblack@google.com 267712853Sgabeblack@google.comDEFN_ASN_OP_T(int) 267812853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned int) 267912853Sgabeblack@google.comDEFN_ASN_OP_T(long) 268012853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned long) 268112853Sgabeblack@google.comDEFN_ASN_OP_T(float) 268212853Sgabeblack@google.comDEFN_ASN_OP_T(double) 268312853Sgabeblack@google.comDEFN_ASN_OP_T(const char *) 268412853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxval_fast &) 268512853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxnum_fast &) 268612853Sgabeblack@google.com 268712853Sgabeblack@google.comDEFN_ASN_OP_T(int64) 268812853Sgabeblack@google.comDEFN_ASN_OP_T(uint64) 268912853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_int_base &) 269012853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_uint_base &) 269112853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_signed &) 269212853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_unsigned &) 269312853Sgabeblack@google.com 269412853Sgabeblack@google.com#undef DEFN_ASN_OP_T 269512853Sgabeblack@google.com 269612853Sgabeblack@google.com 269712853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, fnc, tp) \ 269812853Sgabeblack@google.cominline sc_fxnum & \ 269912853Sgabeblack@google.comsc_fxnum::operator op (tp b) \ 270012853Sgabeblack@google.com{ \ 270112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) \ 270212853Sgabeblack@google.com sc_fxval tmp(b); \ 270312853Sgabeblack@google.com scfx_rep *new_rep = sc_dt::fnc ## _scfx_rep(*m_rep, *tmp.get_rep()); \ 270412853Sgabeblack@google.com delete m_rep; \ 270512853Sgabeblack@google.com m_rep = new_rep; \ 270612853Sgabeblack@google.com cast(); \ 270712853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) \ 270812853Sgabeblack@google.com return *this; \ 270912853Sgabeblack@google.com} 271012853Sgabeblack@google.com 271112853Sgabeblack@google.com#define DEFN_ASN_OP_OTHER(op, fnc) \ 271212853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, int64) \ 271312853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, uint64) \ 271412853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_int_base &) \ 271512853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_uint_base &) \ 271612853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_signed &) \ 271712853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_unsigned &) 271812853Sgabeblack@google.com 271912853Sgabeblack@google.com#define DEFN_ASN_OP(op, fnc) \ 272012853Sgabeblack@google.cominline sc_fxnum & \ 272112853Sgabeblack@google.comsc_fxnum::operator op (const sc_fxnum &b) \ 272212853Sgabeblack@google.com{ \ 272312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) \ 272412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(b) \ 272512853Sgabeblack@google.com scfx_rep *new_rep = sc_dt::fnc ## _scfx_rep(*m_rep, *b.m_rep); \ 272612853Sgabeblack@google.com delete m_rep; \ 272712853Sgabeblack@google.com m_rep = new_rep; \ 272812853Sgabeblack@google.com cast(); \ 272912853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) \ 273012853Sgabeblack@google.com return *this; \ 273112853Sgabeblack@google.com} \ 273212853Sgabeblack@google.com \ 273312853Sgabeblack@google.cominline sc_fxnum & \ 273412853Sgabeblack@google.comsc_fxnum::operator op (const sc_fxval &b) \ 273512853Sgabeblack@google.com{ \ 273612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) \ 273712853Sgabeblack@google.com scfx_rep *new_rep = sc_dt::fnc ## _scfx_rep(*m_rep, *b.get_rep()); \ 273812853Sgabeblack@google.com delete m_rep; \ 273912853Sgabeblack@google.com m_rep = new_rep; \ 274012853Sgabeblack@google.com cast(); \ 274112853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) \ 274212853Sgabeblack@google.com return *this; \ 274312853Sgabeblack@google.com} \ 274412853Sgabeblack@google.com \ 274512853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, int) \ 274612853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, unsigned int) \ 274712853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, long) \ 274812853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, unsigned long) \ 274912853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, float) \ 275012853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, double) \ 275112853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const char *) \ 275212853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_fxval_fast &) \ 275312853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_fxnum_fast &) \ 275412853Sgabeblack@google.comDEFN_ASN_OP_OTHER(op, fnc) 275512853Sgabeblack@google.com 275612853Sgabeblack@google.comDEFN_ASN_OP(*=, mult) 275712853Sgabeblack@google.comDEFN_ASN_OP(/=, div) 275812853Sgabeblack@google.comDEFN_ASN_OP(+=, add) 275912853Sgabeblack@google.comDEFN_ASN_OP(-=, sub) 276012853Sgabeblack@google.com 276112853Sgabeblack@google.com#undef DEFN_ASN_OP_T 276212853Sgabeblack@google.com#undef DEFN_ASN_OP_OTHER 276312853Sgabeblack@google.com#undef DEFN_ASN_OP 276412853Sgabeblack@google.com 276512853Sgabeblack@google.com 276612853Sgabeblack@google.cominline sc_fxnum & 276712853Sgabeblack@google.comsc_fxnum::operator <<= (int b) 276812853Sgabeblack@google.com{ 276912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 277012853Sgabeblack@google.com m_rep->lshift(b); 277112853Sgabeblack@google.com cast(); 277212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) 277312853Sgabeblack@google.com return *this; 277412853Sgabeblack@google.com} 277512853Sgabeblack@google.com 277612853Sgabeblack@google.cominline sc_fxnum & 277712853Sgabeblack@google.comsc_fxnum::operator >>= (int b) 277812853Sgabeblack@google.com{ 277912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 278012853Sgabeblack@google.com m_rep->rshift(b); 278112853Sgabeblack@google.com cast(); 278212853Sgabeblack@google.com SC_FXNUM_OBSERVER_WRITE_(*this) 278312853Sgabeblack@google.com return *this; 278412853Sgabeblack@google.com} 278512853Sgabeblack@google.com 278612853Sgabeblack@google.com// auto-increment and auto-decrement 278712853Sgabeblack@google.cominline const sc_fxval 278812853Sgabeblack@google.comsc_fxnum::operator ++ (int) 278912853Sgabeblack@google.com{ 279012853Sgabeblack@google.com sc_fxval c(*this); 279112853Sgabeblack@google.com (*this) += 1; 279212853Sgabeblack@google.com return c; 279312853Sgabeblack@google.com} 279412853Sgabeblack@google.com 279512853Sgabeblack@google.cominline const sc_fxval 279612853Sgabeblack@google.comsc_fxnum::operator -- (int) 279712853Sgabeblack@google.com{ 279812853Sgabeblack@google.com sc_fxval c(*this); 279912853Sgabeblack@google.com (*this) -= 1; 280012853Sgabeblack@google.com return c; 280112853Sgabeblack@google.com} 280212853Sgabeblack@google.com 280312853Sgabeblack@google.cominline sc_fxnum & 280412853Sgabeblack@google.comsc_fxnum::operator ++ () 280512853Sgabeblack@google.com{ 280612853Sgabeblack@google.com (*this) += 1; 280712853Sgabeblack@google.com return *this; 280812853Sgabeblack@google.com} 280912853Sgabeblack@google.com 281012853Sgabeblack@google.cominline sc_fxnum & 281112853Sgabeblack@google.comsc_fxnum::operator -- () 281212853Sgabeblack@google.com{ 281312853Sgabeblack@google.com (*this) -= 1; 281412853Sgabeblack@google.com return *this; 281512853Sgabeblack@google.com} 281612853Sgabeblack@google.com 281712853Sgabeblack@google.com// bit selection 281812853Sgabeblack@google.cominline const sc_fxnum_bitref 281912853Sgabeblack@google.comsc_fxnum::operator [] (int i) const 282012853Sgabeblack@google.com{ 282112853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 282212853Sgabeblack@google.com return sc_fxnum_bitref(const_cast<sc_fxnum &>(*this), 282312853Sgabeblack@google.com i - m_params.fwl()); 282412853Sgabeblack@google.com} 282512853Sgabeblack@google.com 282612853Sgabeblack@google.cominline sc_fxnum_bitref 282712853Sgabeblack@google.comsc_fxnum::operator [] (int i) 282812853Sgabeblack@google.com{ 282912853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 283012853Sgabeblack@google.com return sc_fxnum_bitref(*this, i - m_params.fwl()); 283112853Sgabeblack@google.com} 283212853Sgabeblack@google.com 283312853Sgabeblack@google.cominline const sc_fxnum_bitref 283412853Sgabeblack@google.comsc_fxnum::bit(int i) const 283512853Sgabeblack@google.com{ 283612853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 283712853Sgabeblack@google.com return sc_fxnum_bitref(const_cast<sc_fxnum &>(*this), 283812853Sgabeblack@google.com i - m_params.fwl()); 283912853Sgabeblack@google.com} 284012853Sgabeblack@google.com 284112853Sgabeblack@google.cominline sc_fxnum_bitref 284212853Sgabeblack@google.comsc_fxnum::bit(int i) 284312853Sgabeblack@google.com{ 284412853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 284512853Sgabeblack@google.com return sc_fxnum_bitref(*this, i - m_params.fwl()); 284612853Sgabeblack@google.com} 284712853Sgabeblack@google.com 284812853Sgabeblack@google.com// part selection 284912853Sgabeblack@google.com 285012853Sgabeblack@google.cominline const sc_fxnum_subref 285112853Sgabeblack@google.comsc_fxnum::operator () (int i, int j) const 285212853Sgabeblack@google.com{ 285312853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 285412853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 285512853Sgabeblack@google.com 285612853Sgabeblack@google.com return sc_fxnum_subref(const_cast<sc_fxnum &>(*this), 285712853Sgabeblack@google.com i - m_params.fwl(), j - m_params.fwl()); 285812853Sgabeblack@google.com} 285912853Sgabeblack@google.com 286012853Sgabeblack@google.cominline sc_fxnum_subref 286112853Sgabeblack@google.comsc_fxnum::operator () (int i, int j) 286212853Sgabeblack@google.com{ 286312853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 286412853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 286512853Sgabeblack@google.com 286612853Sgabeblack@google.com return sc_fxnum_subref(*this, i - m_params.fwl(), j - m_params.fwl()); 286712853Sgabeblack@google.com} 286812853Sgabeblack@google.com 286912853Sgabeblack@google.cominline const sc_fxnum_subref 287012853Sgabeblack@google.comsc_fxnum::range(int i, int j) const 287112853Sgabeblack@google.com{ 287212853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 287312853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 287412853Sgabeblack@google.com 287512853Sgabeblack@google.com return sc_fxnum_subref(const_cast<sc_fxnum &>(*this), 287612853Sgabeblack@google.com i - m_params.fwl(), j - m_params.fwl()); 287712853Sgabeblack@google.com} 287812853Sgabeblack@google.com 287912853Sgabeblack@google.cominline sc_fxnum_subref 288012853Sgabeblack@google.comsc_fxnum::range(int i, int j) 288112853Sgabeblack@google.com{ 288212853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 288312853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 288412853Sgabeblack@google.com 288512853Sgabeblack@google.com return sc_fxnum_subref(*this, i - m_params.fwl(), j - m_params.fwl()); 288612853Sgabeblack@google.com} 288712853Sgabeblack@google.com 288812853Sgabeblack@google.com 288912853Sgabeblack@google.cominline const sc_fxnum_subref 289012853Sgabeblack@google.comsc_fxnum::operator () () const 289112853Sgabeblack@google.com{ 289212853Sgabeblack@google.com return this->operator () (m_params.wl() - 1, 0); 289312853Sgabeblack@google.com} 289412853Sgabeblack@google.com 289512853Sgabeblack@google.cominline sc_fxnum_subref 289612853Sgabeblack@google.comsc_fxnum::operator () () 289712853Sgabeblack@google.com{ 289812853Sgabeblack@google.com return this->operator () (m_params.wl() - 1, 0); 289912853Sgabeblack@google.com} 290012853Sgabeblack@google.com 290112853Sgabeblack@google.cominline const sc_fxnum_subref 290212853Sgabeblack@google.comsc_fxnum::range() const 290312853Sgabeblack@google.com{ 290412853Sgabeblack@google.com return this->range(m_params.wl() - 1, 0); 290512853Sgabeblack@google.com} 290612853Sgabeblack@google.com 290712853Sgabeblack@google.cominline sc_fxnum_subref 290812853Sgabeblack@google.comsc_fxnum::range() 290912853Sgabeblack@google.com{ 291012853Sgabeblack@google.com return this->range(m_params.wl() - 1, 0); 291112853Sgabeblack@google.com} 291212853Sgabeblack@google.com 291312853Sgabeblack@google.com// implicit conversion 291412853Sgabeblack@google.cominline sc_fxnum::operator double() const 291512853Sgabeblack@google.com{ 291612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 291712853Sgabeblack@google.com return m_rep->to_double(); 291812853Sgabeblack@google.com} 291912853Sgabeblack@google.com 292012853Sgabeblack@google.com// explicit conversion to primitive types 292112853Sgabeblack@google.cominline short 292212853Sgabeblack@google.comsc_fxnum::to_short() const 292312853Sgabeblack@google.com{ 292412853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 292512853Sgabeblack@google.com return static_cast<short>(m_rep->to_uint64()); 292612853Sgabeblack@google.com} 292712853Sgabeblack@google.com 292812853Sgabeblack@google.cominline unsigned short 292912853Sgabeblack@google.comsc_fxnum::to_ushort() const 293012853Sgabeblack@google.com{ 293112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 293212853Sgabeblack@google.com return static_cast<unsigned short>(m_rep->to_uint64()); 293312853Sgabeblack@google.com} 293412853Sgabeblack@google.com 293512853Sgabeblack@google.cominline int 293612853Sgabeblack@google.comsc_fxnum::to_int() const 293712853Sgabeblack@google.com{ 293812853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 293912853Sgabeblack@google.com return static_cast<int>(m_rep->to_uint64()); 294012853Sgabeblack@google.com} 294112853Sgabeblack@google.com 294212853Sgabeblack@google.cominline int64 294312853Sgabeblack@google.comsc_fxnum::to_int64() const 294412853Sgabeblack@google.com{ 294512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 294612853Sgabeblack@google.com return static_cast<int64>(m_rep->to_uint64()); 294712853Sgabeblack@google.com} 294812853Sgabeblack@google.com 294912853Sgabeblack@google.cominline unsigned int 295012853Sgabeblack@google.comsc_fxnum::to_uint() const 295112853Sgabeblack@google.com{ 295212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 295312853Sgabeblack@google.com return static_cast<unsigned int>(m_rep->to_uint64()); 295412853Sgabeblack@google.com} 295512853Sgabeblack@google.com 295612853Sgabeblack@google.cominline uint64 295712853Sgabeblack@google.comsc_fxnum::to_uint64() const 295812853Sgabeblack@google.com{ 295912853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 296012853Sgabeblack@google.com return m_rep->to_uint64(); 296112853Sgabeblack@google.com} 296212853Sgabeblack@google.com 296312853Sgabeblack@google.cominline long 296412853Sgabeblack@google.comsc_fxnum::to_long() const 296512853Sgabeblack@google.com{ 296612853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 296712853Sgabeblack@google.com return static_cast<long>(m_rep->to_uint64()); 296812853Sgabeblack@google.com} 296912853Sgabeblack@google.com 297012853Sgabeblack@google.cominline unsigned long 297112853Sgabeblack@google.comsc_fxnum::to_ulong() const 297212853Sgabeblack@google.com{ 297312853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 297412853Sgabeblack@google.com return static_cast<unsigned long>(m_rep->to_uint64()); 297512853Sgabeblack@google.com} 297612853Sgabeblack@google.com 297712853Sgabeblack@google.cominline float 297812853Sgabeblack@google.comsc_fxnum::to_float() const 297912853Sgabeblack@google.com{ 298012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 298112853Sgabeblack@google.com return static_cast<float>(m_rep->to_double()); 298212853Sgabeblack@google.com} 298312853Sgabeblack@google.com 298412853Sgabeblack@google.cominline double 298512853Sgabeblack@google.comsc_fxnum::to_double() const 298612853Sgabeblack@google.com{ 298712853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 298812853Sgabeblack@google.com return m_rep->to_double(); 298912853Sgabeblack@google.com} 299012853Sgabeblack@google.com 299112853Sgabeblack@google.com// query value 299212853Sgabeblack@google.cominline bool 299312853Sgabeblack@google.comsc_fxnum::is_neg() const 299412853Sgabeblack@google.com{ 299512853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 299612853Sgabeblack@google.com return m_rep->is_neg(); 299712853Sgabeblack@google.com} 299812853Sgabeblack@google.com 299912853Sgabeblack@google.cominline bool 300012853Sgabeblack@google.comsc_fxnum::is_zero() const 300112853Sgabeblack@google.com{ 300212853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 300312853Sgabeblack@google.com return m_rep->is_zero(); 300412853Sgabeblack@google.com} 300512853Sgabeblack@google.com 300612853Sgabeblack@google.com// internal use only; 300712853Sgabeblack@google.cominline bool 300812853Sgabeblack@google.comsc_fxnum::is_normal() const 300912853Sgabeblack@google.com{ 301012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 301112853Sgabeblack@google.com return m_rep->is_normal(); 301212853Sgabeblack@google.com} 301312853Sgabeblack@google.com 301412853Sgabeblack@google.cominline bool 301512853Sgabeblack@google.comsc_fxnum::quantization_flag() const 301612853Sgabeblack@google.com{ 301712853Sgabeblack@google.com return m_q_flag; 301812853Sgabeblack@google.com} 301912853Sgabeblack@google.com 302012853Sgabeblack@google.cominline bool 302112853Sgabeblack@google.comsc_fxnum::overflow_flag() const 302212853Sgabeblack@google.com{ 302312853Sgabeblack@google.com return m_o_flag; 302412853Sgabeblack@google.com} 302512853Sgabeblack@google.com 302612853Sgabeblack@google.com 302712853Sgabeblack@google.cominline const sc_fxval 302812853Sgabeblack@google.comsc_fxnum::value() const 302912853Sgabeblack@google.com{ 303012853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this) 303112853Sgabeblack@google.com return sc_fxval(new scfx_rep(*m_rep)); 303212853Sgabeblack@google.com} 303312853Sgabeblack@google.com 303412853Sgabeblack@google.com// query parameters 303512853Sgabeblack@google.cominline int 303612853Sgabeblack@google.comsc_fxnum::wl() const 303712853Sgabeblack@google.com{ 303812853Sgabeblack@google.com return m_params.wl(); 303912853Sgabeblack@google.com} 304012853Sgabeblack@google.com 304112853Sgabeblack@google.cominline int 304212853Sgabeblack@google.comsc_fxnum::iwl() const 304312853Sgabeblack@google.com{ 304412853Sgabeblack@google.com return m_params.iwl(); 304512853Sgabeblack@google.com} 304612853Sgabeblack@google.com 304712853Sgabeblack@google.cominline sc_q_mode 304812853Sgabeblack@google.comsc_fxnum::q_mode() const 304912853Sgabeblack@google.com{ 305012853Sgabeblack@google.com return m_params.q_mode(); 305112853Sgabeblack@google.com} 305212853Sgabeblack@google.com 305312853Sgabeblack@google.cominline sc_o_mode 305412853Sgabeblack@google.comsc_fxnum::o_mode() const 305512853Sgabeblack@google.com{ 305612853Sgabeblack@google.com return m_params.o_mode(); 305712853Sgabeblack@google.com} 305812853Sgabeblack@google.com 305912853Sgabeblack@google.cominline int 306012853Sgabeblack@google.comsc_fxnum::n_bits() const 306112853Sgabeblack@google.com{ 306212853Sgabeblack@google.com return m_params.n_bits(); 306312853Sgabeblack@google.com} 306412853Sgabeblack@google.com 306512853Sgabeblack@google.cominline const sc_fxtype_params & 306612853Sgabeblack@google.comsc_fxnum::type_params() const 306712853Sgabeblack@google.com{ 306812853Sgabeblack@google.com return m_params.type_params(); 306912853Sgabeblack@google.com} 307012853Sgabeblack@google.com 307112853Sgabeblack@google.cominline const sc_fxcast_switch & 307212853Sgabeblack@google.comsc_fxnum::cast_switch() const 307312853Sgabeblack@google.com{ 307412853Sgabeblack@google.com return m_params.cast_switch(); 307512853Sgabeblack@google.com} 307612853Sgabeblack@google.com 307712853Sgabeblack@google.com// internal use only; 307812853Sgabeblack@google.cominline void 307912853Sgabeblack@google.comsc_fxnum::observer_read() const 308012853Sgabeblack@google.com{ 308112853Sgabeblack@google.com SC_FXNUM_OBSERVER_READ_(*this); 308212853Sgabeblack@google.com} 308312853Sgabeblack@google.com 308412853Sgabeblack@google.com// internal use only; 308512853Sgabeblack@google.cominline bool 308612853Sgabeblack@google.comsc_fxnum::get_bit(int i) const 308712853Sgabeblack@google.com{ 308812853Sgabeblack@google.com return m_rep->get_bit(i); 308912853Sgabeblack@google.com} 309012853Sgabeblack@google.com 309112853Sgabeblack@google.com// protected methods and friend functions 309212853Sgabeblack@google.cominline bool 309312853Sgabeblack@google.comsc_fxnum::set_bit(int i, bool high) 309412853Sgabeblack@google.com{ 309512853Sgabeblack@google.com if (high) 309612853Sgabeblack@google.com return m_rep->set(i, m_params); 309712853Sgabeblack@google.com else 309812853Sgabeblack@google.com return m_rep->clear(i, m_params); 309912853Sgabeblack@google.com} 310012853Sgabeblack@google.com 310112853Sgabeblack@google.cominline bool 310212853Sgabeblack@google.comsc_fxnum::get_slice(int i, int j, sc_bv_base &bv) const 310312853Sgabeblack@google.com{ 310412853Sgabeblack@google.com return m_rep->get_slice(i, j, m_params, bv); 310512853Sgabeblack@google.com} 310612853Sgabeblack@google.com 310712853Sgabeblack@google.cominline bool 310812853Sgabeblack@google.comsc_fxnum::set_slice(int i, int j, const sc_bv_base &bv) 310912853Sgabeblack@google.com{ 311012853Sgabeblack@google.com return m_rep->set_slice(i, j, m_params, bv); 311112853Sgabeblack@google.com} 311212853Sgabeblack@google.com 311312853Sgabeblack@google.cominline ::std::ostream & 311412853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum &a) 311512853Sgabeblack@google.com{ 311612853Sgabeblack@google.com a.print(os); 311712853Sgabeblack@google.com return os; 311812853Sgabeblack@google.com} 311912853Sgabeblack@google.com 312012853Sgabeblack@google.cominline ::std::istream & 312112853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum &a) 312212853Sgabeblack@google.com{ 312312853Sgabeblack@google.com a.scan(is); 312412853Sgabeblack@google.com return is; 312512853Sgabeblack@google.com} 312612853Sgabeblack@google.com 312712853Sgabeblack@google.com 312812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 312912853Sgabeblack@google.com// CLASS : sc_fxnum_fast 313012853Sgabeblack@google.com// 313112853Sgabeblack@google.com// Base class for the fixed-point types; limited precision. 313212853Sgabeblack@google.com// ---------------------------------------------------------------------------- 313312853Sgabeblack@google.com 313412853Sgabeblack@google.cominline sc_fxnum_fast_observer * 313512853Sgabeblack@google.comsc_fxnum_fast::observer() const 313612853Sgabeblack@google.com{ 313712853Sgabeblack@google.com return m_observer; 313812853Sgabeblack@google.com} 313912853Sgabeblack@google.com 314012853Sgabeblack@google.com 314112853Sgabeblack@google.com// constructors 314212853Sgabeblack@google.cominline sc_fxnum_fast::sc_fxnum_fast(const sc_fxtype_params &type_params_, 314312853Sgabeblack@google.com sc_enc enc_, 314412853Sgabeblack@google.com const sc_fxcast_switch &cast_sw, 314512853Sgabeblack@google.com sc_fxnum_fast_observer *observer_) : 314612853Sgabeblack@google.com m_val(0.0), m_params(type_params_, enc_, cast_sw), m_q_flag(false), 314712853Sgabeblack@google.com m_o_flag(false), m_observer(observer_) 314812853Sgabeblack@google.com{ 314912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_DEFAULT_ 315012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this) 315112853Sgabeblack@google.com} 315212853Sgabeblack@google.com 315312853Sgabeblack@google.cominline sc_fxnum_fast::sc_fxnum_fast(const sc_fxnum_fast &a, 315412853Sgabeblack@google.com const sc_fxtype_params &type_params_, 315512853Sgabeblack@google.com sc_enc enc_, 315612853Sgabeblack@google.com const sc_fxcast_switch &cast_sw, 315712853Sgabeblack@google.com sc_fxnum_fast_observer *observer_) : 315812853Sgabeblack@google.com m_val(a.m_val), m_params(type_params_, enc_, cast_sw), m_q_flag(false), 315912853Sgabeblack@google.com m_o_flag(false), m_observer(observer_) 316012853Sgabeblack@google.com{ 316112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_DEFAULT_ 316212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 316312853Sgabeblack@google.com cast(); 316412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this) 316512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 316612853Sgabeblack@google.com} 316712853Sgabeblack@google.com 316812853Sgabeblack@google.com#define DEFN_CTOR_T(tp, arg) \ 316912853Sgabeblack@google.cominline sc_fxnum_fast::sc_fxnum_fast( \ 317012853Sgabeblack@google.com tp a, const sc_fxtype_params &type_params_, sc_enc enc_, \ 317112853Sgabeblack@google.com const sc_fxcast_switch &cast_sw, \ 317212853Sgabeblack@google.com sc_fxnum_fast_observer *observer_) : \ 317312853Sgabeblack@google.com m_val(arg), m_params(type_params_, enc_, cast_sw), m_q_flag(false), \ 317412853Sgabeblack@google.com m_o_flag(false), m_observer(observer_) \ 317512853Sgabeblack@google.com{ \ 317612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_DEFAULT_ \ 317712853Sgabeblack@google.com cast(); \ 317812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this) \ 317912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \ 318012853Sgabeblack@google.com} 318112853Sgabeblack@google.com 318212853Sgabeblack@google.com#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp, static_cast<double>(a)) 318312853Sgabeblack@google.com#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp, sc_fxval_fast::from_string(a)) 318412853Sgabeblack@google.com#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp, a.to_double()) 318512853Sgabeblack@google.com 318612853Sgabeblack@google.comDEFN_CTOR_T_A(int) 318712853Sgabeblack@google.comDEFN_CTOR_T_A(unsigned int) 318812853Sgabeblack@google.comDEFN_CTOR_T_A(long) 318912853Sgabeblack@google.comDEFN_CTOR_T_A(unsigned long) 319012853Sgabeblack@google.comDEFN_CTOR_T_A(float) 319112853Sgabeblack@google.comDEFN_CTOR_T_A(double) 319212853Sgabeblack@google.comDEFN_CTOR_T_B(const char *) 319312853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_fxval &) 319412853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_fxval_fast &) 319512853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_fxnum &) 319612853Sgabeblack@google.com 319712853Sgabeblack@google.comDEFN_CTOR_T_A(int64) 319812853Sgabeblack@google.comDEFN_CTOR_T_A(uint64) 319912853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_int_base &) 320012853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_uint_base &) 320112853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_signed &) 320212853Sgabeblack@google.comDEFN_CTOR_T_C(const sc_unsigned &) 320312853Sgabeblack@google.com 320412853Sgabeblack@google.com#undef DEFN_CTOR_T 320512853Sgabeblack@google.com#undef DEFN_CTOR_T_A 320612853Sgabeblack@google.com#undef DEFN_CTOR_T_B 320712853Sgabeblack@google.com#undef DEFN_CTOR_T_C 320812853Sgabeblack@google.com#undef DEFN_CTOR_T_D 320912853Sgabeblack@google.com#undef DEFN_CTOR_T_E 321012853Sgabeblack@google.com 321112853Sgabeblack@google.cominline sc_fxnum_fast::~sc_fxnum_fast() 321212853Sgabeblack@google.com{ 321312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_DESTRUCT_(*this) 321412853Sgabeblack@google.com} 321512853Sgabeblack@google.com 321612853Sgabeblack@google.com// internal use only; 321712853Sgabeblack@google.cominline double 321812853Sgabeblack@google.comsc_fxnum_fast::get_val() const 321912853Sgabeblack@google.com{ 322012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 322112853Sgabeblack@google.com return m_val; 322212853Sgabeblack@google.com} 322312853Sgabeblack@google.com 322412853Sgabeblack@google.com// unary operators 322512853Sgabeblack@google.cominline const sc_fxval_fast 322612853Sgabeblack@google.comsc_fxnum_fast::operator - () const 322712853Sgabeblack@google.com{ 322812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 322912853Sgabeblack@google.com return sc_fxval_fast(- m_val); 323012853Sgabeblack@google.com} 323112853Sgabeblack@google.com 323212853Sgabeblack@google.cominline const sc_fxval_fast 323312853Sgabeblack@google.comsc_fxnum_fast::operator + () const 323412853Sgabeblack@google.com{ 323512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 323612853Sgabeblack@google.com return sc_fxval_fast(m_val); 323712853Sgabeblack@google.com} 323812853Sgabeblack@google.com 323912853Sgabeblack@google.com// unary functions 324012853Sgabeblack@google.cominline void 324112853Sgabeblack@google.comneg(sc_fxval_fast &c, const sc_fxnum_fast &a) 324212853Sgabeblack@google.com{ 324312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 324412853Sgabeblack@google.com c.set_val(- a.m_val); 324512853Sgabeblack@google.com} 324612853Sgabeblack@google.com 324712853Sgabeblack@google.cominline void 324812853Sgabeblack@google.comneg(sc_fxnum_fast &c, const sc_fxnum_fast &a) 324912853Sgabeblack@google.com{ 325012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 325112853Sgabeblack@google.com c.m_val = - a.m_val; 325212853Sgabeblack@google.com c.cast(); 325312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) 325412853Sgabeblack@google.com} 325512853Sgabeblack@google.com 325612853Sgabeblack@google.com// binary operators 325712853Sgabeblack@google.com#define DEFN_BIN_OP_T(op, tp) \ 325812853Sgabeblack@google.cominline const sc_fxval_fast \ 325912853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, tp b) \ 326012853Sgabeblack@google.com{ \ 326112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 326212853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 326312853Sgabeblack@google.com return sc_fxval_fast(a.m_val op tmp.get_val()); \ 326412853Sgabeblack@google.com} \ 326512853Sgabeblack@google.com \ 326612853Sgabeblack@google.cominline const sc_fxval_fast \ 326712853Sgabeblack@google.comoperator op (tp a, const sc_fxnum_fast &b) \ 326812853Sgabeblack@google.com{ \ 326912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 327012853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 327112853Sgabeblack@google.com return sc_fxval_fast(tmp.get_val() op b.m_val); \ 327212853Sgabeblack@google.com} 327312853Sgabeblack@google.com 327412853Sgabeblack@google.com#define DEFN_BIN_OP_OTHER(op) \ 327512853Sgabeblack@google.comDEFN_BIN_OP_T(op, int64) \ 327612853Sgabeblack@google.comDEFN_BIN_OP_T(op, uint64) \ 327712853Sgabeblack@google.comDEFN_BIN_OP_T(op, const sc_int_base &) \ 327812853Sgabeblack@google.comDEFN_BIN_OP_T(op, const sc_uint_base &) \ 327912853Sgabeblack@google.comDEFN_BIN_OP_T(op, const sc_signed &) \ 328012853Sgabeblack@google.comDEFN_BIN_OP_T(op, const sc_unsigned &) 328112853Sgabeblack@google.com 328212853Sgabeblack@google.com#define DEFN_BIN_OP(op, dummy) \ 328312853Sgabeblack@google.cominline const sc_fxval_fast \ 328412853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, const sc_fxnum_fast &b) \ 328512853Sgabeblack@google.com{ \ 328612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 328712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 328812853Sgabeblack@google.com return sc_fxval_fast(a.m_val op b.m_val); \ 328912853Sgabeblack@google.com} \ 329012853Sgabeblack@google.com \ 329112853Sgabeblack@google.cominline const sc_fxval_fast \ 329212853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, const sc_fxval_fast &b) \ 329312853Sgabeblack@google.com{ \ 329412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 329512853Sgabeblack@google.com return sc_fxval_fast(a.m_val op b.get_val()); \ 329612853Sgabeblack@google.com} \ 329712853Sgabeblack@google.com \ 329812853Sgabeblack@google.cominline const sc_fxval_fast \ 329912853Sgabeblack@google.comoperator op (const sc_fxval_fast &a, const sc_fxnum_fast &b) \ 330012853Sgabeblack@google.com{ \ 330112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 330212853Sgabeblack@google.com return sc_fxval_fast(a.get_val() op b.m_val); \ 330312853Sgabeblack@google.com} \ 330412853Sgabeblack@google.com \ 330512853Sgabeblack@google.comDEFN_BIN_OP_T(op, int) \ 330612853Sgabeblack@google.comDEFN_BIN_OP_T(op, unsigned int) \ 330712853Sgabeblack@google.comDEFN_BIN_OP_T(op, long) \ 330812853Sgabeblack@google.comDEFN_BIN_OP_T(op, unsigned long) \ 330912853Sgabeblack@google.comDEFN_BIN_OP_T(op, float) \ 331012853Sgabeblack@google.comDEFN_BIN_OP_T(op, double) \ 331112853Sgabeblack@google.comDEFN_BIN_OP_T(op, const char *) \ 331212853Sgabeblack@google.comDEFN_BIN_OP_OTHER(op) 331312853Sgabeblack@google.com 331412853Sgabeblack@google.comDEFN_BIN_OP(*, mult) 331512853Sgabeblack@google.comDEFN_BIN_OP(+, add) 331612853Sgabeblack@google.comDEFN_BIN_OP(-, sub) 331712853Sgabeblack@google.com//DEFN_BIN_OP(/, div) 331812853Sgabeblack@google.cominline const sc_fxval_fast 331912853Sgabeblack@google.comoperator / (const sc_fxnum_fast &a, const sc_fxnum_fast &b) 332012853Sgabeblack@google.com{ 332112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 332212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) 332312853Sgabeblack@google.com return sc_fxval_fast(a.m_val / b.m_val); 332412853Sgabeblack@google.com} 332512853Sgabeblack@google.com 332612853Sgabeblack@google.cominline const sc_fxval_fast 332712853Sgabeblack@google.comoperator / (const sc_fxnum_fast &a, const sc_fxval_fast &b) 332812853Sgabeblack@google.com{ 332912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 333012853Sgabeblack@google.com return sc_fxval_fast(a.m_val / b.get_val()); 333112853Sgabeblack@google.com} 333212853Sgabeblack@google.com 333312853Sgabeblack@google.cominline const sc_fxval_fast 333412853Sgabeblack@google.comoperator / (const sc_fxval_fast &a, const sc_fxnum_fast &b) 333512853Sgabeblack@google.com{ 333612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) 333712853Sgabeblack@google.com return sc_fxval_fast(a.get_val() / b.m_val); 333812853Sgabeblack@google.com} 333912853Sgabeblack@google.com 334012853Sgabeblack@google.comDEFN_BIN_OP_T(/, int) 334112853Sgabeblack@google.comDEFN_BIN_OP_T(/, unsigned int) 334212853Sgabeblack@google.comDEFN_BIN_OP_T(/, long) 334312853Sgabeblack@google.comDEFN_BIN_OP_T(/, unsigned long) 334412853Sgabeblack@google.comDEFN_BIN_OP_T(/, float) 334512853Sgabeblack@google.comDEFN_BIN_OP_T(/, double) 334612853Sgabeblack@google.comDEFN_BIN_OP_T(/, const char *) 334712853Sgabeblack@google.com//DEFN_BIN_OP_OTHER(/) 334812853Sgabeblack@google.com 334912853Sgabeblack@google.comDEFN_BIN_OP_T(/, int64) 335012853Sgabeblack@google.comDEFN_BIN_OP_T(/, uint64) 335112853Sgabeblack@google.comDEFN_BIN_OP_T(/, const sc_int_base &) 335212853Sgabeblack@google.comDEFN_BIN_OP_T(/, const sc_uint_base &) 335312853Sgabeblack@google.comDEFN_BIN_OP_T(/, const sc_signed &) 335412853Sgabeblack@google.comDEFN_BIN_OP_T(/, const sc_unsigned &) 335512853Sgabeblack@google.com 335612853Sgabeblack@google.com#undef DEFN_BIN_OP_T 335712853Sgabeblack@google.com#undef DEFN_BIN_OP_OTHER 335812853Sgabeblack@google.com#undef DEFN_BIN_OP 335912853Sgabeblack@google.com 336012853Sgabeblack@google.cominline const sc_fxval_fast 336112853Sgabeblack@google.comoperator << (const sc_fxnum_fast &a, int b) 336212853Sgabeblack@google.com{ 336312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 336412853Sgabeblack@google.com return sc_fxval_fast(a.m_val *scfx_pow2(b)); 336512853Sgabeblack@google.com} 336612853Sgabeblack@google.com 336712853Sgabeblack@google.cominline const sc_fxval_fast 336812853Sgabeblack@google.comoperator >> (const sc_fxnum_fast &a, int b) 336912853Sgabeblack@google.com{ 337012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 337112853Sgabeblack@google.com return sc_fxval_fast(a.m_val *scfx_pow2(-b)); 337212853Sgabeblack@google.com} 337312853Sgabeblack@google.com 337412853Sgabeblack@google.com// binary functions 337512853Sgabeblack@google.com#define DEFN_BIN_FNC_T(fnc, op, tp) \ 337612853Sgabeblack@google.cominline void \ 337712853Sgabeblack@google.comfnc (sc_fxval_fast &c, const sc_fxnum_fast &a, tp b) \ 337812853Sgabeblack@google.com{ \ 337912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 338012853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 338112853Sgabeblack@google.com c.set_val(a.m_val op tmp.get_val()); \ 338212853Sgabeblack@google.com} \ 338312853Sgabeblack@google.com \ 338412853Sgabeblack@google.cominline void \ 338512853Sgabeblack@google.comfnc (sc_fxval_fast &c, tp a, const sc_fxnum_fast &b) \ 338612853Sgabeblack@google.com{ \ 338712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 338812853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 338912853Sgabeblack@google.com c.set_val(tmp.get_val() op b.m_val); \ 339012853Sgabeblack@google.com} \ 339112853Sgabeblack@google.com \ 339212853Sgabeblack@google.cominline void \ 339312853Sgabeblack@google.comfnc (sc_fxnum_fast &c, const sc_fxnum_fast &a, tp b) \ 339412853Sgabeblack@google.com{ \ 339512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 339612853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 339712853Sgabeblack@google.com c.m_val = a.m_val op tmp.get_val(); \ 339812853Sgabeblack@google.com c.cast(); \ 339912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) \ 340012853Sgabeblack@google.com} \ 340112853Sgabeblack@google.com \ 340212853Sgabeblack@google.cominline void \ 340312853Sgabeblack@google.comfnc (sc_fxnum_fast &c, tp a, const sc_fxnum_fast &b) \ 340412853Sgabeblack@google.com{ \ 340512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 340612853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 340712853Sgabeblack@google.com c.m_val = tmp.get_val() op b.m_val; \ 340812853Sgabeblack@google.com c.cast(); \ 340912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) \ 341012853Sgabeblack@google.com} 341112853Sgabeblack@google.com 341212853Sgabeblack@google.com#define DEFN_BIN_FNC_OTHER(fnc, op) \ 341312853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, int64) \ 341412853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, uint64) \ 341512853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_int_base &) \ 341612853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_uint_base &) \ 341712853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_signed &) \ 341812853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_unsigned &) 341912853Sgabeblack@google.com 342012853Sgabeblack@google.com#define DEFN_BIN_FNC(fnc, op) \ 342112853Sgabeblack@google.cominline void \ 342212853Sgabeblack@google.comfnc (sc_fxval_fast &c, const sc_fxnum_fast &a, const sc_fxnum_fast &b) \ 342312853Sgabeblack@google.com{ \ 342412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 342512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 342612853Sgabeblack@google.com c.set_val(a.m_val op b.m_val); \ 342712853Sgabeblack@google.com} \ 342812853Sgabeblack@google.com \ 342912853Sgabeblack@google.cominline void \ 343012853Sgabeblack@google.comfnc (sc_fxnum_fast &c, const sc_fxnum_fast &a, const sc_fxnum_fast &b) \ 343112853Sgabeblack@google.com{ \ 343212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 343312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 343412853Sgabeblack@google.com c.m_val = a.m_val op b.m_val; \ 343512853Sgabeblack@google.com c.cast(); \ 343612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) \ 343712853Sgabeblack@google.com} \ 343812853Sgabeblack@google.com \ 343912853Sgabeblack@google.cominline void \ 344012853Sgabeblack@google.comfnc (sc_fxval_fast &c, const sc_fxnum_fast &a, const sc_fxval_fast &b) \ 344112853Sgabeblack@google.com{ \ 344212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 344312853Sgabeblack@google.com c.set_val(a.m_val op b.get_val()); \ 344412853Sgabeblack@google.com} \ 344512853Sgabeblack@google.com \ 344612853Sgabeblack@google.cominline void \ 344712853Sgabeblack@google.comfnc (sc_fxval_fast &c, const sc_fxval_fast &a, const sc_fxnum_fast &b) \ 344812853Sgabeblack@google.com{ \ 344912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 345012853Sgabeblack@google.com c.set_val(a.get_val() op b.m_val); \ 345112853Sgabeblack@google.com} \ 345212853Sgabeblack@google.com \ 345312853Sgabeblack@google.cominline void \ 345412853Sgabeblack@google.comfnc (sc_fxnum_fast &c, const sc_fxnum_fast &a, const sc_fxval_fast &b) \ 345512853Sgabeblack@google.com{ \ 345612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 345712853Sgabeblack@google.com c.m_val = a.m_val op b.get_val(); \ 345812853Sgabeblack@google.com c.cast(); \ 345912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) \ 346012853Sgabeblack@google.com} \ 346112853Sgabeblack@google.com \ 346212853Sgabeblack@google.cominline void \ 346312853Sgabeblack@google.comfnc (sc_fxnum_fast &c, const sc_fxval_fast &a, const sc_fxnum_fast &b) \ 346412853Sgabeblack@google.com{ \ 346512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 346612853Sgabeblack@google.com c.m_val = a.get_val() op b.m_val; \ 346712853Sgabeblack@google.com c.cast(); \ 346812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) \ 346912853Sgabeblack@google.com} \ 347012853Sgabeblack@google.com \ 347112853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, int) \ 347212853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, unsigned int) \ 347312853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, long) \ 347412853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, unsigned long) \ 347512853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, float) \ 347612853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, double) \ 347712853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const char *) \ 347812853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_fxval &) \ 347912853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_fxnum &) \ 348012853Sgabeblack@google.comDEFN_BIN_FNC_OTHER(fnc, op) 348112853Sgabeblack@google.com 348212853Sgabeblack@google.comDEFN_BIN_FNC(mult, *) 348312853Sgabeblack@google.comDEFN_BIN_FNC(div, /) 348412853Sgabeblack@google.comDEFN_BIN_FNC(add, +) 348512853Sgabeblack@google.comDEFN_BIN_FNC(sub, -) 348612853Sgabeblack@google.com 348712853Sgabeblack@google.com#undef DEFN_BIN_FNC_T 348812853Sgabeblack@google.com#undef DEFN_BIN_FNC_OTHER 348912853Sgabeblack@google.com#undef DEFN_BIN_FNC 349012853Sgabeblack@google.com 349112853Sgabeblack@google.cominline void 349212853Sgabeblack@google.comlshift(sc_fxval_fast &c, const sc_fxnum_fast &a, int b) 349312853Sgabeblack@google.com{ 349412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 349512853Sgabeblack@google.com c.set_val(a.m_val * scfx_pow2(b)); 349612853Sgabeblack@google.com} 349712853Sgabeblack@google.com 349812853Sgabeblack@google.cominline void 349912853Sgabeblack@google.comrshift(sc_fxval_fast &c, const sc_fxnum_fast &a, int b) 350012853Sgabeblack@google.com{ 350112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 350212853Sgabeblack@google.com c.set_val(a.m_val * scfx_pow2(-b)); 350312853Sgabeblack@google.com} 350412853Sgabeblack@google.com 350512853Sgabeblack@google.cominline void 350612853Sgabeblack@google.comlshift(sc_fxnum_fast &c, const sc_fxnum_fast &a, int b) 350712853Sgabeblack@google.com{ 350812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 350912853Sgabeblack@google.com c.m_val = a.m_val * scfx_pow2(b); 351012853Sgabeblack@google.com c.cast(); 351112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) 351212853Sgabeblack@google.com} 351312853Sgabeblack@google.com 351412853Sgabeblack@google.cominline void 351512853Sgabeblack@google.comrshift(sc_fxnum_fast &c, const sc_fxnum_fast &a, int b) 351612853Sgabeblack@google.com{ 351712853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 351812853Sgabeblack@google.com c.m_val = a.m_val * scfx_pow2(-b); 351912853Sgabeblack@google.com c.cast(); 352012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(c) 352112853Sgabeblack@google.com} 352212853Sgabeblack@google.com 352312853Sgabeblack@google.com// relational (including equality) operators 352412853Sgabeblack@google.com#define DEFN_REL_OP_T(op, tp) \ 352512853Sgabeblack@google.cominline bool \ 352612853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, tp b) \ 352712853Sgabeblack@google.com{ \ 352812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 352912853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 353012853Sgabeblack@google.com return (a.m_val op tmp.get_val()); \ 353112853Sgabeblack@google.com} \ 353212853Sgabeblack@google.com \ 353312853Sgabeblack@google.cominline bool \ 353412853Sgabeblack@google.comoperator op (tp a, const sc_fxnum_fast &b) \ 353512853Sgabeblack@google.com{ \ 353612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 353712853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 353812853Sgabeblack@google.com return (tmp.get_val() op b.m_val); \ 353912853Sgabeblack@google.com} 354012853Sgabeblack@google.com 354112853Sgabeblack@google.com#define DEFN_REL_OP_OTHER(op) \ 354212853Sgabeblack@google.comDEFN_REL_OP_T(op, int64) \ 354312853Sgabeblack@google.comDEFN_REL_OP_T(op, uint64) \ 354412853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_int_base &) \ 354512853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_uint_base &) \ 354612853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_signed &) \ 354712853Sgabeblack@google.comDEFN_REL_OP_T(op, const sc_unsigned &) 354812853Sgabeblack@google.com 354912853Sgabeblack@google.com#define DEFN_REL_OP(op) \ 355012853Sgabeblack@google.cominline bool \ 355112853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, const sc_fxnum_fast &b) \ 355212853Sgabeblack@google.com{ \ 355312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 355412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 355512853Sgabeblack@google.com return (a.m_val op b.m_val); \ 355612853Sgabeblack@google.com} \ 355712853Sgabeblack@google.com \ 355812853Sgabeblack@google.cominline bool \ 355912853Sgabeblack@google.comoperator op (const sc_fxnum_fast &a, const sc_fxval_fast &b) \ 356012853Sgabeblack@google.com{ \ 356112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) \ 356212853Sgabeblack@google.com return (a.m_val op b.get_val()); \ 356312853Sgabeblack@google.com} \ 356412853Sgabeblack@google.com \ 356512853Sgabeblack@google.cominline bool \ 356612853Sgabeblack@google.comoperator op (const sc_fxval_fast &a, const sc_fxnum_fast &b) \ 356712853Sgabeblack@google.com{ \ 356812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 356912853Sgabeblack@google.com return (a.get_val() op b.m_val); \ 357012853Sgabeblack@google.com} \ 357112853Sgabeblack@google.com \ 357212853Sgabeblack@google.comDEFN_REL_OP_T(op, int) \ 357312853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned int) \ 357412853Sgabeblack@google.comDEFN_REL_OP_T(op, long) \ 357512853Sgabeblack@google.comDEFN_REL_OP_T(op, unsigned long) \ 357612853Sgabeblack@google.comDEFN_REL_OP_T(op, float) \ 357712853Sgabeblack@google.comDEFN_REL_OP_T(op, double) \ 357812853Sgabeblack@google.comDEFN_REL_OP_T(op, const char *) \ 357912853Sgabeblack@google.comDEFN_REL_OP_OTHER(op) 358012853Sgabeblack@google.com 358112853Sgabeblack@google.comDEFN_REL_OP(<) 358212853Sgabeblack@google.comDEFN_REL_OP(<=) 358312853Sgabeblack@google.comDEFN_REL_OP(>) 358412853Sgabeblack@google.comDEFN_REL_OP(>=) 358512853Sgabeblack@google.comDEFN_REL_OP(==) 358612853Sgabeblack@google.comDEFN_REL_OP(!=) 358712853Sgabeblack@google.com 358812853Sgabeblack@google.com#undef DEFN_REL_OP_T 358912853Sgabeblack@google.com#undef DEFN_REL_OP_OTHER 359012853Sgabeblack@google.com#undef DEFN_REL_OP 359112853Sgabeblack@google.com 359212853Sgabeblack@google.com// assignment operators 359312853Sgabeblack@google.com 359412853Sgabeblack@google.cominline sc_fxnum_fast & 359512853Sgabeblack@google.comsc_fxnum_fast::operator = (const sc_fxnum_fast &a) 359612853Sgabeblack@google.com{ 359712853Sgabeblack@google.com if (&a != this) { 359812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(a) 359912853Sgabeblack@google.com m_val = a.m_val; 360012853Sgabeblack@google.com cast(); 360112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 360212853Sgabeblack@google.com } 360312853Sgabeblack@google.com return *this; 360412853Sgabeblack@google.com} 360512853Sgabeblack@google.com 360612853Sgabeblack@google.cominline sc_fxnum_fast & 360712853Sgabeblack@google.comsc_fxnum_fast::operator = (const sc_fxval_fast &a) 360812853Sgabeblack@google.com{ 360912853Sgabeblack@google.com m_val = a.get_val(); 361012853Sgabeblack@google.com cast(); 361112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 361212853Sgabeblack@google.com return *this; 361312853Sgabeblack@google.com} 361412853Sgabeblack@google.com 361512853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 361612853Sgabeblack@google.cominline sc_fxnum_fast & \ 361712853Sgabeblack@google.comsc_fxnum_fast::operator = (tp a) \ 361812853Sgabeblack@google.com{ \ 361912853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 362012853Sgabeblack@google.com m_val = tmp.get_val(); \ 362112853Sgabeblack@google.com cast(); \ 362212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \ 362312853Sgabeblack@google.com return *this; \ 362412853Sgabeblack@google.com} 362512853Sgabeblack@google.com 362612853Sgabeblack@google.comDEFN_ASN_OP_T(int) 362712853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned int) 362812853Sgabeblack@google.comDEFN_ASN_OP_T(long) 362912853Sgabeblack@google.comDEFN_ASN_OP_T(unsigned long) 363012853Sgabeblack@google.comDEFN_ASN_OP_T(float) 363112853Sgabeblack@google.comDEFN_ASN_OP_T(double) 363212853Sgabeblack@google.comDEFN_ASN_OP_T(const char *) 363312853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxval &) 363412853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxnum &) 363512853Sgabeblack@google.com 363612853Sgabeblack@google.comDEFN_ASN_OP_T(int64) 363712853Sgabeblack@google.comDEFN_ASN_OP_T(uint64) 363812853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_int_base &) 363912853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_uint_base &) 364012853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_signed &) 364112853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_unsigned &) 364212853Sgabeblack@google.com 364312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 364412853Sgabeblack@google.com 364512853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, tp) \ 364612853Sgabeblack@google.cominline sc_fxnum_fast & \ 364712853Sgabeblack@google.comsc_fxnum_fast::operator op (tp b) \ 364812853Sgabeblack@google.com{ \ 364912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) \ 365012853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 365112853Sgabeblack@google.com m_val op tmp.get_val(); \ 365212853Sgabeblack@google.com cast(); \ 365312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \ 365412853Sgabeblack@google.com return *this; \ 365512853Sgabeblack@google.com} 365612853Sgabeblack@google.com 365712853Sgabeblack@google.com#define DEFN_ASN_OP_OTHER(op) \ 365812853Sgabeblack@google.comDEFN_ASN_OP_T(op, int64) \ 365912853Sgabeblack@google.comDEFN_ASN_OP_T(op, uint64) \ 366012853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_int_base &) \ 366112853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_uint_base &) \ 366212853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_signed &) \ 366312853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_unsigned &) 366412853Sgabeblack@google.com 366512853Sgabeblack@google.com#define DEFN_ASN_OP(op) \ 366612853Sgabeblack@google.cominline sc_fxnum_fast & \ 366712853Sgabeblack@google.comsc_fxnum_fast::operator op (const sc_fxnum_fast &b) \ 366812853Sgabeblack@google.com{ \ 366912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) \ 367012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(b) \ 367112853Sgabeblack@google.com m_val op b.m_val; \ 367212853Sgabeblack@google.com cast(); \ 367312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \ 367412853Sgabeblack@google.com return *this; \ 367512853Sgabeblack@google.com} \ 367612853Sgabeblack@google.com \ 367712853Sgabeblack@google.cominline sc_fxnum_fast & \ 367812853Sgabeblack@google.comsc_fxnum_fast::operator op (const sc_fxval_fast &b) \ 367912853Sgabeblack@google.com{ \ 368012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) \ 368112853Sgabeblack@google.com m_val op b.get_val(); \ 368212853Sgabeblack@google.com cast(); \ 368312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \ 368412853Sgabeblack@google.com return *this; \ 368512853Sgabeblack@google.com} \ 368612853Sgabeblack@google.com \ 368712853Sgabeblack@google.comDEFN_ASN_OP_T(op, int) \ 368812853Sgabeblack@google.comDEFN_ASN_OP_T(op, unsigned int) \ 368912853Sgabeblack@google.comDEFN_ASN_OP_T(op, long) \ 369012853Sgabeblack@google.comDEFN_ASN_OP_T(op, unsigned long) \ 369112853Sgabeblack@google.comDEFN_ASN_OP_T(op, float) \ 369212853Sgabeblack@google.comDEFN_ASN_OP_T(op, double) \ 369312853Sgabeblack@google.comDEFN_ASN_OP_T(op, const char *) \ 369412853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_fxval &) \ 369512853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_fxnum &) \ 369612853Sgabeblack@google.comDEFN_ASN_OP_OTHER(op) 369712853Sgabeblack@google.com 369812853Sgabeblack@google.comDEFN_ASN_OP(*=) 369912853Sgabeblack@google.comDEFN_ASN_OP(/=) 370012853Sgabeblack@google.comDEFN_ASN_OP(+=) 370112853Sgabeblack@google.comDEFN_ASN_OP(-=) 370212853Sgabeblack@google.com 370312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 370412853Sgabeblack@google.com#undef DEFN_ASN_OP_OTHER 370512853Sgabeblack@google.com#undef DEFN_ASN_OP 370612853Sgabeblack@google.com 370712853Sgabeblack@google.cominline sc_fxnum_fast & 370812853Sgabeblack@google.comsc_fxnum_fast::operator <<= (int b) 370912853Sgabeblack@google.com{ 371012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 371112853Sgabeblack@google.com m_val *= scfx_pow2(b); 371212853Sgabeblack@google.com cast(); 371312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 371412853Sgabeblack@google.com return *this; 371512853Sgabeblack@google.com} 371612853Sgabeblack@google.com 371712853Sgabeblack@google.cominline sc_fxnum_fast & 371812853Sgabeblack@google.comsc_fxnum_fast::operator >>= (int b) 371912853Sgabeblack@google.com{ 372012853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 372112853Sgabeblack@google.com m_val *= scfx_pow2(-b); 372212853Sgabeblack@google.com cast(); 372312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 372412853Sgabeblack@google.com return *this; 372512853Sgabeblack@google.com} 372612853Sgabeblack@google.com 372712853Sgabeblack@google.com// auto-increment and auto-decrement 372812853Sgabeblack@google.cominline const sc_fxval_fast 372912853Sgabeblack@google.comsc_fxnum_fast::operator ++ (int) 373012853Sgabeblack@google.com{ 373112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 373212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 373312853Sgabeblack@google.com double c = m_val; 373412853Sgabeblack@google.com m_val = m_val + 1; 373512853Sgabeblack@google.com cast(); 373612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 373712853Sgabeblack@google.com return sc_fxval_fast(c); 373812853Sgabeblack@google.com} 373912853Sgabeblack@google.com 374012853Sgabeblack@google.cominline const sc_fxval_fast 374112853Sgabeblack@google.comsc_fxnum_fast::operator -- (int) 374212853Sgabeblack@google.com{ 374312853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 374412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 374512853Sgabeblack@google.com double c = m_val; 374612853Sgabeblack@google.com m_val = m_val - 1; 374712853Sgabeblack@google.com cast(); 374812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 374912853Sgabeblack@google.com return sc_fxval_fast(c); 375012853Sgabeblack@google.com} 375112853Sgabeblack@google.com 375212853Sgabeblack@google.cominline sc_fxnum_fast & 375312853Sgabeblack@google.comsc_fxnum_fast::operator ++ () 375412853Sgabeblack@google.com{ 375512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 375612853Sgabeblack@google.com m_val = m_val + 1; 375712853Sgabeblack@google.com cast(); 375812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 375912853Sgabeblack@google.com return *this; 376012853Sgabeblack@google.com} 376112853Sgabeblack@google.com 376212853Sgabeblack@google.cominline sc_fxnum_fast & 376312853Sgabeblack@google.comsc_fxnum_fast::operator -- () 376412853Sgabeblack@google.com{ 376512853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 376612853Sgabeblack@google.com m_val = m_val - 1; 376712853Sgabeblack@google.com cast(); 376812853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_WRITE_(*this) 376912853Sgabeblack@google.com return *this; 377012853Sgabeblack@google.com} 377112853Sgabeblack@google.com 377212853Sgabeblack@google.com// bit selection 377312853Sgabeblack@google.cominline const sc_fxnum_fast_bitref 377412853Sgabeblack@google.comsc_fxnum_fast::operator [] (int i) const 377512853Sgabeblack@google.com{ 377612853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 377712853Sgabeblack@google.com return sc_fxnum_fast_bitref(const_cast<sc_fxnum_fast &>(*this), 377812853Sgabeblack@google.com i - m_params.fwl()); 377912853Sgabeblack@google.com} 378012853Sgabeblack@google.com 378112853Sgabeblack@google.cominline sc_fxnum_fast_bitref 378212853Sgabeblack@google.comsc_fxnum_fast::operator [] (int i) 378312853Sgabeblack@google.com{ 378412853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 378512853Sgabeblack@google.com return sc_fxnum_fast_bitref(*this, i - m_params.fwl()); 378612853Sgabeblack@google.com} 378712853Sgabeblack@google.com 378812853Sgabeblack@google.cominline const sc_fxnum_fast_bitref 378912853Sgabeblack@google.comsc_fxnum_fast::bit(int i) const 379012853Sgabeblack@google.com{ 379112853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 379212853Sgabeblack@google.com return sc_fxnum_fast_bitref(const_cast<sc_fxnum_fast &>(*this), 379312853Sgabeblack@google.com i - m_params.fwl()); 379412853Sgabeblack@google.com} 379512853Sgabeblack@google.com 379612853Sgabeblack@google.cominline sc_fxnum_fast_bitref 379712853Sgabeblack@google.comsc_fxnum_fast::bit(int i) 379812853Sgabeblack@google.com{ 379912853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 380012853Sgabeblack@google.com return sc_fxnum_fast_bitref(*this, i - m_params.fwl()); 380112853Sgabeblack@google.com} 380212853Sgabeblack@google.com 380312853Sgabeblack@google.com// part selection 380412853Sgabeblack@google.cominline const sc_fxnum_fast_subref 380512853Sgabeblack@google.comsc_fxnum_fast::operator () (int i, int j) const 380612853Sgabeblack@google.com{ 380712853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 380812853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 380912853Sgabeblack@google.com 381012853Sgabeblack@google.com return sc_fxnum_fast_subref(const_cast<sc_fxnum_fast &>(*this), 381112853Sgabeblack@google.com i - m_params.fwl(), j - m_params.fwl()); 381212853Sgabeblack@google.com} 381312853Sgabeblack@google.com 381412853Sgabeblack@google.cominline sc_fxnum_fast_subref 381512853Sgabeblack@google.comsc_fxnum_fast::operator () (int i, int j) 381612853Sgabeblack@google.com{ 381712853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 381812853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 381912853Sgabeblack@google.com 382012853Sgabeblack@google.com return sc_fxnum_fast_subref(*this, i - m_params.fwl(), j - m_params.fwl()); 382112853Sgabeblack@google.com} 382212853Sgabeblack@google.com 382312853Sgabeblack@google.cominline const sc_fxnum_fast_subref 382412853Sgabeblack@google.comsc_fxnum_fast::range(int i, int j) const 382512853Sgabeblack@google.com{ 382612853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 382712853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 382812853Sgabeblack@google.com 382912853Sgabeblack@google.com return sc_fxnum_fast_subref(const_cast<sc_fxnum_fast &>(*this), 383012853Sgabeblack@google.com i - m_params.fwl(), j - m_params.fwl()); 383112853Sgabeblack@google.com} 383212853Sgabeblack@google.com 383312853Sgabeblack@google.cominline sc_fxnum_fast_subref 383412853Sgabeblack@google.comsc_fxnum_fast::range(int i, int j) 383512853Sgabeblack@google.com{ 383612853Sgabeblack@google.com SC_ERROR_IF_(i < 0 || i >= m_params.wl(), "index out of range"); 383712853Sgabeblack@google.com SC_ERROR_IF_(j < 0 || j >= m_params.wl(), "index out of range"); 383812853Sgabeblack@google.com 383912853Sgabeblack@google.com return sc_fxnum_fast_subref(*this, i - m_params.fwl(), j - m_params.fwl()); 384012853Sgabeblack@google.com} 384112853Sgabeblack@google.com 384212853Sgabeblack@google.cominline const sc_fxnum_fast_subref 384312853Sgabeblack@google.comsc_fxnum_fast::operator () () const 384412853Sgabeblack@google.com{ 384512853Sgabeblack@google.com return this->operator () (m_params.wl() - 1, 0); 384612853Sgabeblack@google.com} 384712853Sgabeblack@google.com 384812853Sgabeblack@google.cominline sc_fxnum_fast_subref 384912853Sgabeblack@google.comsc_fxnum_fast::operator () () 385012853Sgabeblack@google.com{ 385112853Sgabeblack@google.com return this->operator () (m_params.wl() - 1, 0); 385212853Sgabeblack@google.com} 385312853Sgabeblack@google.com 385412853Sgabeblack@google.cominline const sc_fxnum_fast_subref 385512853Sgabeblack@google.comsc_fxnum_fast::range() const 385612853Sgabeblack@google.com{ 385712853Sgabeblack@google.com return this->range(m_params.wl() - 1, 0); 385812853Sgabeblack@google.com} 385912853Sgabeblack@google.com 386012853Sgabeblack@google.cominline sc_fxnum_fast_subref 386112853Sgabeblack@google.comsc_fxnum_fast::range() 386212853Sgabeblack@google.com{ 386312853Sgabeblack@google.com return this->range(m_params.wl() - 1, 0); 386412853Sgabeblack@google.com} 386512853Sgabeblack@google.com 386612853Sgabeblack@google.com// implicit conversion 386712853Sgabeblack@google.cominline sc_fxnum_fast::operator double() const 386812853Sgabeblack@google.com{ 386912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 387012853Sgabeblack@google.com return m_val; 387112853Sgabeblack@google.com} 387212853Sgabeblack@google.com 387312853Sgabeblack@google.com// explicit conversion to primitive types 387412853Sgabeblack@google.cominline short 387512853Sgabeblack@google.comsc_fxnum_fast::to_short() const 387612853Sgabeblack@google.com{ 387712853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 387812853Sgabeblack@google.com return static_cast<short>(to_uint64()); 387912853Sgabeblack@google.com} 388012853Sgabeblack@google.com 388112853Sgabeblack@google.cominline unsigned short 388212853Sgabeblack@google.comsc_fxnum_fast::to_ushort() const 388312853Sgabeblack@google.com{ 388412853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 388512853Sgabeblack@google.com return static_cast<unsigned short>(to_uint64()); 388612853Sgabeblack@google.com} 388712853Sgabeblack@google.com 388812853Sgabeblack@google.cominline int 388912853Sgabeblack@google.comsc_fxnum_fast::to_int() const 389012853Sgabeblack@google.com{ 389112853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 389212853Sgabeblack@google.com return static_cast<int>(to_uint64()); 389312853Sgabeblack@google.com} 389412853Sgabeblack@google.com 389512853Sgabeblack@google.cominline int64 389612853Sgabeblack@google.comsc_fxnum_fast::to_int64() const 389712853Sgabeblack@google.com{ 389812853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 389912853Sgabeblack@google.com return static_cast<int64>(to_uint64()); 390012853Sgabeblack@google.com} 390112853Sgabeblack@google.com 390212853Sgabeblack@google.cominline unsigned int 390312853Sgabeblack@google.comsc_fxnum_fast::to_uint() const 390412853Sgabeblack@google.com{ 390512853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 390612853Sgabeblack@google.com return static_cast<unsigned int>(to_uint64()); 390712853Sgabeblack@google.com} 390812853Sgabeblack@google.com 390912853Sgabeblack@google.cominline uint64 391012853Sgabeblack@google.comsc_fxnum_fast::to_uint64() const 391112853Sgabeblack@google.com{ 391212853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in is_normal 391312853Sgabeblack@google.com if (!is_normal()) { 391412853Sgabeblack@google.com return 0; 391512853Sgabeblack@google.com } 391612853Sgabeblack@google.com 391712853Sgabeblack@google.com int exponent; 391812853Sgabeblack@google.com double mantissa_dbl = frexp(m_val, &exponent); 391912853Sgabeblack@google.com 392012853Sgabeblack@google.com uint64 mantissa = static_cast<uint64>(fabs(mantissa_dbl) * 392112853Sgabeblack@google.com (UINT64_ONE << 53)); 392212853Sgabeblack@google.com exponent -= 53; 392312853Sgabeblack@google.com 392412853Sgabeblack@google.com if (!(-64 < exponent && exponent < 64)) { 392512853Sgabeblack@google.com return 0; 392612853Sgabeblack@google.com } 392712853Sgabeblack@google.com 392812853Sgabeblack@google.com mantissa = exponent >= 0 ? mantissa << exponent : mantissa >> -exponent; 392912853Sgabeblack@google.com return mantissa_dbl >= 0 ? mantissa : -mantissa; 393012853Sgabeblack@google.com} 393112853Sgabeblack@google.com 393212853Sgabeblack@google.cominline long 393312853Sgabeblack@google.comsc_fxnum_fast::to_long() const 393412853Sgabeblack@google.com{ 393512853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 393612853Sgabeblack@google.com return static_cast<long>(to_uint64()); 393712853Sgabeblack@google.com} 393812853Sgabeblack@google.com 393912853Sgabeblack@google.cominline unsigned long 394012853Sgabeblack@google.comsc_fxnum_fast::to_ulong() const 394112853Sgabeblack@google.com{ 394212853Sgabeblack@google.com // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64 394312853Sgabeblack@google.com return static_cast<unsigned long>(to_uint64()); 394412853Sgabeblack@google.com} 394512853Sgabeblack@google.com 394612853Sgabeblack@google.cominline float 394712853Sgabeblack@google.comsc_fxnum_fast::to_float() const 394812853Sgabeblack@google.com{ 394912853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 395012853Sgabeblack@google.com return static_cast<float>(m_val); 395112853Sgabeblack@google.com} 395212853Sgabeblack@google.com 395312853Sgabeblack@google.cominline double 395412853Sgabeblack@google.comsc_fxnum_fast::to_double() const 395512853Sgabeblack@google.com{ 395612853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 395712853Sgabeblack@google.com return m_val; 395812853Sgabeblack@google.com} 395912853Sgabeblack@google.com 396012853Sgabeblack@google.com// query value 396112853Sgabeblack@google.cominline bool 396212853Sgabeblack@google.comsc_fxnum_fast::is_neg() const 396312853Sgabeblack@google.com{ 396412853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 396512853Sgabeblack@google.com scfx_ieee_double id(m_val); 396612853Sgabeblack@google.com return (id.negative() != 0); 396712853Sgabeblack@google.com} 396812853Sgabeblack@google.com 396912853Sgabeblack@google.cominline bool 397012853Sgabeblack@google.comsc_fxnum_fast::is_zero() const 397112853Sgabeblack@google.com{ 397212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 397312853Sgabeblack@google.com scfx_ieee_double id(m_val); 397412853Sgabeblack@google.com return id.is_zero(); 397512853Sgabeblack@google.com} 397612853Sgabeblack@google.com 397712853Sgabeblack@google.com// internal use only; 397812853Sgabeblack@google.cominline bool 397912853Sgabeblack@google.comsc_fxnum_fast::is_normal() const 398012853Sgabeblack@google.com{ 398112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 398212853Sgabeblack@google.com scfx_ieee_double id(m_val); 398312853Sgabeblack@google.com return (id.is_normal() || id.is_subnormal() || id.is_zero()); 398412853Sgabeblack@google.com} 398512853Sgabeblack@google.com 398612853Sgabeblack@google.cominline bool 398712853Sgabeblack@google.comsc_fxnum_fast::quantization_flag() const 398812853Sgabeblack@google.com{ 398912853Sgabeblack@google.com return m_q_flag; 399012853Sgabeblack@google.com} 399112853Sgabeblack@google.com 399212853Sgabeblack@google.cominline bool 399312853Sgabeblack@google.comsc_fxnum_fast::overflow_flag() const 399412853Sgabeblack@google.com{ 399512853Sgabeblack@google.com return m_o_flag; 399612853Sgabeblack@google.com} 399712853Sgabeblack@google.com 399812853Sgabeblack@google.cominline const sc_fxval_fast 399912853Sgabeblack@google.comsc_fxnum_fast::value() const 400012853Sgabeblack@google.com{ 400112853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this) 400212853Sgabeblack@google.com return sc_fxval_fast(m_val); 400312853Sgabeblack@google.com} 400412853Sgabeblack@google.com 400512853Sgabeblack@google.com// query parameters 400612853Sgabeblack@google.cominline int 400712853Sgabeblack@google.comsc_fxnum_fast::wl() const 400812853Sgabeblack@google.com{ 400912853Sgabeblack@google.com return m_params.wl(); 401012853Sgabeblack@google.com} 401112853Sgabeblack@google.com 401212853Sgabeblack@google.cominline int 401312853Sgabeblack@google.comsc_fxnum_fast::iwl() const 401412853Sgabeblack@google.com{ 401512853Sgabeblack@google.com return m_params.iwl(); 401612853Sgabeblack@google.com} 401712853Sgabeblack@google.com 401812853Sgabeblack@google.cominline sc_q_mode 401912853Sgabeblack@google.comsc_fxnum_fast::q_mode() const 402012853Sgabeblack@google.com{ 402112853Sgabeblack@google.com return m_params.q_mode(); 402212853Sgabeblack@google.com} 402312853Sgabeblack@google.com 402412853Sgabeblack@google.cominline sc_o_mode 402512853Sgabeblack@google.comsc_fxnum_fast::o_mode() const 402612853Sgabeblack@google.com{ 402712853Sgabeblack@google.com return m_params.o_mode(); 402812853Sgabeblack@google.com} 402912853Sgabeblack@google.com 403012853Sgabeblack@google.cominline int 403112853Sgabeblack@google.comsc_fxnum_fast::n_bits() const 403212853Sgabeblack@google.com{ 403312853Sgabeblack@google.com return m_params.n_bits(); 403412853Sgabeblack@google.com} 403512853Sgabeblack@google.com 403612853Sgabeblack@google.cominline const sc_fxtype_params & 403712853Sgabeblack@google.comsc_fxnum_fast::type_params() const 403812853Sgabeblack@google.com{ 403912853Sgabeblack@google.com return m_params.type_params(); 404012853Sgabeblack@google.com} 404112853Sgabeblack@google.com 404212853Sgabeblack@google.cominline const sc_fxcast_switch & 404312853Sgabeblack@google.comsc_fxnum_fast::cast_switch() const 404412853Sgabeblack@google.com{ 404512853Sgabeblack@google.com return m_params.cast_switch(); 404612853Sgabeblack@google.com} 404712853Sgabeblack@google.com 404812853Sgabeblack@google.com// internal use only; 404912853Sgabeblack@google.cominline void 405012853Sgabeblack@google.comsc_fxnum_fast::observer_read() const 405112853Sgabeblack@google.com{ 405212853Sgabeblack@google.com SC_FXNUM_FAST_OBSERVER_READ_(*this); 405312853Sgabeblack@google.com} 405412853Sgabeblack@google.com 405512853Sgabeblack@google.cominline ::std::ostream & 405612853Sgabeblack@google.comoperator << (::std::ostream &os, const sc_fxnum_fast &a) 405712853Sgabeblack@google.com{ 405812853Sgabeblack@google.com a.print(os); 405912853Sgabeblack@google.com return os; 406012853Sgabeblack@google.com} 406112853Sgabeblack@google.com 406212853Sgabeblack@google.cominline ::std::istream & 406312853Sgabeblack@google.comoperator >> (::std::istream &is, sc_fxnum_fast &a) 406412853Sgabeblack@google.com{ 406512853Sgabeblack@google.com a.scan(is); 406612853Sgabeblack@google.com return is; 406712853Sgabeblack@google.com} 406812853Sgabeblack@google.com 406912853Sgabeblack@google.com 407012853Sgabeblack@google.com// ---------------------------------------------------------------------------- 407112853Sgabeblack@google.com// CLASS : sc_fxval 407212853Sgabeblack@google.com// 407312853Sgabeblack@google.com// Fixed-point value type; arbitrary precision. 407412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 407512853Sgabeblack@google.com 407612853Sgabeblack@google.com// public constructors 407712853Sgabeblack@google.cominline sc_fxval::sc_fxval(const sc_fxnum &a, sc_fxval_observer *observer_) : 407812853Sgabeblack@google.com m_rep(new scfx_rep(*a.get_rep())), m_observer(observer_) 407912853Sgabeblack@google.com{ 408012853Sgabeblack@google.com SC_FXVAL_OBSERVER_DEFAULT_ 408112853Sgabeblack@google.com SC_FXVAL_OBSERVER_CONSTRUCT_(*this) 408212853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) 408312853Sgabeblack@google.com} 408412853Sgabeblack@google.com 408512853Sgabeblack@google.cominline sc_fxval::sc_fxval(const sc_fxnum_fast &a, 408612853Sgabeblack@google.com sc_fxval_observer *observer_) : 408712853Sgabeblack@google.com m_rep(new scfx_rep(a.to_double())), m_observer(observer_) 408812853Sgabeblack@google.com{ 408912853Sgabeblack@google.com SC_FXVAL_OBSERVER_DEFAULT_ 409012853Sgabeblack@google.com SC_FXVAL_OBSERVER_CONSTRUCT_(*this) 409112853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) 409212853Sgabeblack@google.com} 409312853Sgabeblack@google.com 409412853Sgabeblack@google.com// binary operators 409512853Sgabeblack@google.com#define DEFN_BIN_OP_T(op, fnc, tp) \ 409612853Sgabeblack@google.cominline const sc_fxval \ 409712853Sgabeblack@google.comoperator op (const sc_fxval &a, tp b) \ 409812853Sgabeblack@google.com{ \ 409912853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(a) \ 410012853Sgabeblack@google.com sc_fxval tmp(b); \ 410112853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*a.m_rep, *tmp.m_rep)); \ 410212853Sgabeblack@google.com} \ 410312853Sgabeblack@google.com \ 410412853Sgabeblack@google.cominline const sc_fxval \ 410512853Sgabeblack@google.comoperator op (tp a, const sc_fxval &b) \ 410612853Sgabeblack@google.com{ \ 410712853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(b) \ 410812853Sgabeblack@google.com sc_fxval tmp(a); \ 410912853Sgabeblack@google.com return sc_fxval(sc_dt::fnc ## _scfx_rep(*tmp.m_rep, *b.m_rep)); \ 411012853Sgabeblack@google.com} 411112853Sgabeblack@google.com 411212853Sgabeblack@google.com#define DEFN_BIN_OP(op, fnc) \ 411312853Sgabeblack@google.comDEFN_BIN_OP_T(op, fnc, const sc_fxnum_fast &) 411412853Sgabeblack@google.com 411512853Sgabeblack@google.comDEFN_BIN_OP(*, mult) 411612853Sgabeblack@google.comDEFN_BIN_OP(+, add) 411712853Sgabeblack@google.comDEFN_BIN_OP(-, sub) 411812853Sgabeblack@google.com//DEFN_BIN_OP(/, div) 411912853Sgabeblack@google.comDEFN_BIN_OP_T(/, div, const sc_fxnum_fast &) 412012853Sgabeblack@google.com 412112853Sgabeblack@google.com#undef DEFN_BIN_OP_T 412212853Sgabeblack@google.com#undef DEFN_BIN_OP 412312853Sgabeblack@google.com 412412853Sgabeblack@google.com 412512853Sgabeblack@google.com// binary functions 412612853Sgabeblack@google.com#define DEFN_BIN_FNC_T(fnc, tp) \ 412712853Sgabeblack@google.cominline void \ 412812853Sgabeblack@google.comfnc (sc_fxval &c, const sc_fxval &a, tp b) \ 412912853Sgabeblack@google.com{ \ 413012853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(a) \ 413112853Sgabeblack@google.com sc_fxval tmp(b); \ 413212853Sgabeblack@google.com delete c.m_rep; \ 413312853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*a.m_rep, *tmp.m_rep); \ 413412853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(c) \ 413512853Sgabeblack@google.com} \ 413612853Sgabeblack@google.com \ 413712853Sgabeblack@google.cominline void \ 413812853Sgabeblack@google.comfnc (sc_fxval &c, tp a, const sc_fxval &b) \ 413912853Sgabeblack@google.com{ \ 414012853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(b) \ 414112853Sgabeblack@google.com sc_fxval tmp(a); \ 414212853Sgabeblack@google.com delete c.m_rep; \ 414312853Sgabeblack@google.com c.m_rep = sc_dt::fnc ## _scfx_rep(*tmp.m_rep, *b.m_rep); \ 414412853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(c) \ 414512853Sgabeblack@google.com} 414612853Sgabeblack@google.com 414712853Sgabeblack@google.com#define DEFN_BIN_FNC(fnc) \ 414812853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, const sc_fxnum_fast &) 414912853Sgabeblack@google.com 415012853Sgabeblack@google.comDEFN_BIN_FNC(mult) 415112853Sgabeblack@google.comDEFN_BIN_FNC(div) 415212853Sgabeblack@google.comDEFN_BIN_FNC(add) 415312853Sgabeblack@google.comDEFN_BIN_FNC(sub) 415412853Sgabeblack@google.com 415512853Sgabeblack@google.com#undef DEFN_BIN_FNC_T 415612853Sgabeblack@google.com#undef DEFN_BIN_FNC 415712853Sgabeblack@google.com 415812853Sgabeblack@google.com 415912853Sgabeblack@google.com// relational (including equality) operators 416012853Sgabeblack@google.com#define DEFN_REL_OP_T(op, ret, tp) \ 416112853Sgabeblack@google.cominline bool \ 416212853Sgabeblack@google.comoperator op (const sc_fxval &a, tp b) \ 416312853Sgabeblack@google.com{ \ 416412853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(a) \ 416512853Sgabeblack@google.com sc_fxval tmp(b); \ 416612853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*a.m_rep, *tmp.m_rep); \ 416712853Sgabeblack@google.com return (ret); \ 416812853Sgabeblack@google.com} \ 416912853Sgabeblack@google.com \ 417012853Sgabeblack@google.cominline bool \ 417112853Sgabeblack@google.comoperator op (tp a, const sc_fxval &b) \ 417212853Sgabeblack@google.com{ \ 417312853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(b) \ 417412853Sgabeblack@google.com sc_fxval tmp(a); \ 417512853Sgabeblack@google.com int result = sc_dt::cmp_scfx_rep(*tmp.m_rep, *b.m_rep); \ 417612853Sgabeblack@google.com return (ret); \ 417712853Sgabeblack@google.com} 417812853Sgabeblack@google.com 417912853Sgabeblack@google.com#define DEFN_REL_OP(op, ret) \ 418012853Sgabeblack@google.comDEFN_REL_OP_T(op, ret, const sc_fxnum_fast &) 418112853Sgabeblack@google.com 418212853Sgabeblack@google.comDEFN_REL_OP(<, result < 0) 418312853Sgabeblack@google.comDEFN_REL_OP(<=, result <= 0) 418412853Sgabeblack@google.comDEFN_REL_OP(>, result > 0 && result != 2) 418512853Sgabeblack@google.comDEFN_REL_OP(>=, result >= 0 && result != 2) 418612853Sgabeblack@google.comDEFN_REL_OP(==, result == 0) 418712853Sgabeblack@google.comDEFN_REL_OP(!=, result != 0) 418812853Sgabeblack@google.com 418912853Sgabeblack@google.com#undef DEFN_REL_OP_T 419012853Sgabeblack@google.com#undef DEFN_REL_OP 419112853Sgabeblack@google.com 419212853Sgabeblack@google.com// assignment operators 419312853Sgabeblack@google.cominline sc_fxval & 419412853Sgabeblack@google.comsc_fxval::operator = (const sc_fxnum &a) 419512853Sgabeblack@google.com{ 419612853Sgabeblack@google.com *m_rep = *a.get_rep(); 419712853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) 419812853Sgabeblack@google.com return *this; 419912853Sgabeblack@google.com} 420012853Sgabeblack@google.com 420112853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 420212853Sgabeblack@google.cominline sc_fxval & \ 420312853Sgabeblack@google.comsc_fxval::operator = (tp b) \ 420412853Sgabeblack@google.com{ \ 420512853Sgabeblack@google.com sc_fxval tmp(b); \ 420612853Sgabeblack@google.com *m_rep = *tmp.m_rep; \ 420712853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) \ 420812853Sgabeblack@google.com return *this; \ 420912853Sgabeblack@google.com} 421012853Sgabeblack@google.com 421112853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxnum_fast &) 421212853Sgabeblack@google.com 421312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 421412853Sgabeblack@google.com 421512853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, fnc, tp) \ 421612853Sgabeblack@google.cominline sc_fxval & \ 421712853Sgabeblack@google.comsc_fxval::operator op (tp b) \ 421812853Sgabeblack@google.com{ \ 421912853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(*this) \ 422012853Sgabeblack@google.com sc_fxval tmp(b); \ 422112853Sgabeblack@google.com scfx_rep *new_rep = sc_dt::fnc ## _scfx_rep(*m_rep, *tmp.m_rep); \ 422212853Sgabeblack@google.com delete m_rep; \ 422312853Sgabeblack@google.com m_rep = new_rep; \ 422412853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) \ 422512853Sgabeblack@google.com return *this; \ 422612853Sgabeblack@google.com} 422712853Sgabeblack@google.com 422812853Sgabeblack@google.com#define DEFN_ASN_OP(op, fnc) \ 422912853Sgabeblack@google.cominline sc_fxval & \ 423012853Sgabeblack@google.comsc_fxval::operator op (const sc_fxnum &b) \ 423112853Sgabeblack@google.com{ \ 423212853Sgabeblack@google.com SC_FXVAL_OBSERVER_READ_(*this) \ 423312853Sgabeblack@google.com scfx_rep *new_rep = sc_dt::fnc ## _scfx_rep(*m_rep, *b.get_rep()); \ 423412853Sgabeblack@google.com delete m_rep; \ 423512853Sgabeblack@google.com m_rep = new_rep; \ 423612853Sgabeblack@google.com SC_FXVAL_OBSERVER_WRITE_(*this) \ 423712853Sgabeblack@google.com return *this; \ 423812853Sgabeblack@google.com} \ 423912853Sgabeblack@google.com \ 424012853Sgabeblack@google.comDEFN_ASN_OP_T(op, fnc, const sc_fxnum_fast &) 424112853Sgabeblack@google.com 424212853Sgabeblack@google.comDEFN_ASN_OP(*=, mult) 424312853Sgabeblack@google.comDEFN_ASN_OP(/=, div) 424412853Sgabeblack@google.comDEFN_ASN_OP(+=, add) 424512853Sgabeblack@google.comDEFN_ASN_OP(-=, sub) 424612853Sgabeblack@google.com 424712853Sgabeblack@google.com#undef DEFN_ASN_OP_T 424812853Sgabeblack@google.com#undef DEFN_ASN_OP 424912853Sgabeblack@google.com 425012853Sgabeblack@google.com 425112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 425212853Sgabeblack@google.com// CLASS : sc_fxval_fast 425312853Sgabeblack@google.com// 425412853Sgabeblack@google.com// Fixed-point value types; limited precision. 425512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 425612853Sgabeblack@google.com 425712853Sgabeblack@google.com// public constructors 425812853Sgabeblack@google.com 425912853Sgabeblack@google.cominline 426012853Sgabeblack@google.comsc_fxval_fast::sc_fxval_fast(const sc_fxnum &a, 426112853Sgabeblack@google.com sc_fxval_fast_observer *observer_) : 426212853Sgabeblack@google.com m_val(a.to_double()), m_observer(observer_) 426312853Sgabeblack@google.com{ 426412853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_DEFAULT_ 426512853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(*this) 426612853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) 426712853Sgabeblack@google.com} 426812853Sgabeblack@google.com 426912853Sgabeblack@google.cominline sc_fxval_fast::sc_fxval_fast(const sc_fxnum_fast &a, 427012853Sgabeblack@google.com sc_fxval_fast_observer *observer_) : 427112853Sgabeblack@google.com m_val(a.get_val()), m_observer(observer_) 427212853Sgabeblack@google.com{ 427312853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_DEFAULT_ 427412853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(*this) 427512853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) 427612853Sgabeblack@google.com} 427712853Sgabeblack@google.com 427812853Sgabeblack@google.com 427912853Sgabeblack@google.com// binary functions 428012853Sgabeblack@google.com#define DEFN_BIN_FNC_T(fnc, op, tp) \ 428112853Sgabeblack@google.cominline void \ 428212853Sgabeblack@google.comfnc (sc_fxval_fast &c, const sc_fxval_fast &a, tp b) \ 428312853Sgabeblack@google.com{ \ 428412853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_READ_(a) \ 428512853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 428612853Sgabeblack@google.com c.m_val = a.m_val op tmp.m_val; \ 428712853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(c) \ 428812853Sgabeblack@google.com} \ 428912853Sgabeblack@google.com \ 429012853Sgabeblack@google.cominline void \ 429112853Sgabeblack@google.comfnc (sc_fxval_fast &c, tp a, const sc_fxval_fast &b) \ 429212853Sgabeblack@google.com{ \ 429312853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_READ_(b) \ 429412853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 429512853Sgabeblack@google.com c.m_val = tmp.m_val op b.m_val; \ 429612853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(c) \ 429712853Sgabeblack@google.com} 429812853Sgabeblack@google.com 429912853Sgabeblack@google.com#define DEFN_BIN_FNC(fnc, op) \ 430012853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_fxval &) \ 430112853Sgabeblack@google.comDEFN_BIN_FNC_T(fnc, op, const sc_fxnum &) 430212853Sgabeblack@google.com 430312853Sgabeblack@google.comDEFN_BIN_FNC(mult, *) 430412853Sgabeblack@google.comDEFN_BIN_FNC(div, /) 430512853Sgabeblack@google.comDEFN_BIN_FNC(add, +) 430612853Sgabeblack@google.comDEFN_BIN_FNC(sub, -) 430712853Sgabeblack@google.com 430812853Sgabeblack@google.com#undef DEFN_BIN_FNC_T 430912853Sgabeblack@google.com#undef DEFN_BIN_FNC 431012853Sgabeblack@google.com 431112853Sgabeblack@google.com 431212853Sgabeblack@google.com// assignment operators 431312853Sgabeblack@google.cominline sc_fxval_fast & 431412853Sgabeblack@google.comsc_fxval_fast::operator = (const sc_fxnum_fast &a) 431512853Sgabeblack@google.com{ 431612853Sgabeblack@google.com m_val = a.get_val(); 431712853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) 431812853Sgabeblack@google.com return *this; 431912853Sgabeblack@google.com} 432012853Sgabeblack@google.com 432112853Sgabeblack@google.com#define DEFN_ASN_OP_T(tp) \ 432212853Sgabeblack@google.cominline sc_fxval_fast & \ 432312853Sgabeblack@google.comsc_fxval_fast::operator = (tp a) \ 432412853Sgabeblack@google.com{ \ 432512853Sgabeblack@google.com sc_fxval_fast tmp(a); \ 432612853Sgabeblack@google.com m_val = tmp.m_val; \ 432712853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) \ 432812853Sgabeblack@google.com return *this; \ 432912853Sgabeblack@google.com} 433012853Sgabeblack@google.com 433112853Sgabeblack@google.comDEFN_ASN_OP_T(const sc_fxnum &) 433212853Sgabeblack@google.com 433312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 433412853Sgabeblack@google.com 433512853Sgabeblack@google.com#define DEFN_ASN_OP_T(op, tp) \ 433612853Sgabeblack@google.cominline sc_fxval_fast & \ 433712853Sgabeblack@google.comsc_fxval_fast::operator op (tp b) \ 433812853Sgabeblack@google.com{ \ 433912853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_READ_(*this) \ 434012853Sgabeblack@google.com sc_fxval_fast tmp(b); \ 434112853Sgabeblack@google.com m_val op tmp.m_val; \ 434212853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) \ 434312853Sgabeblack@google.com return *this; \ 434412853Sgabeblack@google.com} 434512853Sgabeblack@google.com 434612853Sgabeblack@google.com#define DEFN_ASN_OP(op) \ 434712853Sgabeblack@google.cominline sc_fxval_fast & \ 434812853Sgabeblack@google.comsc_fxval_fast::operator op (const sc_fxnum_fast &b) \ 434912853Sgabeblack@google.com{ \ 435012853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_READ_(*this) \ 435112853Sgabeblack@google.com m_val op b.get_val(); \ 435212853Sgabeblack@google.com SC_FXVAL_FAST_OBSERVER_WRITE_(*this) \ 435312853Sgabeblack@google.com return *this; \ 435412853Sgabeblack@google.com} \ 435512853Sgabeblack@google.com \ 435612853Sgabeblack@google.comDEFN_ASN_OP_T(op, const sc_fxnum &) 435712853Sgabeblack@google.com 435812853Sgabeblack@google.comDEFN_ASN_OP(*=) 435912853Sgabeblack@google.comDEFN_ASN_OP(/=) 436012853Sgabeblack@google.comDEFN_ASN_OP(+=) 436112853Sgabeblack@google.comDEFN_ASN_OP(-=) 436212853Sgabeblack@google.com 436312853Sgabeblack@google.com#undef DEFN_ASN_OP_T 436412853Sgabeblack@google.com#undef DEFN_ASN_OP 436512853Sgabeblack@google.com 436612853Sgabeblack@google.com} // namespace sc_dt 436712853Sgabeblack@google.com 436812853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_FX_SC_FXNUM_HH__ 4369