tv.h 18.7 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Michael Beck's avatar
Michael Beck committed
6
/**
Michael Beck's avatar
Michael Beck committed
7
8
9
10
11
 * @file
 * @brief    Representation of and static computations on target machine
 *           values.
 * @date     2003
 * @author   Mathias Heil
Matthias Braun's avatar
Matthias Braun committed
12
13
14
15
16
17
18
19
20
21
22
23
24
 * @brief    target machine values.
 */
#ifndef FIRM_TV_TV_H
#define FIRM_TV_TV_H

#include <stddef.h>
#include "firm_types.h"

#include "begin.h"

/** @defgroup ir_tarval  Target Machine Values
 *
 * Tarvals only represent values of mode_sort:
Michael Beck's avatar
Michael Beck committed
25
26
27
28
29
 *    - int_number,
 *    - float_number,
 *    - boolean,
 *    - reference,
 *    - character
30
31
 *
 *   In case of references the module accepts an entity to represent the
Matthias Braun's avatar
Matthias Braun committed
32
 *   value. Furthermore, computations and conversions of these values can
33
34
 *   be performed.
 *
Michael Beck's avatar
Michael Beck committed
35
 * @sa
36
37
 *    Techreport 1999-14
 *    irmode.h for the modes definitions
Matthias Braun's avatar
Matthias Braun committed
38
39
 *
 * @{
Michael Beck's avatar
Michael Beck committed
40
 */
41

42
43
/**
 * Constructor function for new tarvals.
44
 *
45
46
47
 * @param str   The string representing the target value
 * @param len   The length of the string
 * @param mode  The mode requested for the result tarval
48
 *
49
50
51
52
 * This function creates a new tarval representing the value represented
 * by a CString, aka char array. If a tarval representing this value already
 * exists, this tarval is returned instead of a new one. So tarvals are
 * directly comparable since their representation is unique.
53
 *
54
 * This function accepts the following strings:
55
 *
56
 * if mode is int_number:
57
58
 *  - [+-]?0[xX][0-9a-fA-F]+ (hexadecimal representation)
 *  - [+-]?0[0-7]*           (octal representation)
59
 *  - [+-]?0[bB][01]+        (binary representation)
60
 *  - [+-]?[1-9][0-9]*       (decimal representation)
61
 *
Christoph Mallon's avatar
Christoph Mallon committed
62
 * if mode is float_number:
63
 *  - [+-]?(decimal int) (. (decimal int))? ([eE][+-]?(decimal int))?
64
65
66
 *
 * if mode is boolean: true, True, TRUE ... False... 0, 1,
 *
67
 * if mode is reference: "null" and the same as for int_number
68
69
70
71
72
 *
 * Leading and/or trailing spaces are ignored
 *
 * @return
 *   A tarval of proper type representing the requested value is returned.
73
74
75
76
 *   Tarvals are unique, so for any value/mode pair at most one tarval will
 *   exist, which will be returned upon further requests with an identical
 *   value/mode pair.
 *
77
 * @note
78
79
 *   Behaviour is undefined if the number in @p str is malformed. Debug builds
 *   should fail assertions in these cases.
80
 *
81
 * @sa
82
 *   irmode.h for predefined modes
83
84
85
 *   new_tarval_from_long()
 *   new_tarval_from_double()
 */
Matthias Braun's avatar
Matthias Braun committed
86
87
FIRM_API ir_tarval *new_tarval_from_str(const char *str, size_t len,
                                        ir_mode *mode);
Christian Schäfer's avatar
Christian Schäfer committed
88

89
90
91
/**
 * Construct a new tarval from a given string.
 *
92
93
94
95
96
97
98
 * @param str      The string representing the target value
 * @param len      The length of the string
 * @param negative != 0 if number should be negative
 * @param base     number system base.
 *                 binary(2), octal(8), decimal(10) and hexadecimal(16) numbers
 *                 are supported.
 * @param mode     The mode requested for the result tarval
99
100
101
102
103
 *
 * @return
 *   A tarval with the given mode. If overflow settings are set to
 *   TV_OVERFLOW_BAD then a tarval_bad is returned if the number can't be
 *   represented in the given mode.
104
 *   Returns bad if the number couldn't successfully be parsed.
105
 */
Matthias Braun's avatar
Matthias Braun committed
106
FIRM_API ir_tarval *new_integer_tarval_from_str(const char *str, size_t len,
107
108
                                                int negative,
                                                unsigned char base,
Matthias Braun's avatar
Matthias Braun committed
109
                                                ir_mode *mode);
110

111
112
/**
 * Constructor function for new tarvals
113
 *
114
 * @param l     The long representing the value
115
116
 * @param mode  The mode requested for the result tarval must be a
 *              twos_complement mode.
117
 *
118
119
120
121
 * This function creates a new tarval representing the value represented
 * by a long integer. If a tarval representing this value already exists,
 * this tarval is returned instead of a new one. So tarvals are directly
 * comparable since their representation is unique.
122
 *
123
124
 * @return
 *   A tarval of proper type representing the requested value is returned.
125
126
127
128
 *   Tarvals are unique, so for any value/mode pair at most one tarval will
 *   exist, which will be returned upon further requests with an identical
 *   value/mode pair.
 *
129
130
131
 * @note
 *   If the long is not representable in the given mode an assertion is
 *   thrown in assert build.
132
 *
133
 * @sa
134
 *   irmode.h for predefined modes
135
136
 *   new_tarval_from_str()
 *   new_tarval_from_double()
137
 *
138
 */
Matthias Braun's avatar
Matthias Braun committed
139
FIRM_API ir_tarval *new_tarval_from_long(long l, ir_mode *mode);
140

Matthias Braun's avatar
Matthias Braun committed
141
/**
142
143
 * Construct a new tarval from a sequence of bytes. The bytes are interpreted
 * in a "little endian" fashion which means less significant bytes come first.
Matthias Braun's avatar
Matthias Braun committed
144
 *
145
146
147
 * @param buf  pointer to a buffer holding at least
 *             get_ir_mode_size_bytes(mode) bytes.
 * @param mode mode for the resulting tarval
Matthias Braun's avatar
Matthias Braun committed
148
149
150
 * @return A newly created (or cached) tarval representing the value.
 */
FIRM_API ir_tarval *new_tarval_from_bytes(unsigned char const *buf,
151
                                          ir_mode *mode);
Matthias Braun's avatar
Matthias Braun committed
152

Matthias Braun's avatar
Matthias Braun committed
153
154
155
156
157
158
159
160
161
/**
 * Construct a new floating point quiet NaN value.
 * @param mode       floating point mode for the resulting value
 * @param signaling  if != 0 produces a signaling NaN else a quiet one.
 * @param payload    if != NULL puts the integer tarval into the mantissa.
 */
FIRM_API ir_tarval *new_tarval_nan(ir_mode *mode, int signaling,
                                   ir_tarval *payload);

162
163
164
165
166
167
/**
 * Write tarval to a sequence of bytes. The value is written in a
 * "little endian" fashion which means the less significant bytes come first.
 */
FIRM_API void tarval_to_bytes(unsigned char *buffer, ir_tarval *tv);

168
169
/**
 * Returns value as long if possible.
170
 */
yb9976's avatar
yb9976 committed
171
FIRM_API long get_tarval_long(const ir_tarval *tv);
172

173
/**
174
175
176
177
178
 * This validates if get_tarval_long() will return something sensible.
 * This is the case if the value is a two_complement (integer/reference) mode
 * and converting it to a mode equivalent to "long" would not result in
 * information loss. So ULONGMAX in an unsigned mode is fine, ULONG_MAX in a
 * signed mode not.
179
180
 *
 * @param tv    the tarval
181
 */
yb9976's avatar
yb9976 committed
182
FIRM_API int tarval_is_long(const ir_tarval *tv);
183

184
185
/**
 * Constructor function for new tarvals.
186
 *
187
 * @param d     The (long) double representing the value
188
 * @param mode  The mode requested for the result tarval
189
 *
190
 * This function creates a new tarval representing the value represented
191
 * by a (long) double. If a tarval representing this value already exists,
192
193
194
 * this tarval is returned instead of a new one. So tarvals are directly
 * comparable since their representation is unique.
 * Only modes of sort float_number can be constructed this way.
195
 *
196
197
 * @return
 *   A tarval of proper type representing the requested value is returned.
198
199
200
201
 *   Tarvals are unique, so for any value/mode pair at most one tarval will
 *   exist, which will be returned upon further requests with an identical
 *   value/mode pair.
 *
202
 * @note
203
 *   If the (long) double is not representable in the given mode an assertion
204
 *   is thrown. This will happen for any mode not of sort float_number.
205
 *
206
 * @sa
207
 *   irmode.h for predefined values
208
209
210
 *   new_tarval_from_str()
 *   new_tarval_from_long()
 */
211
212
213
214
215
216
FIRM_API ir_tarval *new_tarval_from_double(double d, ir_mode *mode);

/**
 * same as new_tarval_from_double(), but with a long double argument
 */
FIRM_API ir_tarval *new_tarval_from_long_double(long double d, ir_mode *mode);
217
218
219
220
221
222
223

/**
 * This returns a double with the value represented value, or
 * gibberish, depending on the size of double and the size of the
 * stored value.
 * This will overflow silently, so use only if you know what
 * you are doing! (better check with tarval_is_long...)
224
225
 *
 * @param tv    the tarval
226
 */
yb9976's avatar
yb9976 committed
227
FIRM_API double get_tarval_double(const ir_tarval *tv);
228
229
230
231

/**
 * same as get_tarval_double but returns a long double value
 */
yb9976's avatar
yb9976 committed
232
FIRM_API long double get_tarval_long_double(const ir_tarval *tv);
233
234
235
236
237

/**
 * This validates if tarval_to_double() will return a satisfying
 * result. I.e. if tv is an float_number and between min, max
 * of double
238
239
 *
 * @param tv    the tarval
240
 */
yb9976's avatar
yb9976 committed
241
FIRM_API int tarval_is_double(const ir_tarval *tv);
242

243
244
245
246
247
/**
 * Returns the mode of the tarval.
 *
 * @param tv    the tarval
 */
yb9976's avatar
yb9976 committed
248
FIRM_API ir_mode *get_tarval_mode(const ir_tarval *tv);
249

Michael Beck's avatar
Michael Beck committed
250
251
/**
 * Returns 1 if tv is negative
252
 *
253
 * @param tv    the tarval
254
 */
yb9976's avatar
yb9976 committed
255
FIRM_API int tarval_is_negative(const ir_tarval *tv);
256

Michael Beck's avatar
Michael Beck committed
257
258
259
/**
 * Returns 1 if tv is null
 *
260
 * @param tv    the tarval
Michael Beck's avatar
Michael Beck committed
261
 */
yb9976's avatar
yb9976 committed
262
FIRM_API int tarval_is_null(const ir_tarval *tv);
Michael Beck's avatar
Michael Beck committed
263

Michael Beck's avatar
Michael Beck committed
264
265
266
/**
 * Returns 1 if tv is the "one"
 *
267
 * @param tv    the tarval
Michael Beck's avatar
Michael Beck committed
268
 */
yb9976's avatar
yb9976 committed
269
FIRM_API int tarval_is_one(const ir_tarval *tv);
Michael Beck's avatar
Michael Beck committed
270

Michael Beck's avatar
Michael Beck committed
271
/**
272
273
 * returns non-zero if all bits in the tarval are set.
 * This means the value is -1 for signed modes with irma_twos_complement.
274
 */
yb9976's avatar
yb9976 committed
275
FIRM_API int tarval_is_all_one(const ir_tarval *tv);
276

277
/**
yb9976's avatar
yb9976 committed
278
 * Returns non-zero if the tarval is a constant (i.e. NOT
279
280
 * a reserved tarval like bad, undef, reachable etc.)
 */
yb9976's avatar
yb9976 committed
281
FIRM_API int tarval_is_constant(const ir_tarval *tv);
282

283
284
285
/** The 'bad' tarval. Representing "no value", do not confuse this with
 * tarval_unknown. */
FIRM_API ir_tarval *const tarval_bad;
286
/** Returns the 'bad' tarval. */
Matthias Braun's avatar
Matthias Braun committed
287
FIRM_API ir_tarval *get_tarval_bad(void);
288

289
290
291
292
293
/** The 'unknown' tarval. Representing an unknown (but legal) value, do
 * not confuse this with tarval_bad. */
FIRM_API ir_tarval *const tarval_unknown;
/** Returns the 'unknown' tarval. */
FIRM_API ir_tarval *get_tarval_unknown(void);
294
295

/** The mode_b tarval 'false'. */
296
FIRM_API ir_tarval *tarval_b_false;
297
/** Returns the mode_b tarval 'false'. */
Matthias Braun's avatar
Matthias Braun committed
298
FIRM_API ir_tarval *get_tarval_b_false(void);
299
300

/** The mode_b tarval 'true'. */
301
FIRM_API ir_tarval *tarval_b_true;
302
/** Returns the mode_b tarval 'true'. */
Matthias Braun's avatar
Matthias Braun committed
303
FIRM_API ir_tarval *get_tarval_b_true(void);
304

