OpenASIP  2.0
MathTools.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file MathTools.hh
26  *
27  * Mathematical tools.
28  *
29  * Declarations.
30  *
31  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
32  *
33  */
34 
35 #ifndef TTA_MATH_TOOLS_HH
36 #define TTA_MATH_TOOLS_HH
37 
38 #include <utility>
39 
40 #include "BaseType.hh"
41 
42 class MathTools {
43 public:
44  static unsigned int bitLength(long unsigned int number);
45  static bool bitFieldsEquals(
46  unsigned enc1, unsigned pos1,
47  unsigned enc2, unsigned pos2,
48  unsigned width);
49  static long unsigned int concatenateBits(
50  long unsigned int msbBitField, unsigned msbWidth,
51  long unsigned int lsbBitField, unsigned lsbWidth);
52  static int ceil_log2(long unsigned int number);
53  template<typename NumberType>
54  static int ceil_div(NumberType dividee, NumberType diveder);
55  static int requiredBits(unsigned long int number);
56  static int requiredBits0Bit0(long unsigned int number);
57  static int requiredBitsSigned(SLongWord number);
58  static int requiredBitsSigned(int number);
59  static int requiredBitsSigned(UInt32 number);
60  static int requiredBitsSigned(ULongWord number);
61  static SLongWord signExtendTo(SLongWord value, int width);
62  static ULongWord zeroExtendTo(ULongWord value, int width);
63 
64  static SLongWord fastSignExtendTo(SLongWord value, int width);
65  static ULongWord fastZeroExtendTo(ULongWord value, int width);
66 
67  template<class IntegerType>
68  static void setBit(
69  IntegerType& bits, unsigned int index, bool bitState = true);
70 
71  static int random(int, int);
72  static unsigned int roundUpToPowerTwo(unsigned int number);
73  static int roundUpToPowerTwo(int number);
75  static bool isInPowerOfTwo(unsigned int number);
76  template<typename ResultNumberTypeS, typename ResultNumberTypeU=ResultNumberTypeS>
77  static std::pair<ResultNumberTypeS, ResultNumberTypeU> bitsToIntegerRange(
78  unsigned bitWidth, bool signExtending);
79  static bool bit(ULongWord integer, unsigned int index);
80 
82 };
83 
84 #include "MathTools.icc"
85 
86 #endif
MathTools::ceil_div
static int ceil_div(NumberType dividee, NumberType diveder)
MathTools::setBit
static void setBit(IntegerType &bits, unsigned int index, bool bitState=true)
BaseType.hh
MathTools
Definition: MathTools.hh:42
MathTools::concatenateBits
static long unsigned int concatenateBits(long unsigned int msbBitField, unsigned msbWidth, long unsigned int lsbBitField, unsigned lsbWidth)
Definition: MathTools.cc:47
MathTools::fastSignExtendTo
static SLongWord fastSignExtendTo(SLongWord value, int width)
MathTools::ceil_log2
static int ceil_log2(long unsigned int number)
MathTools::random
static int random(int, int)
MathTools.icc
MathTools::zeroExtendTo
static ULongWord zeroExtendTo(ULongWord value, int width)
MathTools::fastZeroExtendTo
static ULongWord fastZeroExtendTo(ULongWord value, int width)
MathTools::roundDownToPowerTwo
static SLongWord roundDownToPowerTwo(SLongWord number)
MathTools::requiredBits
static int requiredBits(unsigned long int number)
MathTools::bit
static bool bit(ULongWord integer, unsigned int index)
UInt32
Word UInt32
Definition: BaseType.hh:134
MathTools::isInPowerOfTwo
static bool isInPowerOfTwo(unsigned int number)
MathTools::bitLength
static unsigned int bitLength(long unsigned int number)
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
MathTools::roundUpToPowerTwo
static unsigned int roundUpToPowerTwo(unsigned int number)
MathTools::signExtendTo
static SLongWord signExtendTo(SLongWord value, int width)
MathTools::requiredBits0Bit0
static int requiredBits0Bit0(long unsigned int number)
MathTools::bitsToIntegerRange
static std::pair< ResultNumberTypeS, ResultNumberTypeU > bitsToIntegerRange(unsigned bitWidth, bool signExtending)
SLongWord
long SLongWord
Definition: BaseType.hh:52
MathTools::requiredBitsSigned
static int requiredBitsSigned(SLongWord number)
MathTools::bitFieldsEquals
static bool bitFieldsEquals(unsigned enc1, unsigned pos1, unsigned enc2, unsigned pos2, unsigned width)