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