libFirm
tv.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5 
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 
86 FIRM_API ir_tarval *new_tarval_from_str(const char *str, size_t len,
87  ir_mode *mode);
88 
106 FIRM_API ir_tarval *new_integer_tarval_from_str(const char *str, size_t len,
107  int negative,
108  unsigned char base,
109  ir_mode *mode);
110 
139 FIRM_API ir_tarval *new_tarval_from_long(long l, ir_mode *mode);
140 
150 FIRM_API ir_tarval *new_tarval_from_bytes(unsigned char const *buf,
151  ir_mode *mode);
152 
159 FIRM_API ir_tarval *new_tarval_nan(ir_mode *mode, int signaling,
160  ir_tarval const *payload);
161 
166 FIRM_API void tarval_to_bytes(unsigned char *buffer, ir_tarval const *tv);
167 
171 FIRM_API long get_tarval_long(ir_tarval const *tv);
172 
182 FIRM_API int tarval_is_long(ir_tarval const *tv);
183 
211 FIRM_API ir_tarval *new_tarval_from_double(double d, ir_mode *mode);
212 
216 FIRM_API ir_tarval *new_tarval_from_long_double(long double d, ir_mode *mode);
217 
227 FIRM_API double get_tarval_double(ir_tarval const *tv);
228 
232 FIRM_API long double get_tarval_long_double(ir_tarval const *tv);
233 
241 FIRM_API int tarval_is_double(ir_tarval const *tv);
242 
248 FIRM_API ir_mode *get_tarval_mode(ir_tarval const *tv);
249 
255 FIRM_API int tarval_is_negative(ir_tarval const *tv);
256 
262 FIRM_API int tarval_is_null(ir_tarval const *tv);
263 
269 FIRM_API int tarval_is_one(ir_tarval const *tv);
270 
275 FIRM_API int tarval_is_all_one(ir_tarval const *tv);
276 
281 FIRM_API int tarval_is_constant(ir_tarval const *tv);
282 
285 FIRM_API ir_tarval *const tarval_bad;
287 FIRM_API ir_tarval *get_tarval_bad(void);
288 
291 FIRM_API ir_tarval *const tarval_unknown;
293 FIRM_API ir_tarval *get_tarval_unknown(void);
294 
298 FIRM_API ir_tarval *get_tarval_b_false(void);
299 
303 FIRM_API ir_tarval *get_tarval_b_true(void);
304 
308 FIRM_API void tarval_set_wrap_on_overflow(int wrap_on_overflow);
309 
313 FIRM_API int tarval_get_wrap_on_overflow(void);
314 
326 FIRM_API ir_relation tarval_cmp(ir_tarval const *a, ir_tarval const *b);
327 
350 FIRM_API ir_tarval *tarval_convert_to(ir_tarval const *src, ir_mode *mode);
351 
357 FIRM_API ir_tarval *tarval_bitcast(ir_tarval const *src, ir_mode *mode);
358 
359 /*
360  * These function implement basic computations representable as opcodes
361  * in FIRM nodes.
362  *
363  * PARAMETERS
364  * tarval_neg:
365  * traval_abs:
366  * a - the tarval to operate on
367  *
368  * all others:
369  * a - the first operand tarval
370  * b - the second operand tarval
371  *
372  * RESULT
373  * If necessary a new tarval is constructed for the resulting value,
374  * or the one already carrying the computation result is retrieved and
375  * returned as result.
376  *
377  * NOTES
378  * The order the arguments are given in is important, imagine postfix
379  * notation.
380  * Illegal operations will trigger an assertion.
381  * The sort member of the struct mode defines which operations are valid
382  */
383 
391 FIRM_API ir_tarval *tarval_not(ir_tarval const *a);
392 
400 FIRM_API ir_tarval *tarval_neg(ir_tarval const *a);
401 
410 FIRM_API ir_tarval *tarval_add(ir_tarval const *a, ir_tarval const *b);
411 
420 FIRM_API ir_tarval *tarval_sub(ir_tarval const *a, ir_tarval const *b);
421 
430 FIRM_API ir_tarval *tarval_mul(ir_tarval const *a, ir_tarval const *b);
431 
440 FIRM_API ir_tarval *tarval_div(ir_tarval const *a, ir_tarval const *b);
441 
450 FIRM_API ir_tarval *tarval_mod(ir_tarval const *a, ir_tarval const *b);
451 
461 FIRM_API ir_tarval *tarval_divmod(ir_tarval const *a, ir_tarval const *b,
462  ir_tarval **mod_res);
463 
471 FIRM_API ir_tarval *tarval_abs(ir_tarval const *a);
472 
481 FIRM_API ir_tarval *tarval_and(ir_tarval const *a, ir_tarval const *b);
482 
491 FIRM_API ir_tarval *tarval_andnot(ir_tarval const *a, ir_tarval const *b);
492 
501 FIRM_API ir_tarval *tarval_or(ir_tarval const *a, ir_tarval const *b);
502 
511 FIRM_API ir_tarval *tarval_ornot(ir_tarval const *a, ir_tarval const *b);
512 
521 FIRM_API ir_tarval *tarval_eor(ir_tarval const *a, ir_tarval const *b);
522 
531 FIRM_API ir_tarval *tarval_shl(ir_tarval const *a, ir_tarval const *b);
532 
537 FIRM_API ir_tarval *tarval_shl_unsigned(ir_tarval const *a, unsigned b);
538 
547 FIRM_API ir_tarval *tarval_shr(ir_tarval const *a, ir_tarval const *b);
548 
553 FIRM_API ir_tarval *tarval_shr_unsigned(ir_tarval const *a, unsigned b);
554 
563 FIRM_API ir_tarval *tarval_shrs(ir_tarval const *a, ir_tarval const *b);
564 
569 FIRM_API ir_tarval *tarval_shrs_unsigned(ir_tarval const *a, unsigned b);
570 
597 FIRM_API unsigned char get_tarval_sub_bits(ir_tarval const *tv, unsigned byte_ofs);
598 
606 FIRM_API int get_tarval_popcount(ir_tarval const *tv);
607 
615 FIRM_API int get_tarval_lowest_bit(ir_tarval const *tv);
616 
624 FIRM_API int get_tarval_highest_bit(ir_tarval const *tv);
625 
632 FIRM_API int tarval_zero_mantissa(ir_tarval const *tv);
633 
640 FIRM_API int tarval_get_exponent(ir_tarval const *tv);
641 
649 FIRM_API int tarval_ieee754_can_conv_lossless(ir_tarval const *tv, const ir_mode *mode);
650 
654 FIRM_API unsigned tarval_ieee754_get_exact(void);
655 
661 FIRM_API int tarval_is_nan(ir_tarval const *tv);
662 
668 FIRM_API int tarval_is_quiet_nan(ir_tarval const *tv);
669 
675 FIRM_API int tarval_is_signaling_nan(ir_tarval const *tv);
676 
682 FIRM_API int tarval_is_finite(ir_tarval const *tv);
683 
686 #include "end.h"
687 
688 #endif
int tarval_is_all_one(ir_tarval const *tv)
returns non-zero if all bits in the tarval are set.
ir_tarval * get_tarval_bad(void)
Returns the &#39;bad&#39; tarval.
ir_tarval * tarval_andnot(ir_tarval const *a, ir_tarval const *b)
Bitwise and not of two integer tarvals.
int tarval_is_nan(ir_tarval const *tv)
Check if tv is a floating point NaN.
ir_tarval * tarval_shl(ir_tarval const *a, ir_tarval const *b)
Logical Left shift.
ir_tarval *const tarval_unknown
The &#39;unknown&#39; tarval.
Definition: tv.h:291
int get_tarval_lowest_bit(ir_tarval const *tv)
Returns the number of the lowest set bit in a given (integer) tarval.
ir_tarval * tarval_not(ir_tarval const *a)
Bitwise Negation of a tarval.
ir_tarval * get_tarval_b_true(void)
Returns the mode_b tarval &#39;true&#39;.
ir_tarval * tarval_mod(ir_tarval const *a, ir_tarval const *b)
Remainder of integer division.
ir_tarval * tarval_b_true
The mode_b tarval &#39;true&#39;.
Definition: tv.h:301
ir_mode * get_tarval_mode(ir_tarval const *tv)
Returns the mode of the tarval.
int get_tarval_highest_bit(ir_tarval const *tv)
Return the number of the highest set bit in a given (integer) tarval.
ir_tarval * tarval_add(ir_tarval const *a, ir_tarval const *b)
Addition of two tarvals.
ir_tarval * get_tarval_b_false(void)
Returns the mode_b tarval &#39;false&#39;.
ir_tarval * tarval_eor(ir_tarval const *a, ir_tarval const *b)
Bitwise exclusive or of two integer tarvals.
ir_tarval * tarval_shrs_unsigned(ir_tarval const *a, unsigned b)
signed (arithmetic) right shift (variant with unsigned argument).
unsigned char get_tarval_sub_bits(ir_tarval const *tv, unsigned byte_ofs)
Returns the bitpattern of the bytes_ofs byte.
ir_tarval * new_tarval_from_long_double(long double d, ir_mode *mode)
same as new_tarval_from_double(), but with a long double argument
ir_tarval * tarval_shr_unsigned(ir_tarval const *a, unsigned b)
unsigned (logical) right shift (variant with unsigned argument).
int tarval_is_signaling_nan(ir_tarval const *tv)
Check if tv is a floating point signaling NaN.
int tarval_get_wrap_on_overflow(void)
Returns 0 if operations return bad on overflow, != 0 if they wrap around.
ir_tarval * get_tarval_unknown(void)
Returns the &#39;unknown&#39; tarval.
ir_tarval * tarval_abs(ir_tarval const *a)
Absolute value of a tarval.
ir_tarval * new_integer_tarval_from_str(const char *str, size_t len, int negative, unsigned char base, ir_mode *mode)
Construct a new tarval from a given string.
ir_tarval * tarval_or(ir_tarval const *a, ir_tarval const *b)
Bitwise or of two integer tarvals.
struct ir_tarval ir_tarval
Target Machine Value.
Definition: firm_types.h:68
ir_tarval * tarval_divmod(ir_tarval const *a, ir_tarval const *b, ir_tarval **mod_res)
Integer division AND remainder.
ir_tarval * new_tarval_from_double(double d, ir_mode *mode)
Constructor function for new tarvals.
ir_tarval * tarval_shr(ir_tarval const *a, ir_tarval const *b)
Unsigned (logical) right shift.
int tarval_is_one(ir_tarval const *tv)
Returns 1 if tv is the "one".
ir_tarval * tarval_b_false
The mode_b tarval &#39;false&#39;.
Definition: tv.h:296
int tarval_is_negative(ir_tarval const *tv)
Returns 1 if tv is negative.
int tarval_zero_mantissa(ir_tarval const *tv)
Returns non-zero if the mantissa of a floating point tarval is zero (i.e.
ir_tarval * tarval_bitcast(ir_tarval const *src, ir_mode *mode)
Converts a tarval to another mode by reinterpreting the contained bits.
ir_tarval *const tarval_bad
The &#39;bad&#39; tarval.
Definition: tv.h:285
int tarval_is_long(ir_tarval const *tv)
This validates if get_tarval_long() will return something sensible.
ir_tarval * tarval_div(ir_tarval const *a, ir_tarval const *b)
Integer division of two tarvals.
ir_tarval * new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
Constructor function for new tarvals.
double get_tarval_double(ir_tarval const *tv)
This returns a double with the value represented value, or gibberish, depending on the size of double...
ir_relation
Relations for comparing numbers.
Definition: firm_types.h:159
ir_tarval * new_tarval_from_long(long l, ir_mode *mode)
Constructor function for new tarvals.
ir_tarval * tarval_convert_to(ir_tarval const *src, ir_mode *mode)
Converts a tarval to another mode.
ir_tarval * new_tarval_nan(ir_mode *mode, int signaling, ir_tarval const *payload)
Construct a new floating point quiet NaN value.
ir_tarval * tarval_sub(ir_tarval const *a, ir_tarval const *b)
Subtraction from a tarval.
ir_tarval * tarval_shl_unsigned(ir_tarval const *a, unsigned b)
logical left shift (variant with unsigned argument).
int get_tarval_popcount(ir_tarval const *tv)
Returns the number of set bits in a given (integer) tarval.
ir_tarval * tarval_and(ir_tarval const *a, ir_tarval const *b)
Bitwise and of two integer tarvals.
struct ir_mode ir_mode
SSA Value mode.
Definition: firm_types.h:59
void tarval_set_wrap_on_overflow(int wrap_on_overflow)
Sets whether values should wrap on overflow or return the bad value.
ir_tarval * tarval_ornot(ir_tarval const *a, ir_tarval const *b)
Bitwise or not of two integer tarvals.
int tarval_ieee754_can_conv_lossless(ir_tarval const *tv, const ir_mode *mode)
Check if the tarval can be converted to the given mode without precision loss.
int tarval_get_exponent(ir_tarval const *tv)
Returns the exponent of a floating point IEEE-754 tarval.
unsigned tarval_ieee754_get_exact(void)
Returns non-zero if the result of the last IEEE-754 operation was exact.
ir_tarval * new_tarval_from_bytes(unsigned char const *buf, ir_mode *mode)
Construct a new tarval from a sequence of bytes.
int tarval_is_null(ir_tarval const *tv)
Returns 1 if tv is null.
long get_tarval_long(ir_tarval const *tv)
Returns value as long if possible.
ir_tarval * tarval_mul(ir_tarval const *a, ir_tarval const *b)
Multiplication of tarvals.
void tarval_to_bytes(unsigned char *buffer, ir_tarval const *tv)
Write tarval to a sequence of bytes.
long double get_tarval_long_double(ir_tarval const *tv)
same as get_tarval_double but returns a long double value
int tarval_is_quiet_nan(ir_tarval const *tv)
Check if tv is a floating point quiet NaN.
int tarval_is_double(ir_tarval const *tv)
This validates if tarval_to_double() will return a satisfying result.
int tarval_is_constant(ir_tarval const *tv)
Returns non-zero if the tarval is a constant (i.e.
int tarval_is_finite(ir_tarval const *tv)
Check if the tarval represents a finite value, ie neither NaN nor inf.
ir_relation tarval_cmp(ir_tarval const *a, ir_tarval const *b)
Compares two tarvals.
ir_tarval * tarval_neg(ir_tarval const *a)
Arithmetic Negation of a tarval.
ir_tarval * tarval_shrs(ir_tarval const *a, ir_tarval const *b)
Signed (arithmetic) right shift.