Commit 6d4b5329 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

tv: Add get_tarval_magnitude().

parent fa7eb6ee
......@@ -1229,6 +1229,23 @@ int get_tarval_highest_bit(ir_tarval const *tv)
return -1;
}
unsigned get_tarval_magnitude(ir_tarval const *tv)
{
assert(get_mode_arithmetic(tv->mode) == irma_twos_complement);
unsigned const size = get_mode_size_bits(tv->mode);
unsigned const neg = tarval_get_bit(tv, size - 1);
unsigned const ext = neg ? (1U << SC_BITS) - 1 : 0;
unsigned l = get_mode_size_bytes(tv->mode);
for (unsigned i = l; i-- != 0;) {
unsigned char const v = get_tarval_sub_bits(tv, i);
if (v != ext)
return i * SC_BITS + (32 - nlz(v ^ ext)) + 1;
}
return 1;
}
int tarval_zero_mantissa(ir_tarval const *tv)
{
assert(get_mode_arithmetic(tv->mode) == irma_ieee754
......
......@@ -135,6 +135,11 @@ ir_tarval *get_tarval_small(ir_mode *mode);
ir_tarval *get_tarval_epsilon(ir_mode *mode);
/**
* Get the number of bits required to reconstruct this tarval by sign extension.
*/
unsigned get_tarval_magnitude(ir_tarval const *tv);
/**
* Get the @p idx'th bit of the internal representation of the given tarval
* @p tv.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment