Hi all,
The int_log2 function in arm.c is not really useful since we already have a
generic function for calculating
the log2 of HOST_WIDE_INTs. The only difference in functionality is that
int_log2 also asserts that the result
is no greater than 31.
This patch removes int_log2 in favour of exact_log2 and adds an assert on the
result to make sure the return
value was as expected.
Bootstrapped and tested on arm-none-linux-gnueabihf.
Is this ok? Or is there something I'm missing about int_log2?
Thanks,
Kyrill
2016-05-24 Kyrylo Tkachov <[email protected]>
* config/arm/arm.c (int_log2): Delete definition and prototype.
(shift_op): Use exact_log2 instead of int_log2.
(vfp3_const_double_for_fract_bits): Likewise.
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 6cc0feb6f87157171c889e998e52b4e5d8683c66..3fe6eab46f3c18ace6899b5be45ad646992f43e4 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -104,7 +104,6 @@ static void arm_print_operand_address (FILE *, machine_mode, rtx);
static bool arm_print_operand_punct_valid_p (unsigned char code);
static const char *fp_const_from_val (REAL_VALUE_TYPE *);
static arm_cc get_arm_condition_code (rtx);
-static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
static const char *output_multi_immediate (rtx *, const char *, const char *,
int, HOST_WIDE_INT);
static const char *shift_op (rtx, HOST_WIDE_INT *);
@@ -18920,7 +18919,8 @@ shift_op (rtx op, HOST_WIDE_INT *amountp)
return NULL;
}
- *amountp = int_log2 (*amountp);
+ *amountp = exact_log2 (*amountp);
+ gcc_assert (IN_RANGE (*amountp, 0, 31));
return ARM_LSL_NAME;
default:
@@ -18952,22 +18952,6 @@ shift_op (rtx op, HOST_WIDE_INT *amountp)
return mnem;
}
-/* Obtain the shift from the POWER of two. */
-
-static HOST_WIDE_INT
-int_log2 (HOST_WIDE_INT power)
-{
- HOST_WIDE_INT shift = 0;
-
- while ((((HOST_WIDE_INT) 1 << shift) & power) == 0)
- {
- gcc_assert (shift <= 31);
- shift++;
- }
-
- return shift;
-}
-
/* Output a .ascii pseudo-op, keeping track of lengths. This is
because /bin/as is horribly restrictive. The judgement about
whether or not each character is 'printable' (and can be output as
@@ -27691,7 +27675,11 @@ vfp3_const_double_for_fract_bits (rtx operand)
HOST_WIDE_INT value = real_to_integer (&r0);
value = value & 0xffffffff;
if ((value != 0) && ( (value & (value - 1)) == 0))
- return int_log2 (value);
+ {
+ int ret = exact_log2 (value);
+ gcc_assert (IN_RANGE (ret, 0, 31));
+ return ret;
+ }
}
}
return 0;