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