OpenASIP  2.0
HalfFloatWord.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2012 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 HalfFloatWord.hh
26  * @author Heikki Kultala (pjaaskel-no.spam-cs.tut.fi) 2012
27  * @note This file is used in compiled simulation. Keep dependencies *clean*
28  *
29  * This file contains definitions of float16 data type used by simulator.
30  */
31 
32 #ifndef HALF_FLOAT_WORD_HH
33 #define HALF_FLOAT_WORD_HH
34 
35 #include "BaseType.hh"
36 #include <stdint.h>
37 
38 /**
39  * Half-precision, IEE-754-2008 16-bit floating point number.
40  */
42 public:
43  operator float() const;
44 
45  // constructors
46  explicit HalfFloatWord(uint16_t binaryRep);
47  explicit HalfFloatWord(float value);
48  HalfFloatWord(const HalfFloatWord& hw);
49  HalfFloatWord();
50 
51  // calculations
52  HalfFloatWord operator+ (const HalfFloatWord& right) const;
53  HalfFloatWord operator- (const HalfFloatWord& right) const;
54  HalfFloatWord operator* (const HalfFloatWord& right) const;
55  HalfFloatWord operator/ (const HalfFloatWord& right) const;
56 
57  const HalfFloatWord& operator= (float value);
58  const HalfFloatWord& operator= (const HalfFloatWord& value);
59 
60  uint16_t getBinaryRep() const { return binaryRep_; }
61 
62  static uint16_t convertFloatToHalfWordRep(float value);
63  static float convertToFloat(HalfFloatWord value);
64 
65 private:
66  uint16_t binaryRep_;
67 };
68 
69 const Byte HLF_WORD_SIZE = 8 * sizeof(HalfFloatWord);
70 
71 #endif
BaseType.hh
HalfFloatWord::convertToFloat
static float convertToFloat(HalfFloatWord value)
Definition: HalfFloatWord.cc:99
HLF_WORD_SIZE
const Byte HLF_WORD_SIZE
Definition: HalfFloatWord.hh:69
HalfFloatWord
Definition: HalfFloatWord.hh:41
Byte
unsigned char Byte
Definition: BaseType.hh:116
HalfFloatWord::operator=
const HalfFloatWord & operator=(float value)
Definition: HalfFloatWord.cc:133
HalfFloatWord::operator*
HalfFloatWord operator*(const HalfFloatWord &right) const
Definition: HalfFloatWord.cc:190
HalfFloatWord::getBinaryRep
uint16_t getBinaryRep() const
Definition: HalfFloatWord.hh:60
HalfFloatWord::operator/
HalfFloatWord operator/(const HalfFloatWord &right) const
Definition: HalfFloatWord.cc:194
HalfFloatWord::convertFloatToHalfWordRep
static uint16_t convertFloatToHalfWordRep(float value)
Definition: HalfFloatWord.cc:56
HalfFloatWord::operator+
HalfFloatWord operator+(const HalfFloatWord &right) const
Definition: HalfFloatWord.cc:182
HalfFloatWord::binaryRep_
uint16_t binaryRep_
Definition: HalfFloatWord.hh:66
HalfFloatWord::operator-
HalfFloatWord operator-(const HalfFloatWord &right) const
Definition: HalfFloatWord.cc:186
HalfFloatWord::HalfFloatWord
HalfFloatWord()
Definition: HalfFloatWord.cc:53