311e0cfdb6a7eae9ca3c18e899d1216dad5bf3c7
[libfirm] / include / libfirm / tv.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Representation of and static computations on target machine
23  *           values.
24  * @date     2003
25  * @author   Mathias Heil
26  * @version  $Id$
27  * @brief
28  *   Tarvals represent target machine values.  They are typed by modes.
29  *   Tarvals only represent values of mode_sort:
30  *    - int_number,
31  *    - float_number,
32  *    - boolean,
33  *    - reference,
34  *    - character
35  *
36  *   In case of references the module accepts an entity to represent the
37  *   value.
38  *   Furthermore, computations and conversions of these values can
39  *   be performed.
40  *
41  * HISTORY
42  *    The original tv module originated in the fiasco compiler written ...
43  *    This is the new version, described in the tech report 1999-14 by ...
44  *
45  * @sa
46  *    Techreport 1999-14
47  *    irmode.h for the modes definitions
48  *    irnode.h for the pn_Cmp table
49  */
50 #ifndef FIRM_TV_TV_H
51 #define FIRM_TV_TV_H
52
53 #include "firm_types.h"
54 #include "irnode.h"
55
56 /* ************************ Constructors for tarvals ************************ */
57
58 /**
59  * Constructor function for new tarvals.
60  *
61  * @param str   The string representing the target value
62  * @param len   The length of the string
63  * @param mode  The mode requested for the result tarval
64  *
65  * This function creates a new tarval representing the value represented
66  * by a CString, aka char array. If a tarval representing this value already
67  * exists, this tarval is returned instead of a new one. So tarvals are
68  * directly comparable since their representation is unique.
69  *
70  * This function accepts the following strings:
71  *
72  * if mode is int_number:
73  *  - 0(x|X)[0-9a-fA-F]+ (hexadecimal representation)
74  *  - 0[0-7]*            (octal representation)
75  *  - (+|-)?[1-9][0-9]*  (decimal representation)
76  *
77  * if mode if float_number:
78  *  - (+|-)?(decimal int) (. (decimal int))? ((e|E)(+|-)?(decimal int))?
79  *
80  * if mode is boolean: true, True, TRUE ... False... 0, 1,
81  *
82  * if mode is reference: hexadecimal of decimal number as int
83  *
84  * if mode is character: hex or dec
85  *
86  * Leading and/or trailing spaces are ignored
87  *
88  * @return
89  *   A tarval of proper type representing the requested value is returned.
90  *   Tarvals are unique, so for any value/mode pair at most one tarval will
91  *   exist, which will be returned upon further requests with an identical
92  *   value/mode pair.
93  *
94  * @note
95  *   If the string is not representable in the given mode an assertion is
96  *   thrown in assert build.
97  *
98  * @sa
99  *   irmode.h for predefined modes
100  *   new_tarval_from_long()
101  *   new_tarval_from_double()
102  */
103 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode);
104
105 /**
106  * Constructor function for new tarvals
107  *
108  * @param l     The long representing the value
109  * @param mode  The mode requested for the result tarval
110  *
111  * This function creates a new tarval representing the value represented
112  * by a long integer. If a tarval representing this value already exists,
113  * this tarval is returned instead of a new one. So tarvals are directly
114  * comparable since their representation is unique.
115  *
116  * @return
117  *   A tarval of proper type representing the requested value is returned.
118  *   Tarvals are unique, so for any value/mode pair at most one tarval will
119  *   exist, which will be returned upon further requests with an identical
120  *   value/mode pair.
121  *
122  * @note
123  *   If the long is not representable in the given mode an assertion is
124  *   thrown in assert build.
125  *
126  * @sa
127  *   irmode.h for predefined modes
128  *   new_tarval_from_str()
129  *   new_tarval_from_double()
130  *
131  */
132 tarval *new_tarval_from_long(long l, ir_mode *mode);
133
134 /** Return value as long if possible.
135  *
136  * This returns a long int with the value represented value, or
137  * gibberish, depending on the size of long int and the size of the
138  * stored value. It works for e.g. 1 as mode_Ls, but might not work for
139  * get_mode_max(mode_Ls).
140  * This will overflow silently, so use only if you know what
141  * you are doing! (better check with tarval_is_long()...)
142  * Works only for int modes, even not for character modes!
143  */
144 long get_tarval_long(tarval *tv);
145
146 /**
147  * This validates if get_tarval_long() will return a satisfying
148  * result. I.e. if tv is an int_number and between min, max
149  * of long int (signed!)
150  *
151  * @param tv    the tarval
152  */
153 int tarval_is_long(tarval *tv);
154
155 /**
156  * Constructor function for new tarvals.
157  *
158  * @param d     The (long) double representing the value
159  * @param mode  The mode requested for the result tarval
160  *
161  * This function creates a new tarval representing the value represented
162  * by a (long) double. If a tarval representing this value already exists,
163  * this tarval is returned instead of a new one. So tarvals are directly
164  * comparable since their representation is unique.
165  * Only modes of sort float_number can be constructed this way.
166  *
167  * @return
168  *   A tarval of proper type representing the requested value is returned.
169  *   Tarvals are unique, so for any value/mode pair at most one tarval will
170  *   exist, which will be returned upon further requests with an identical
171  *   value/mode pair.
172  *
173  * @note
174  *   If the (long) double is not representable in the given mode an assertion
175  *   is thrown. This will happen for any mode not of sort float_number.
176  *
177  * @sa
178  *   irmode.h for predefined values
179  *   new_tarval_from_str()
180  *   new_tarval_from_long()
181  */
182 tarval *new_tarval_from_double(long double d, ir_mode *mode);
183
184 /**
185  * This returns a double with the value represented value, or
186  * gibberish, depending on the size of double and the size of the
187  * stored value.
188  * This will overflow silently, so use only if you know what
189  * you are doing! (better check with tarval_is_long...)
190  *
191  * @param tv    the tarval
192  */
193 long double get_tarval_double(tarval *tv);
194
195 /**
196  * This validates if tarval_to_double() will return a satisfying
197  * result. I.e. if tv is an float_number and between min, max
198  * of double
199  *
200  * @param tv    the tarval
201  */
202 int tarval_is_double(tarval *tv);
203
204
205 /** ********** Access routines for tarval fields ********** **/
206
207 /*
208  * NAME
209  *   get_tarval_mode
210  *   get_tarval_ ...
211  *
212  * SYNOPSIS
213  *   ir_mode *get_tarval_mode(tarval *tv)
214  *   ...
215  *
216  * DESCRIPTION
217  *    These are access function for tarval struct members. It is encouraged
218  *   to use them instead of direct access to the struct fields.
219  *
220  * PARAMETERS
221  *   tv - The tarval to access fields of
222  *
223  * RESULT
224  *   get_tv_mode: The mode of the tarval
225  *
226  * SEE ALSO
227  *   the struct tarval
228  */
229
230 /**
231  * Returns the mode of the tarval.
232  *
233  * @param tv    the tarval
234  */
235 ir_mode *get_tarval_mode(const tarval *tv);
236
237 /** Returns the contents of the 'link' field of the tarval */
238 /* void *get_tarval_link (tarval*); */
239
240 /* Testing properties of the represented values */
241
242 /**
243  * Returns 1 if tv is negative
244  *
245  * @param tv    the tarval
246  */
247 int tarval_is_negative(tarval *tv);
248
249 /**
250  * Returns 1 if tv is null
251  *
252  * @param tv    the tarval
253  */
254 int tarval_is_null(tarval *tv);
255
256 /**
257  * Returns 1 if tv is the "one"
258  *
259  * @param tv    the tarval
260  */
261 int tarval_is_one(tarval *tv);
262
263 /**
264  * Returns 1 if tv is the "minus one"
265  *
266  * @param tv    the tarval
267  */
268 int tarval_is_minus_one(tarval *tv);
269
270 /**
271  * returns non-zero if all bits in the tarval are set
272  */
273 int tarval_is_all_one(tarval *tv);
274
275 /**
276  * Return non-zero if the tarval is a constant (ie. NOT
277  * a reserved tarval like bad, undef, reachable etc.)
278  */
279 int tarval_is_constant(tarval *tv);
280
281 /** The 'bad' tarval. */
282 extern tarval *tarval_bad;
283 /** Returns the 'bad' tarval. */
284 tarval *get_tarval_bad(void);
285
286 /** The 'undefined' tarval. */
287 extern tarval *tarval_undefined;
288 /** Returns the 'undefined' tarval. */
289 tarval *get_tarval_undefined(void);
290
291 /** The mode_b tarval 'false'. */
292 extern tarval *tarval_b_false;
293 /** Returns the mode_b tarval 'false'. */
294 tarval *get_tarval_b_false(void);
295
296 /** The mode_b tarval 'true'. */
297 extern tarval *tarval_b_true;
298 /** Returns the mode_b tarval 'true'. */
299 tarval *get_tarval_b_true(void);
300
301 /** The mode_X tarval 'unreachable'. */
302 extern tarval *tarval_unreachable;
303 /** Returns the mode_X tarval 'unreachable'. */
304 tarval *get_tarval_unreachable(void);
305
306 /** The mode_X tarval 'reachable'. */
307 extern tarval *tarval_reachable;
308 /** Returns the mode_X tarval 'reachable'. */
309 tarval *get_tarval_reachable(void);
310
311 /** The 'top' tarval. This is just another name for the 'undefined' tarval. */
312 #define tarval_top          tarval_undefined
313 /** Returns the 'top' tarval. */
314 #define get_tarval_top()    get_tarval_undefined()
315
316 /** The 'bottom' tarval. This is just another name for the 'bad' tarval. */
317 #define tarval_bottom       tarval_bad
318 /** Returns the 'bottom' tarval. */
319 #define get_tarval_bottom() get_tarval_bad()
320
321 /* These functions calculate and return a tarval representing the requested
322  * value.
323  * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
324  * functions, but these are stored on initialization of the irmode module and
325  * therefore the irmode functions should be preferred to the functions below. */
326
327 /** Returns the maximum value of a given mode. */
328 tarval *get_tarval_max(ir_mode *mode);
329
330 /** Returns the minimum value of a given mode. */
331 tarval *get_tarval_min(ir_mode *mode);
332
333 /** Returns the 0 value (additive neutral) of a given mode.
334     For reference modes, the NULL value is returned (old tarval_P_void) */
335 tarval *get_tarval_null(ir_mode *mode);
336
337 /** Returns the 1 value (multiplicative neutral) of a given mode. */
338 tarval *get_tarval_one(ir_mode *mode);
339
340 /** Returns the -1 value (multiplicative neutral) of a given mode.
341  *  Returns tarval bad for unsigned modes */
342 tarval *get_tarval_minus_one(ir_mode *mode);
343
344 /** returns the value where all bits are 1 of a given mode.
345  * returns tarval_bad for float modes */
346 tarval *get_tarval_all_one(ir_mode *mode);
347
348 /** Return quite nan for float_number modes. */
349 tarval *get_tarval_nan(ir_mode *mode);
350
351 /** Return +inf for float_number modes. */
352 tarval *get_tarval_plus_inf(ir_mode *mode);
353
354 /** Return -inf for float_number modes. */
355 tarval *get_tarval_minus_inf(ir_mode *mode);
356
357 /* ******************** Arithmetic operations on tarvals ******************** */
358
359 typedef enum _tarval_int_overflow_mode_t {
360         TV_OVERFLOW_BAD,      /**< tarval module will return tarval_bad if a overflow occurs */
361         TV_OVERFLOW_WRAP,     /**< tarval module will overflow will be ignored, wrap around occurs */
362         TV_OVERFLOW_SATURATE  /**< tarval module will saturate the overflow */
363 } tarval_int_overflow_mode_t;
364
365 /**
366  * Sets the overflow mode for integer operations.
367  *
368  * @param ov_mode  one of teh overflow modes
369  */
370 void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode);
371
372 /**
373  * Get the overflow mode for integer operations.
374  */
375 tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void);
376
377 /**
378  * Compares two tarvals
379  *
380  * Compare a with b and return a pn_Cmp describing the relation
381  * between a and b.  This is either pn_Cmp_Uo, pn_Cmp_Lt, pn_Cmp_Eq, pn_Cmp_Gt,
382  * or pn_Cmp_False if a or b are symbolic pointers which can not be compared at all.
383  *
384  * @param a   the first tarval to be compared
385  * @param b   the second tarval to be compared
386  *
387  * @return
388  *   The pn_Cmp best describing the relation between a and b is returned.
389  *   This means the mode with the least bits set is returned, e.g. if the
390  *   tarvals are equal the pn_Cmp 'pn_Cmp_Eq' is returned, not 'pn_Cmp_Ge' which
391  *   indicates 'greater or equal'
392  *
393  * @sa
394  *    irnode.h for the definition of pn_Cmp
395  */
396 pn_Cmp tarval_cmp(tarval *a, tarval *b);
397
398 /**
399  * Converts a tarval to another mode.
400  *
401  * Convert tarval 'src' to mode 'mode', this will succeed if and only if mode
402  * 'mode' is wider than the mode of src, as defined in the firm documentation
403  * and as returned by the function mode_is_smaller defined in irmode.h.
404  *
405  * @param src    The tarval to convert
406  * @param mode   Tho mode to convert to
407  *
408  * @return
409  *   If a tarval of mode 'mode' with the result of the conversion of the 'src'
410  *   tarvals value already exists, it will be returned, else a new tarval is
411  *   constructed and returned
412  *
413  * @note
414  *    Illegal convertions will trigger a panic
415  *
416  * @sa
417  *    FIRM documentation for conversion rules
418  *    mode_is_smaller defined in irmode.h
419  */
420 tarval *tarval_convert_to(tarval *src, ir_mode *mode);
421
422 /*
423  * These function implement basic computations representable as opcodes
424  * in FIRM nodes.
425  *
426  * PARAMETERS
427  *    tarval_neg:
428  *    traval_abs:
429  *      a - the tarval to operate on
430  *
431  *    all others:
432  *      a - the first operand tarval
433  *      b - the second operand tarval
434  *
435  * RESULT
436  *    If necessary a new tarval is constructed for the resulting value,
437  *   or the one already carrying the computation result is retrieved and
438  *   returned as result.
439  *
440  * NOTES
441  *   The order the arguments are given in is important, imagine postfix
442  *   notation.
443  *   Illegal operations will trigger an assertion.
444  *   The sort member of the struct mode defines which operations are valid
445  */
446
447 /**
448  * Bitwise Negation of a tarval.
449  *
450  * @param a  the first tarval
451  *
452  * @return ~a or tarval_bad
453  */
454 tarval *tarval_not(tarval *a);
455
456 /**
457  * Arithmetic Negation of a tarval.
458  *
459  * @param a  the first tarval
460  *
461  * @return -a or tarval_bad
462  */
463 tarval *tarval_neg(tarval *a);
464
465 /**
466  * Addition of two tarvals.
467  *
468  * @param a  the first tarval
469  * @param b  the second tarval
470  *
471  * @return a + b or tarval_bad
472  */
473 tarval *tarval_add(tarval *a, tarval *b);
474
475 /**
476  * Subtraction from a tarval.
477  *
478  * @param a         the first tarval
479  * @param b         the second tarval
480  * @param dst_mode  the mode of the result, needed for mode_P - mode_P, else NULL
481  *
482  * @return a - b or tarval_bad
483  */
484 tarval *tarval_sub(tarval *a, tarval *b, ir_mode *dst_mode);
485
486 /**
487  * Multiplication of tarvals.
488  *
489  * @param a  the first tarval
490  * @param b  the second tarval
491  *
492  * @return a * b or tarval_bad
493  */
494 tarval *tarval_mul(tarval *a, tarval *b);
495
496 /**
497  * Division of two floating point tarvals.
498  *
499  * @param a  the first tarval
500  * @param b  the second tarval
501  *
502  * @return a / b or tarval_bad
503  */
504 tarval *tarval_quo(tarval *a, tarval *b);
505
506 /**
507  * Integer division of two tarvals.
508  *
509  * @param a  the first tarval
510  * @param b  the second tarval
511  *
512  * @return a / b or tarval_bad
513  */
514 tarval *tarval_div(tarval *a, tarval *b);
515
516 /**
517  * Remainder of integer division.
518  *
519  * @param a  the first tarval
520  * @param b  the second tarval
521  *
522  * @return a % b or tarval_bad
523  */
524 tarval *tarval_mod(tarval *a, tarval *b);
525
526 /**
527  * Integer division AND remainder.
528  *
529  * @param a        the first tarval
530  * @param b        the second tarval
531  * @param mod_res  after return, contains the remainder result, a % b or tarval_bad
532  *
533  * @return a / b or tarval_bad
534  */
535 tarval *tarval_divmod(tarval *a, tarval *b, tarval **mod_res);
536
537 /**
538  * Absolute value of a tarval.
539  *
540  * @param a  the first tarval
541  *
542  * @return |a| or tarval_bad
543  */
544 tarval *tarval_abs(tarval *a);
545
546 /**
547  * Bitwise and of two integer tarvals.
548  *
549  * @param a  the first tarval
550  * @param b  the second tarval
551  *
552  * @return a & b or tarval_bad
553  */
554 tarval *tarval_and(tarval *a, tarval *b);
555
556 /**
557  * Bitwise or of two integer tarvals.
558  *
559  * @param a  the first tarval
560  * @param b  the second tarval
561  *
562  * @return a | b or tarval_bad
563  */
564 tarval *tarval_or(tarval *a, tarval *b);
565
566 /**
567  * Bitwise exclusive or of two integer tarvals.
568  *
569  * @param a  the first tarval
570  * @param b  the second tarval
571  *
572  * @return a ^ b or tarval_bad
573  */
574 tarval *tarval_eor(tarval *a, tarval *b);
575
576 /**
577  * Logical Left shift.
578  *
579  * @param a  the first tarval
580  * @param b  the second tarval
581  *
582  * @return a << b or tarval_bad
583  */
584 tarval *tarval_shl(tarval *a, tarval *b);
585
586 /**
587  * Unsigned (logical) right shift.
588  *
589  * @param a  the first tarval
590  * @param b  the second tarval
591  *
592  * @return a >>u b or tarval_bad
593  */
594 tarval *tarval_shr(tarval *a, tarval *b);
595
596 /**
597  * Signed (arithmetic) right shift.
598  *
599  * @param a  the first tarval
600  * @param b  the second tarval
601  *
602  * @return a >>s b or tarval_bad
603  */
604 tarval *tarval_shrs(tarval *a, tarval *b);
605
606 /**
607  * Rotation to left.
608  *
609  * @param a  the first tarval
610  * @param b  the second tarval
611  *
612  * @return a \<\<L\>\> b or tarval_bad
613  */
614 tarval *tarval_rotl(tarval *a, tarval *b);
615
616 /**
617  * Returns the carry flag of the last operation.
618  */
619 int tarval_carry(void);
620
621 /* *********** Output of tarvals *********** */
622
623 /**
624  * The output mode for tarval values.
625  *
626  * Some modes allow more that one representation, for instance integers
627  * can be represented hex or decimal. Of course it would be enough to have
628  * one and let every backend convert it into the 'right' one.
629  * However, we can do this in the tarval much simpler...
630  */
631 typedef enum {
632         TVO_NATIVE,       /**< the default output mode, depends on the mode */
633         TVO_HEX,          /**< use hex representation, always possible */
634         TVO_DECIMAL,      /**< use decimal representation */
635         TVO_OCTAL,        /**< use octal representation */
636         TVO_BINARY,       /**< use binary representation */
637         TVO_FLOAT,        /**< use floating point representation (i.e 1.342e-2)*/
638         TVO_HEXFLOAT      /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/
639 } tv_output_mode;
640
641 /**
642  * This structure contains helper information to format the output
643  * of a tarval of a mode.
644  */
645 typedef struct tarval_mode_info {
646         tv_output_mode mode_output;  /**< if != TVO_NATIVE select a special mode */
647         const char *mode_prefix;     /**< if set, this prefix will be printed
648                                           before a value of this mode */
649         const char *mode_suffix;     /**< if set, this suffix will be printed
650                                           after a value of this mode */
651 } tarval_mode_info;
652
653 /**
654  * Specify the output options of one mode.
655  *
656  * This functions stores the mode info, so DO NOT DESTROY it.
657  *
658  * @param mode      a ir_mode that should be associated
659  * @param modeinfo  the output format info
660  *
661  * @return zero on success.
662  */
663 int  set_tarval_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo);
664
665 /**
666  * Returns the output options of one mode.
667  *
668  * This functions returns the mode info of a given mode.
669  *
670  * @param mode      a ir_mode that should be associated
671  *
672  * @return the output option
673  */
674 const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode);
675
676 /**
677  * Returns Bit representation of a tarval value, as string of '0' and '1'
678  *
679  * @param tv   The tarval
680  *
681  * This function returns a printable bit representation of any value
682  * stored as tarval. This representation is a null terminated C string.
683  *
684  * @return
685  *   As usual in C a pointer to a char is returned. The length of the
686  *   returned string if fixed, just read as many chars as the mode defines
687  *   as size.
688  *
689  * @note
690  *   The string is allocated using malloc() and is free()ed on the next call
691  *   of this function.
692  *   The string consists of the ASCII characters '0' and '1' and is
693  *   null terminated
694  *
695  * @sa
696  *    irmode.h for the definition of the ir_mode struct
697  *    the size member of aforementioned struct
698  */
699 char *get_tarval_bitpattern(tarval *tv);
700
701 /**
702  * Returns the bitpattern of the bytes_ofs byte.
703  *
704  * This function succeeds even if the mode of the tarval uses lesser bits
705  * than requested, in that case the bitpattern is filled with zero bits.
706  *
707  * To query a 32bit value the following code can be used:
708  *
709  * val0 = tarval_sub_bits(tv, 0);
710  * val1 = tarval_sub_bits(tv, 1);
711  * val2 = tarval_sub_bits(tv, 2);
712  * val3 = tarval_sub_bits(tv, 3);
713  *
714  * Because this is the bit representation of the target machine, only the following
715  * operations are legal on the result:
716  *
717  * - concatenation (endian dependence MUST be handled by the CALLER)
718  * - bitwise logical operations to select/mask bits
719  *
720  * @param tv        the tarval
721  * @param byte_ofs  the byte offset
722  *
723  * @note
724  *   The result of this function is undefined if the mode is neither integer nor float.
725  */
726 unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs);
727
728 /**
729  * Returns non-zero if a given (integer) tarval has only one single bit
730  * set.
731  *
732  * @param tv    the tarval
733  */
734 int tarval_is_single_bit(tarval *tv);
735
736 /**
737  * Output a tarval to a string buffer.
738  *
739  * @param buf     the output buffer
740  * @param buflen  the length of the buffer
741  * @param tv      the tarval
742  */
743 int tarval_snprintf(char *buf, size_t buflen, tarval *tv);
744
745 /**
746  * Output a tarval to stdio.
747  *
748  * @param tv    the tarval
749  */
750 int tarval_printf(tarval *tv);
751
752 /**
753  * Returns non-zero if the mantissa of a floating point IEEE-754
754  * tarval is zero (i.e. 1.0Exxx)
755  *
756  * @param tv    the tarval
757  */
758 int tarval_ieee754_zero_mantissa(tarval *tv);
759
760 /**
761  * Returns the exponent of a floating point IEEE-754
762  * tarval.
763  *
764  * @param tv    the tarval
765  */
766 int tarval_ieee754_get_exponent(tarval *tv);
767
768 /**
769  * Check if the tarval can be converted to the given mode without
770  * precision loss.
771  *
772  * @param tv    the tarval
773  * @param mode  the mode to convert to
774  */
775 int tarval_ieee754_can_conv_lossless(tarval *tv, ir_mode *mode);
776
777 /**
778  * Set the immediate precision for IEEE-754 results. Set this to
779  * 0 to get the same precision as the operands.
780  * For x87 compatibility, set this to 80.
781  *
782  * @return the old setting
783  */
784 unsigned tarval_ieee754_set_immediate_precision(unsigned bits);
785
786 /**
787  *  Returns non-zero if the result of the last IEEE-754 operation was exact.
788  */
789 unsigned tarval_ieee754_get_exact(void);
790
791 /**
792  * Return the size of the mantissa in bits (including possible
793  * implicit bits) for the given mode.
794  */
795 unsigned tarval_ieee754_get_mantissa_size(const ir_mode *mode);
796
797 /**
798  * Enable/Disable floating point constant folding.
799  */
800 void tarval_enable_fp_ops(int enable);
801
802 /** returns 0/1 if floating point folding is enable/disabled */
803 int tarval_fp_ops_enabled(void);
804
805 /**
806  * Check if its the a floating point NaN.
807  *
808  * @param tv    the tarval
809  */
810 int tarval_is_NaN(tarval *tv);
811
812 /**
813  * Check if its the a floating point +inf.
814  *
815  * @param tv    the tarval
816  */
817 int tarval_is_plus_inf(tarval *tv);
818
819 /**
820  * Check if its the a floating point -inf.
821  *
822  * @param tv    the tarval
823  */
824 int tarval_is_minus_inf(tarval *tv);
825
826 /**
827  * Check if the tarval represents a finite value, ie neither NaN nor inf.
828  *
829  * @param tv    the tarval
830  */
831 int tarval_is_finite(tarval *tv);
832
833 /**
834  *   Checks whether a pointer points to a tarval.
835  *
836  *   @param thing     an arbitrary pointer
837  *
838  *   @return
839  *       true if the thing is a tarval, else false
840  */
841 int is_tarval(const void *thing);
842
843 #endif  /* FIRM_TV_TV_H */