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