2 ##########################################################################
7 # IeeeCC754 or IEEE 754 Compliance Checker is a precision and range #
8 # independent tool to test whether an implementation of #
9 # floating-point arithmetic (in hardware or software) is compliant #
10 # with the principles of the IEEE 754-854 floating-point standards. #
11 # You can find out more about the testing tool IeeeCC754 at #
13 # http://win-www.uia.ac.be/u/cant/ieeecc754.html #
15 # This tool is in parts based on and greatly benefited from the #
16 # the program FPTEST developed by Jerome Coonen. For a full #
17 # description of the extensions to FPTEST and a reference to #
18 # the original Coonen program, please refer to the URL given above. #
19 # For the options available with the program IeeeCC754 and its #
20 # compatibility with David Hough's hexadecimal UCB format, we #
21 # also refer to the file readme.usage. #
23 # Usage: see readme.usage #
25 # Responsible authors: #
30 # Johan Bogo (1998-1999) #
31 # Tim Gevers (10-12/2000) #
32 # Debby Ooms (1996-1997) #
33 # Geert Vermuyten (1996-1997) #
34 # Dennis Verschaeren (09/1996-06/2000) #
36 # Copyright (C) 2000 University of Antwerp #
38 # This program can be obtained from the authors, free, but WITHOUT ANY #
39 # WARRANTY; without even the implied warranty of MERCHANTABILITY or #
40 # FITNESS FOR A PARTICULAR PURPOSE. #
43 # Brigitte.Verdonk@uia.ua.ac.be #
44 # Department of Mathematics and Computer Science #
45 # University of Antwerp (UIA) #
46 # Universiteitsplein 1 #
47 # B2610 Antwerp, BELGIUM #
49 ##########################################################################
59 /***************************************************************************
60 * This is a class definition for bitstrings. The bitstring is a array of type
61 * (class T). The use of templates is to specify the block size. Only use
62 * unsigned types to define the class T, because else the shift operations
63 * (especially right shift) won't work correct.
64 ************************************************************************** */
75 #define ERR_OUT_OF_BOUND 501
80 /**This class has been created to simplify the manipulation of bits over some array of integers (unsigned longs).
81 The internal structure of the bitstring resembles a little endian structure,
82 because this concept simplifies the resizing of the bitstring.
83 \TEX{\begin{figure}[h]
85 \includegraphics[totalheight=3cm]{InterneBitstr.eps}
86 \caption{Internal structure of Bitstring}
96 /* * the bitstring */ */
97 unsigned long * bitstr;
98 /* * length of bitstring, */ */
100 /* * number of array elments */ */
102 /* * number of bits in class T */ */
106 /* * returns a unsigned long with the first res bits set. */ */
107 unsigned long GetPattern(unsigned long rest);
109 /** returns the first block of bitstr. It's only defined
110 to be used in PutByte so the xor-operator would work
112 unsigned long Convert();
115 /* * Constructor, creates an empty bitstring */ */
117 /**Constructor, creates a bitstring of size size.
118 @param size the default size*/
119 Bitstring(unsigned long size);
120 /**Constructor,initiate the bitstring with the str as input
121 @param str the default value for the bitstring */
122 Bitstring(char * str);
123 /* * Copy constructor. */ */
124 Bitstring(const Bitstring& copy);
125 /* * Destructor */ */
128 /**Get the length of the bitstring.
129 @return length of the bitstring*/
130 virtual unsigned long Length() const;
131 /**Change the length of the bitstring to "len". If "len" is
132 larger then the length, the bitstring is appended with 0, else
133 the bitstring is truncated to the new length "len"
134 @param len the new length of the bitstring
135 @return previous length
137 virtual unsigned long Resize(unsigned long len);
139 /**Get the bit value at position "bit"
140 @param bit position of the bit
141 @return the bit value \\ \begin{tabular}{rcl} 0 <= "bit" < length &->& The bit value\\
142 else & -> &0\end{tabular} */
143 int GetBit(long bit) const;
145 /**Replace the bit value at position "bit" with the new "bitvalue"
146 @param bit posisition of the bit
147 @param bitvalue new value
148 @return Previous bit value*/
149 int PutBit(unsigned long bit,unsigned int bitvalue);
151 /* Replace the bit value at position "bit" with the 1
152 @param bit position of the bit
153 @return Previous bit value*/
156 /** Replace the bit value at position "bit" with the 0
157 @param bit position of the bit
158 @return Previous bit value */
161 /** Clears the bitstring
162 @return Cleared bitstring */
163 Bitstring ClearBitString();
165 /**Get the byte value at position "byte"
166 @param byte position of the byte
167 @return The byte value */
168 void GetByte(unsigned long byte,Bitstring sub) const;
170 /** Replace the byte value at position "byte" with the new "bytevalue"
171 @param byte position of the byte
172 @param bytevalue new value
173 @return: void /* Previous byte value */ */
174 void PutByte(unsigned long byte,Bitstring bytevalue);
177 /** Increase the bitstring value by 1
178 @return Carry after most significant bit*/
181 /** Decrease the bitstring value by 1
182 @return \begin{tabular}{rcl} 1& -> &wrap around (negative)\\
183 0& -> &OK \end{tabular} */
186 /**Converts a bitstring to a C-string
187 @return the converted bitstring\\ \begin{tabular}{ccl} length >0 & -> & The C-string\\
188 else & -> & "Bitstring is empty" \end{tabular}*/
189 virtual void BitstrToString(char str[256]) const;
191 /** Converts a C-string to a bitstring
192 @param str the C-string to be converted
193 @return converted bitstring */
194 virtual void StringToBitstr(char *str);
196 /** Puts bitstring *this in front of b2 -> so the first bit of b2
197 becomes the first bit of *thisb2
198 @param b2 second bitstring
199 @return *this -> *thisb2 */
200 void Concat(const Bitstring &b2);
202 /* Returns the substring defined by position "begin" to "count"
203 @param begin the begining of the substring
204 @param count the length of the substring
205 @return substring from bitstring */
206 /* Bitstring SubBitstring (unsigned long begin, unsigned long count) const; */
207 void SubBitstring(unsigned long begin, Bitstring &sub) const;
209 /** Overloads the array operator. Returns/change block "n"
210 @param n block number
212 unsigned long& operator [](unsigned long n) const;
214 /**Overloads the assign operator. Makes the bistring equal to "copy"
215 @param copy the new bitstring
216 @return The changed bitstring */
217 Bitstring& operator = (const Bitstring ©);
219 /** Overloads the equal operator.
220 @param b second bitstring
221 @return \begin{tabular}{lcl} equal & -> &1\\
222 not equal &->& 0 \end{tabular}*/
223 int operator == (const Bitstring & b) const;
225 /** Overloads the not equal operator.
226 @return \begin{tabular}{lcl} not equal& ->& 1\\
227 equal & ->& 0 \end{tabular}*/
228 int operator != (const Bitstring &b) const;
230 /** Overloads the greater than operator.
231 @return \begin{tabular}{lcl} greater & ->& 1\\
232 not greater & ->& 0\end{tabular} */
233 int operator > (const Bitstring &b) const;
235 /** Overloads the smaller than operator.
236 @return \begin{tabular}{lcl} smaller& ->& 1\\
237 not smaller & ->& 0\end{tabular} */
238 int operator < (const Bitstring &b) const;
241 /**Overloads the shift left operator. Shifts the bitstring "count"
243 @param count number of shifts
244 @return shifted bitstring */
245 void operator <<(long count);
247 /**Overloads the shift right operator. Shifts the bitstring "count"
249 @param count number of shifts
250 @return shifted bitstring */
251 void operator >>(unsigned long count );
254 /**Overloads the bitwise and operator. Does a bitwise and with
255 "bitstr" and "bitst". Makes the size of bitst equal to the
257 @param bitst second bitstring
258 @return bitwised and -> *this \& bitst */
259 Bitstring operator &( const Bitstring &bitst);
261 /** Overloads the bitwise or operator. Does a bitwise or with
262 "bitstr" and "bitst". Makes the size of bitst equal to the
264 @param bitst second bitstring
265 @return bitwised or -> *this $|$ bitst */
266 Bitstring operator |( const Bitstring &bitst);
268 /** Overloads the bitwise xor operator. Does a bitwise xor with
269 "bitstr" and "bitst". Makes the size of bitst equal to the
271 @param bitst second bitstring
272 @return bitwised xor -> *this \^\ bitst */
273 Bitstring operator ^( const Bitstring &bitst);
275 /** Overloads the bitwise not operator. Does a bitwise not with
277 @return bitwised not -> \cxxtilde(*this) */
278 Bitstring operator ~();
280 /** Overloads the stream output operator. Converts the bitstring to a
281 C-string and returns it to "ostream".
282 @param outs the ouput stream
283 @param outstr the bitstring
284 @return outs -> converted bitstring*/
285 friend ostream& operator << (ostream& outs,const Bitstring &outstr);
287 /** Overloads the stream input operator. Converts the C-string to a
289 @param ins the input stream
290 @param instr the bitstring
292 friend istream& operator >> (istream& ins, Bitstring &instr);
295 /* @Include: Hex.h */