fixed the type of the entity number
[libfirm] / ir / tv / IeeeCC754 / include / Bitstring.h
1 /*
2 ##########################################################################
3 #                                                                        #
4 # Program: IeeeCC754                                                     #
5 #                                                                        #
6 # Description:                                                           #
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            #
12 #                                                                        #
13 #         http:/* win-www.uia.ac.be/u/cant/ieeecc754.html                 # */
14 #                                                                        #
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.                                 #
22 #                                                                        #
23 #  Usage: see readme.usage                                               #
24 #                                                                        #
25 #  Responsible authors:                                                  #
26 #         Brigitte Verdonk                                               #
27 #         Annie Cuyt                                                     #
28 #                                                                        #
29 #  Contributors:                                                         #
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)                           #
35 #                                                                        #
36 #  Copyright (C) 2000  University of Antwerp                             #
37 #                                                                        #
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.                                     #
41 #                                                                        #
42 #  Contact:                                                              #
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                                           #
48 #                                                                        #
49 ##########################################################################
50
51 Filename:
52        $RCSfile$
53
54 Last updated:
55        $Date$
56
57 */
58
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 ************************************************************************** */
65
66 #ifndef _BITSTRING_H
67 #define _BITSTRING_H
68
69
70 #include <math.h>
71 #include <iostream.h>
72
73
74 #define NO_ERR               500
75 #define ERR_OUT_OF_BOUND    501
76
77
78
79 /*class definition*/
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]
84 \begin{center}
85 \includegraphics[totalheight=3cm]{InterneBitstr.eps}
86 \caption{Internal structure of Bitstring}
87 \end{center}
88 \end{figure}}
89 @author Bogo Johan*/
90
91
92
93 class Bitstring
94 {
95 protected:
96   /* * the bitstring */ */
97   unsigned long * bitstr;
98   /* * length of bitstring,          */ */
99   long length;
100   /* *  number of array elments */ */
101   long lengthBlock;
102   /* * number of bits in class T */ */
103   long lengthT;
104
105
106   /* *  returns a unsigned long  with the first res bits set. */ */
107   unsigned long GetPattern(unsigned long rest);
108
109   /** returns the first block of bitstr. It's only defined
110     to be used in PutByte so the xor-operator would work
111     properly.*/
112   unsigned long Convert();
113
114 public:
115   /* *  Constructor, creates an empty bitstring */ */
116   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 */ */
126   ~Bitstring();
127
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
136       */
137   virtual unsigned long Resize(unsigned long len);
138
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;
144
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);
150
151   /* Replace the bit value at position "bit" with the 1
152      @param   bit          position of the bit
153      @return  Previous bit value*/
154   int Set(long bit);
155
156   /** Replace the bit value at position "bit" with the 0
157     @param   bit     position of the bit
158     @return  Previous bit value   */
159   int Clear(long bit);
160
161   /** Clears the bitstring
162     @return  Cleared bitstring  */
163   Bitstring ClearBitString();
164
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;
169
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);
175
176
177   /** Increase the bitstring value by 1
178     @return  Carry after most significant bit*/
179   int Inc();
180
181   /** Decrease the bitstring value by 1
182     @return  \begin{tabular}{rcl}  1& -> &wrap around (negative)\\
183               0& -> &OK \end{tabular} */
184   int Dec();
185
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;
190
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);
195
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);
201
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;
208
209   /** Overloads the array operator. Returns/change block "n"
210     @param n   block number
211     @return  block "n" */
212   unsigned long& operator [](unsigned long n) const;
213
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 &copy);
218
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;
224
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;
229
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;
234
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;
239
240
241   /**Overloads the shift left operator. Shifts the bitstring "count"
242     bits to the left
243     @param count      number of shifts
244     @return  shifted bitstring  */
245   void operator <<(long count);
246
247   /**Overloads the shift right operator. Shifts the bitstring "count"
248     bits to the righ
249     @param  count   number of shifts
250     @return  shifted bitstring */
251   void operator >>(unsigned long count );
252
253
254   /**Overloads the bitwise and operator. Does a bitwise and with
255        "bitstr" and "bitst". Makes the size of bitst equal to the
256           bitstring.
257     @param bitst  second bitstring
258     @return  bitwised and -> *this \& bitst */
259   Bitstring operator &( const Bitstring &bitst);
260
261   /** Overloads the bitwise or operator. Does a bitwise or with
262           "bitstr" and "bitst". Makes the size of bitst equal to the
263           bitstring.
264     @param  bitst   second bitstring
265     @return  bitwised or -> *this $|$ bitst */
266   Bitstring operator |( const Bitstring &bitst);
267
268   /** Overloads the bitwise xor operator. Does a bitwise xor with
269           "bitstr" and "bitst". Makes the size of bitst equal to the
270           bitstring.
271     @param   bitst    second bitstring
272     @return  bitwised xor -> *this \^\ bitst  */
273   Bitstring operator ^( const Bitstring &bitst);
274
275   /** Overloads the bitwise not operator. Does a bitwise not with
276           "bitstr".
277     @return  bitwised not -> \cxxtilde(*this) */
278   Bitstring operator ~();
279
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);
286
287   /** Overloads the stream input operator. Converts the C-string to a
288     bitstring.
289     @param  ins   the input stream
290     @param  instr  the bitstring
291     @return  ins  */
292   friend istream& operator >> (istream& ins, Bitstring &instr);
293 };
294
295 /* @Include: Hex.h */
296
297 #endif