libFirm
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
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 *payload);
161 
166 FIRM_API void tarval_to_bytes(unsigned char *buffer, ir_tarval *tv);
167 
171 FIRM_API long get_tarval_long(const ir_tarval *tv);
172 
182 FIRM_API int tarval_is_long(const ir_tarval *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(const ir_tarval *tv);
228 
232 FIRM_API long double get_tarval_long_double(const ir_tarval *tv);
233 
241 FIRM_API int tarval_is_double(const ir_tarval *tv);
242 
248 FIRM_API ir_mode *get_tarval_mode(const ir_tarval *tv);
249 
255 FIRM_API int tarval_is_negative(const ir_tarval *tv);
256 
262 FIRM_API int tarval_is_null(const ir_tarval *tv);
263 
269 FIRM_API int tarval_is_one(const ir_tarval *tv);
270 
275 FIRM_API int tarval_is_all_one(const ir_tarval *tv);
276 
281 FIRM_API int tarval_is_constant(const ir_tarval *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(const ir_tarval *a, const ir_tarval *b);
327 
350 FIRM_API ir_tarval *tarval_convert_to(ir_tarval *src, ir_mode *mode);
351 
357 FIRM_API ir_tarval *tarval_bitcast(ir_tarval *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 *a);
392 
400 FIRM_API ir_tarval *tarval_neg(ir_tarval *a);
401 
410 FIRM_API ir_tarval *tarval_add(ir_tarval *a, ir_tarval *b);
411 
420 FIRM_API ir_tarval *tarval_sub(ir_tarval *a, ir_tarval *b);
421 
430 FIRM_API ir_tarval *tarval_mul(ir_tarval *a, ir_tarval *b);
431 
440 FIRM_API ir_tarval *tarval_div(ir_tarval *a, ir_tarval *b);
441 
450 FIRM_API ir_tarval *tarval_mod(ir_tarval *a, ir_tarval *b);
451 
461 FIRM_API ir_tarval *tarval_divmod(ir_tarval *a, ir_tarval *b, ir_tarval **mod_res);
462 
470 FIRM_API ir_tarval *tarval_abs(ir_tarval *a);
471 
480 FIRM_API ir_tarval *tarval_and(ir_tarval *a, ir_tarval *b);
481 
490 FIRM_API ir_tarval *tarval_andnot(ir_tarval *a, ir_tarval *b);
491 
500 FIRM_API ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b);
501 
510 FIRM_API ir_tarval *tarval_ornot(ir_tarval *a, ir_tarval *b);
511 
520 FIRM_API ir_tarval *tarval_eor(ir_tarval *a, ir_tarval *b);
521 
530 FIRM_API ir_tarval *tarval_shl(ir_tarval *a, ir_tarval *b);
531 
536 FIRM_API ir_tarval *tarval_shl_unsigned(ir_tarval *a, unsigned b);
537 
546 FIRM_API ir_tarval *tarval_shr(ir_tarval *a, ir_tarval *b);
547 
552 FIRM_API ir_tarval *tarval_shr_unsigned(ir_tarval *a, unsigned b);
553 
562 FIRM_API ir_tarval *tarval_shrs(ir_tarval *a, ir_tarval *b);
563 
568 FIRM_API ir_tarval *tarval_shrs_unsigned(ir_tarval *a, unsigned b);
569 
596 FIRM_API unsigned char get_tarval_sub_bits(const ir_tarval *tv, unsigned byte_ofs);
597 
605 FIRM_API int get_tarval_popcount(const ir_tarval *tv);
606 
614 FIRM_API int get_tarval_lowest_bit(const ir_tarval *tv);
615 
623 FIRM_API int get_tarval_highest_bit(const ir_tarval *tv);
624 
631 FIRM_API int tarval_zero_mantissa(const ir_tarval *tv);
632 
639 FIRM_API int tarval_get_exponent(const ir_tarval *tv);
640 
648 FIRM_API int tarval_ieee754_can_conv_lossless(const ir_tarval *tv, const ir_mode *mode);
649 
653 FIRM_API unsigned tarval_ieee754_get_exact(void);
654 
660 FIRM_API int tarval_is_nan(const ir_tarval *tv);
661 
667 FIRM_API int tarval_is_quiet_nan(const ir_tarval *tv);
668 
674 FIRM_API int tarval_is_signaling_nan(const ir_tarval *tv);
675 
681 FIRM_API int tarval_is_finite(const ir_tarval *tv);
682 
685 #include "end.h"
686 
687 #endif
int tarval_get_wrap_on_overflow(void)
Returns 0 if operations return bad on overflow, != 0 if they wrap around.
int tarval_is_quiet_nan(const ir_tarval *tv)
Check if tv is a floating point quiet NaN.
ir_tarval * get_tarval_unknown(void)
Returns the 'unknown' tarval.
ir_tarval * tarval_sub(ir_tarval *a, ir_tarval *b)
Subtraction from a tarval.
int tarval_get_exponent(const ir_tarval *tv)
Returns the exponent of a floating point IEEE-754 tarval.
int get_tarval_lowest_bit(const ir_tarval *tv)
Returns the number of the lowest set bit in a given (integer) tarval.
ir_tarval * tarval_b_false
The mode_b tarval 'false'.
Definition: tv.h:296
ir_tarval * tarval_andnot(ir_tarval *a, ir_tarval *b)
Bitwise and not of two integer tarvals.
ir_tarval * tarval_shl(ir_tarval *a, ir_tarval *b)
Logical Left shift.
ir_mode * get_tarval_mode(const ir_tarval *tv)
Returns the mode of the tarval.
ir_tarval * tarval_div(ir_tarval *a, ir_tarval *b)
Integer division of two tarvals.
ir_tarval * tarval_mul(ir_tarval *a, ir_tarval *b)
Multiplication of tarvals.
int tarval_is_signaling_nan(const ir_tarval *tv)
Check if tv is a floating point signaling NaN.
ir_tarval * tarval_not(ir_tarval *a)
Bitwise Negation of a tarval.
int tarval_is_null(const ir_tarval *tv)
Returns 1 if tv is null.
unsigned tarval_ieee754_get_exact(void)
Returns non-zero if the result of the last IEEE-754 operation was exact.
ir_tarval * tarval_shl_unsigned(ir_tarval *a, unsigned b)
logical left shift (variant with unsigned argument).
long get_tarval_long(const ir_tarval *tv)
Returns value as long if possible.
ir_tarval * tarval_eor(ir_tarval *a, ir_tarval *b)
Bitwise exclusive or of two integer tarvals.
ir_tarval * tarval_mod(ir_tarval *a, ir_tarval *b)
Remainder of integer division.
ir_tarval * new_tarval_from_long(long l, ir_mode *mode)
Constructor function for new tarvals.
int tarval_is_negative(const ir_tarval *tv)
Returns 1 if tv is negative.
unsigned char get_tarval_sub_bits(const ir_tarval *tv, unsigned byte_ofs)
Returns the bitpattern of the bytes_ofs byte.
int tarval_zero_mantissa(const ir_tarval *tv)
Returns non-zero if the mantissa of a floating point tarval is zero (i.e.
ir_tarval * tarval_add(ir_tarval *a, ir_tarval *b)
Addition of two tarvals.
ir_tarval * tarval_convert_to(ir_tarval *src, ir_mode *mode)
Converts a tarval to another mode.
int tarval_is_double(const ir_tarval *tv)
This validates if tarval_to_double() will return a satisfying result.
long double get_tarval_long_double(const ir_tarval *tv)
same as get_tarval_double but returns a long double value
void tarval_set_wrap_on_overflow(int wrap_on_overflow)
Sets whether values should wrap on overflow or return the bad value.
ir_tarval * get_tarval_bad(void)
Returns the 'bad' tarval.
ir_tarval * get_tarval_b_false(void)
Returns the mode_b tarval 'false'.
ir_tarval * new_tarval_from_bytes(unsigned char const *buf, ir_mode *mode)
Construct a new tarval from a sequence of bytes.
ir_tarval *const tarval_unknown
The 'unknown' tarval.
Definition: tv.h:291
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_divmod(ir_tarval *a, ir_tarval *b, ir_tarval **mod_res)
Integer division AND remainder.
ir_tarval * get_tarval_b_true(void)
Returns the mode_b tarval 'true'.
ir_tarval * tarval_shr_unsigned(ir_tarval *a, unsigned b)
unsigned (logical) right shift (variant with unsigned argument).
int tarval_is_finite(const ir_tarval *tv)
Check if the tarval represents a finite value, ie neither NaN nor inf.
int tarval_ieee754_can_conv_lossless(const ir_tarval *tv, const ir_mode *mode)
Check if the tarval can be converted to the given mode without precision loss.
int get_tarval_highest_bit(const ir_tarval *tv)
Return the number of the highest set bit in a given (integer) tarval.
ir_tarval * tarval_and(ir_tarval *a, ir_tarval *b)
Bitwise and of two integer tarvals.
int get_tarval_popcount(const ir_tarval *tv)
Returns the number of set bits in a given (integer) tarval.
ir_tarval * tarval_neg(ir_tarval *a)
Arithmetic Negation of a tarval.
struct ir_tarval ir_tarval
Target Machine Value.
Definition: firm_types.h:68
ir_tarval * tarval_abs(ir_tarval *a)
Absolute value of a tarval.
ir_tarval * new_tarval_nan(ir_mode *mode, int signaling, ir_tarval *payload)
Construct a new floating point quiet NaN value.
int tarval_is_long(const ir_tarval *tv)
This validates if get_tarval_long() will return something sensible.
ir_relation
Relations for comparing numbers.
Definition: firm_types.h:159
ir_tarval * tarval_shrs_unsigned(ir_tarval *a, unsigned b)
signed (arithmetic) right shift (variant with unsigned argument).
int tarval_is_all_one(const ir_tarval *tv)
returns non-zero if all bits in the tarval are set.
ir_tarval * tarval_ornot(ir_tarval *a, ir_tarval *b)
Bitwise or not of two integer tarvals.
int tarval_is_constant(const ir_tarval *tv)
Returns non-zero if the tarval is a constant (i.e.
int tarval_is_one(const ir_tarval *tv)
Returns 1 if tv is the "one".
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.
struct ir_mode ir_mode
SSA Value mode.
Definition: firm_types.h:59
ir_tarval * tarval_b_true
The mode_b tarval 'true'.
Definition: tv.h:301
ir_tarval * tarval_shr(ir_tarval *a, ir_tarval *b)
Unsigned (logical) right shift.
ir_tarval *const tarval_bad
The 'bad' tarval.
Definition: tv.h:285
ir_tarval * new_tarval_from_double(double d, ir_mode *mode)
Constructor function for new tarvals.
ir_tarval * new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
Constructor function for new tarvals.
ir_tarval * tarval_bitcast(ir_tarval *src, ir_mode *mode)
Converts a tarval to another mode by reinterpreting the contained bits.
int tarval_is_nan(const ir_tarval *tv)
Check if tv is a floating point NaN.
ir_tarval * tarval_or(ir_tarval *a, ir_tarval *b)
Bitwise or of two integer tarvals.
void tarval_to_bytes(unsigned char *buffer, ir_tarval *tv)
Write tarval to a sequence of bytes.
ir_tarval * tarval_shrs(ir_tarval *a, ir_tarval *b)
Signed (arithmetic) right shift.
double get_tarval_double(const ir_tarval *tv)
This returns a double with the value represented value, or gibberish, depending on the size of double...
ir_relation tarval_cmp(const ir_tarval *a, const ir_tarval *b)
Compares two tarvals.