305
/**
Matthias Braun's avatar
Matthias Braun committed
306
 * Sets whether values should wrap on overflow or return the bad value.
307
 */
Matthias Braun's avatar
Matthias Braun committed
308
FIRM_API void tarval_set_wrap_on_overflow(int wrap_on_overflow);
309
310

/**
Matthias Braun's avatar
Matthias Braun committed
311
 * Returns 0 if operations return bad on overflow, != 0 if they wrap around.
312
 */
Matthias Braun's avatar
Matthias Braun committed
313
FIRM_API int tarval_get_wrap_on_overflow(void);
314

315
316
/**
 * Compares two tarvals
317
 *
318
319
320
321
 * Compare a with b and return their relation.
 * This is either ir_rel_unordered, ir_rel_less, ir_rel_greater, ir_rel_equal
 * or ir_rel_false if a or b are symbolic pointers which can not be compared at
 * all.
322
 *
323
324
 * @param a   the first tarval to be compared
 * @param b   the second tarval to be compared
325
 */
yb9976's avatar
yb9976 committed
326
FIRM_API ir_relation tarval_cmp(const ir_tarval *a, const ir_tarval *b);
327

328
329
/**
 * Converts a tarval to another mode.
330
 *
Michael Beck's avatar
Michael Beck committed
331
 * Convert tarval 'src' to mode 'mode', this will succeed if and only if mode
332
333
 * 'mode' is wider than the mode of src, as defined in the firm documentation
 * and as returned by the function mode_is_smaller defined in irmode.h.
334
 *
335
336
 * @param src    The tarval to convert
 * @param mode   Tho mode to convert to
337
 *
338
339
 * @return
 *   If a tarval of mode 'mode' with the result of the conversion of the 'src'
340
341
342
 *   tarvals value already exists, it will be returned, else a new tarval is
 *   constructed and returned
 *
343
 * @note
344
 *    Illegal conversions will trigger a panic
345
 *
346
 * @sa
347
348
 *    FIRM documentation for conversion rules
 *    mode_is_smaller defined in irmode.h
349
 */
Matthias Braun's avatar
Matthias Braun committed
350
FIRM_API ir_tarval *tarval_convert_to(ir_tarval *src, ir_mode *mode);
351

Matthias Braun's avatar
Matthias Braun committed
352
353
354
355
356
357
358
/**
 * Converts a tarval to another mode by reinterpreting the contained
 * bits. This is only allowed if the source and destination mode have the
 * same number of bits.
 */
FIRM_API ir_tarval *tarval_bitcast(ir_tarval *src, ir_mode *mode);

359
360
361
/*
 * These function implement basic computations representable as opcodes
 * in FIRM nodes.
362
363
364
365
366
367
 *
 * PARAMETERS
 *    tarval_neg:
 *    traval_abs:
 *      a - the tarval to operate on
 *
Michael Beck's avatar
Michael Beck committed
368
 *    all others:
369
370
371
372
 *      a - the first operand tarval
 *      b - the second operand tarval
 *
 * RESULT
Michael Beck's avatar
Michael Beck committed
373
 *    If necessary a new tarval is constructed for the resulting value,
374
375
376
377
 *   or the one already carrying the computation result is retrieved and
 *   returned as result.
 *
 * NOTES
378
 *   The order the arguments are given in is important, imagine postfix
379
 *   notation.
380
381
382
383
 *   Illegal operations will trigger an assertion.
 *   The sort member of the struct mode defines which operations are valid
 */

