From: Michael Beck Date: Mon, 20 Mar 2006 00:43:27 +0000 (+0000) Subject: is_singlebit_tarval() added, needed for Cmp optimization X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=8989f20e96488fd5fc23a6fa8fd2d5e50fb4c1a0;p=libfirm is_singlebit_tarval() added, needed for Cmp optimization [r7480] --- diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 5c6b09bfe..5ae82fb20 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -1664,7 +1664,33 @@ tarval_classification_t classify_tarval(tarval *tv) return TV_CLASSIFY_OTHER; } -/** +/* + * Returns non-zero if a given (integer) tarval has only one single bit + * set. + */ +int is_single_bit_tarval(tarval *tv) { + int i, l; + int bits; + + if (!tv || tv == tarval_bad) return 0; + if (! mode_is_int(tv->mode)) return 0; + + l = get_mode_size_bytes(tv->mode); + for (bits = 0, i = l - 1; i >= 0; --i) { + unsigned char v = get_tarval_sub_bits(tv, (unsigned)i); + + /* check for more than one bit in these */ + if (v) { + if (v & (v-1)) + return 0; + if (++bits > 1) + return 0; + } + } + return bits; +} + +/* * Sets the overflow mode for integer operations. */ void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) { diff --git a/ir/tv/tv.h b/ir/tv/tv.h index f26b5d474..e4224e972 100644 --- a/ir/tv/tv.h +++ b/ir/tv/tv.h @@ -578,7 +578,9 @@ typedef enum _tarval_classification_t { /** * Identifying tarvals values for algebraic simplifications. - * @param tv + * + * @param tv the tarval + * * @return * - TV_CLASSIFY_NULL for additive neutral or the NULL tarval for reference modes, * - TV_CLASSIFY_ONE for multiplicative neutral, @@ -587,6 +589,12 @@ typedef enum _tarval_classification_t { */ tarval_classification_t classify_tarval(tarval *tv); +/** + * Returns non-zero if a given (integer) tarval has only one single bit + * set. + */ +int is_single_bit_tarval(tarval *tv); + /** * Output of tarvals to a buffer. */