384
385
386
387
388
389
390
/**
 * Bitwise Negation of a tarval.
 *
 * @param a  the first tarval
 *
 * @return ~a or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
391
FIRM_API ir_tarval *tarval_not(ir_tarval *a);
392

393
394
395
396
397
398
399
/**
 * Arithmetic Negation of a tarval.
 *
 * @param a  the first tarval
 *
 * @return -a or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
400
FIRM_API ir_tarval *tarval_neg(ir_tarval *a);
401

402
403
404
405
406
407
408
409
/**
 * Addition of two tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a + b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
410
FIRM_API ir_tarval *tarval_add(ir_tarval *a, ir_tarval *b);
411

412
413
414
415
416
417
418
419
420
/**
 * Subtraction from a tarval.
 *
 * @param a         the first tarval
 * @param b         the second tarval
 * @param dst_mode  the mode of the result, needed for mode_P - mode_P, else NULL
 *
 * @return a - b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
421
FIRM_API ir_tarval *tarval_sub(ir_tarval *a, ir_tarval *b, ir_mode *dst_mode);
422

423
424
425
426
427
428
429
430
/**
 * Multiplication of tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a * b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
431
FIRM_API ir_tarval *tarval_mul(ir_tarval *a, ir_tarval *b);
432

433
434
435
436
437
438
439
440
/**
 * Integer division of two tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a / b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
441
FIRM_API ir_tarval *tarval_div(ir_tarval *a, ir_tarval *b);
442

443
444
445
446
447
448
449
450
/**
 * Remainder of integer division.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a % b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
451
FIRM_API ir_tarval *tarval_mod(ir_tarval *a, ir_tarval *b);
452

453
454
455
456
457
458
459
460
461
/**
 * Integer division AND remainder.
 *
 * @param a        the first tarval
 * @param b        the second tarval
 * @param mod_res  after return, contains the remainder result, a % b or tarval_bad
 *
 * @return a / b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
462
FIRM_API ir_tarval *tarval_divmod(ir_tarval *a, ir_tarval *b, ir_tarval **mod_res);
Michael Beck's avatar
Michael Beck committed
463

464
465
466
467
468
469
470
/**
 * Absolute value of a tarval.
 *
 * @param a  the first tarval
 *
 * @return |a| or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
471
FIRM_API ir_tarval *tarval_abs(ir_tarval *a);
472

473
474
475
476
477
478
479
480
/**
 * Bitwise and of two integer tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a & b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
481
FIRM_API ir_tarval *tarval_and(ir_tarval *a, ir_tarval *b);
482

483
484
485
486
487
488
489
490
/**
 * Bitwise and not of two integer tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a & ~b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
491
FIRM_API ir_tarval *tarval_andnot(ir_tarval *a, ir_tarval *b);
492

493
494
495
496
497
498
499
500
/**
 * Bitwise or of two integer tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a | b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
501
FIRM_API ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b);
502

yb9976's avatar
yb9976 committed
503
504
505
506
507
508
509
510
511
512
/**
 * Bitwise or not of two integer tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a | ~b or tarval_bad
 */
FIRM_API ir_tarval *tarval_ornot(ir_tarval *a, ir_tarval *b);

513
514
515
516
517
518
519
520
/**
 * Bitwise exclusive or of two integer tarvals.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a ^ b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
521
FIRM_API ir_tarval *tarval_eor(ir_tarval *a, ir_tarval *b);
522

523
524
525
526
527
528
529
530
/**
 * Logical Left shift.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a << b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
531
FIRM_API ir_tarval *tarval_shl(ir_tarval *a, ir_tarval *b);
532

533
534
535
536
537
538
/**
 * logical left shift (variant with unsigned argument).
 * @see tarval_shl()
 */
FIRM_API ir_tarval *tarval_shl_unsigned(ir_tarval *a, unsigned b);

539
540
541
542
543
544
545
546
/**
 * Unsigned (logical) right shift.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a >>u b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
547
FIRM_API ir_tarval *tarval_shr(ir_tarval *a, ir_tarval *b);
548

549
550
551
552
553
554
/**
 * unsigned (logical) right shift (variant with unsigned argument).
 * @see tarval_shr()
 */
FIRM_API ir_tarval *tarval_shr_unsigned(ir_tarval *a, unsigned b);

555
556
557
558
559
560
561
562
/**
 * Signed (arithmetic) right shift.
 *
 * @param a  the first tarval
 * @param b  the second tarval
 *
 * @return a >>s b or tarval_bad
 */
Matthias Braun's avatar
Matthias Braun committed
563
FIRM_API ir_tarval *tarval_shrs(ir_tarval *a, ir_tarval *b);
564

565
566
567
568
569
570
/**
 * signed (arithmetic) right shift (variant with unsigned argument).
 * @see tarval_shrs()
 */
FIRM_API ir_tarval *tarval_shrs_unsigned(ir_tarval *a, unsigned b);

571
572
573
/**
 * Returns the bitpattern of the bytes_ofs byte.
 *
574
 * This function succeeds even if the mode of the tarval uses fewer bits
575
576
577
578
 * than requested, in that case the bitpattern is filled with zero bits.
 *
 * To query a 32bit value the following code can be used:
 *
579
 * val0 = tarval_sub_bits(tv, 0);  <- lowest bits
580
581
 * val1 = tarval_sub_bits(tv, 1);
 * val2 = tarval_sub_bits(tv, 2);
582
 * val3 = tarval_sub_bits(tv, 3);  <- highest bits
583
 *
584
585
 * Because this is the bit representation of the target machine, only the
 * following operations are legal on the result:
586
 *
Michael Beck's avatar
Michael Beck committed
587
 * - concatenation (endian dependence MUST be handled by the CALLER)
588
 * - bitwise logical operations to select/mask bits
589
 *
590
 * @param tv        the tarval
591
 * @param byte_ofs  the byte offset from lower to higher
592
593
 *
 * @note
594
595
 *   The result of this function is undefined if the mode is neither integer
 *   nor float.
596
 */
yb9976's avatar
yb9976 committed
597
FIRM_API unsigned char get_tarval_sub_bits(const ir_tarval *tv, unsigned byte_ofs);
598

599
/**
600
 * Returns the number of set bits in a given (integer) tarval.
601
602
603
604
605
 *
 * @param tv    the tarval
 *
 * @return number of set bits or -1 on error
 */
yb9976's avatar
yb9976 committed
606
FIRM_API int get_tarval_popcount(const ir_tarval *tv);
607
608

/**
609
 * Returns the number of the lowest set bit in a given (integer) tarval.
610
611
612
613
614
 *
 * @param tv    the tarval
 *
 * @return number of lowest set bit or -1 on error
 */
yb9976's avatar
yb9976 committed
615
FIRM_API int get_tarval_lowest_bit(const ir_tarval *tv);
616

617
618
619
620
621
622
623
/**
 * Return the number of the highest set bit in a given (integer) tarval.
 *
 * @param tv    the tarval
 *
 * @return number of highest set bit or -1 on error
 */
yb9976's avatar
yb9976 committed
624
FIRM_API int get_tarval_highest_bit(const ir_tarval *tv);
625

Michael Beck's avatar
Michael Beck committed
626
/**
627
628
 * Returns non-zero if the mantissa of a floating point tarval is zero
 * (i.e. 1.0Exxx)
629
630
 *
 * @param tv    the tarval
Michael Beck's avatar
Michael Beck committed
631
 */
yb9976's avatar
yb9976 committed
632
FIRM_API int tarval_zero_mantissa(const ir_tarval *tv);
Michael Beck's avatar
Michael Beck committed
633
634
635
636

/**
 * Returns the exponent of a floating point IEEE-754
 * tarval.
637
638
 *
 * @param tv    the tarval
Michael Beck's avatar
Michael Beck committed
639
 */
yb9976's avatar
yb9976 committed
640
FIRM_API int tarval_get_exponent(const ir_tarval *tv);
Michael Beck's avatar
Michael Beck committed
641

642
643
644
645
646
/**
 * Check if the tarval can be converted to the given mode without
 * precision loss.
 *
 * @param tv    the tarval
647
 * @param mode  the mode to convert to
648
 */
yb9976's avatar
yb9976 committed
649
FIRM_API int tarval_ieee754_can_conv_lossless(const ir_tarval *tv, ir_mode *mode);
650

651
/**
652
 * Returns non-zero if the result of the last IEEE-754 operation was exact.
653
 */
Michael Beck's avatar
Michael Beck committed
654
FIRM_API unsigned tarval_ieee754_get_exact(void);
655

656
/**
Matthias Braun's avatar
Matthias Braun committed
657
 * Check if @p tv is a floating point NaN.
658
659
 *
 * @param tv    the tarval
660
 */
yb9976's avatar
yb9976 committed
661
FIRM_API int tarval_is_nan(const ir_tarval *tv);
662

Matthias Braun's avatar
Matthias Braun committed
663
664
665
666
667
668
669
670
671
672
673
674
675
676
/**
 * Check if @p tv is a floating point quiet NaN.
 *
 * @param tv    the tarval
 */
FIRM_API int tarval_is_quiet_nan(const ir_tarval *tv);

/**
 * Check if @p tv is a floating point signaling NaN.
 *
 * @param tv    the tarval
 */
FIRM_API int tarval_is_signaling_nan(const ir_tarval *tv);

677
678
/**
 * Check if the tarval represents a finite value, ie neither NaN nor inf.
679
680
 *
 * @param tv    the tarval
681
 */
yb9976's avatar
yb9976 committed
682
FIRM_API int tarval_is_finite(const ir_tarval *tv);
683

Matthias Braun's avatar
Matthias Braun committed
684
685
/** @} */

686
#include "end.h"
Michael Beck's avatar
Michael Beck committed
687

688
#endif