aboutsummaryrefslogtreecommitdiff
path: root/gcc/hwint.c
diff options
context:
space:
mode:
authorKenneth Zadeck <zadeck@naturalbridge.com>2013-04-03 20:24:07 +0000
committerKenneth Zadeck <zadeck@gcc.gnu.org>2013-04-03 20:24:07 +0000
commit5e0919f1eecbb00fdcf16ff7e064be122fd0bbfc (patch)
tree98ffd8bc9a37f3b09621b894c7db0addd5423458 /gcc/hwint.c
parentbe672e08bbe0d9f210285ec6f3eccf4ff0469d0e (diff)
downloadgcc-5e0919f1eecbb00fdcf16ff7e064be122fd0bbfc.zip
gcc-5e0919f1eecbb00fdcf16ff7e064be122fd0bbfc.tar.gz
gcc-5e0919f1eecbb00fdcf16ff7e064be122fd0bbfc.tar.bz2
hwint.c (sext_hwi, zext_hwi): New functions.
2013-04-03 Kenneth Zadeck <zadeck@naturalbridge.com> * hwint.c (sext_hwi, zext_hwi): New functions. * hwint.h (HOST_BITS_PER_HALF_WIDE_INT, HOST_HALF_WIDE_INT, HOST_HALF_WIDE_INT_PRINT, HOST_HALF_WIDE_INT_PRINT_C, HOST_HALF_WIDE_INT_PRINT_DEC, HOST_HALF_WIDE_INT_PRINT_DEC_C, HOST_HALF_WIDE_INT_PRINT_UNSIGNED, HOST_HALF_WIDE_INT_PRINT_HEX, HOST_HALF_WIDE_INT_PRINT_HEX_PURE): New symbols. (sext_hwi, zext_hwi): New functions. From-SVN: r197456
Diffstat (limited to 'gcc/hwint.c')
-rw-r--r--gcc/hwint.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/hwint.c b/gcc/hwint.c
index 330b42c..134fe1d 100644
--- a/gcc/hwint.c
+++ b/gcc/hwint.c
@@ -204,3 +204,35 @@ least_common_multiple (HOST_WIDE_INT a, HOST_WIDE_INT b)
{
return mul_hwi (abs_hwi (a) / gcd (a, b), abs_hwi (b));
}
+
+#ifdef ENABLE_CHECKING
+/* Sign extend SRC starting from PREC. */
+
+HOST_WIDE_INT
+sext_hwi (HOST_WIDE_INT src, unsigned int prec)
+{
+ gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT);
+
+ if (prec == HOST_BITS_PER_WIDE_INT)
+ return src;
+ else
+ {
+ int shift = HOST_BITS_PER_WIDE_INT - prec;
+ return (src << shift) >> shift;
+ }
+}
+
+/* Zero extend SRC starting from PREC. */
+
+unsigned HOST_WIDE_INT
+zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec)
+{
+ gcc_checking_assert (prec <= HOST_BITS_PER_WIDE_INT);
+
+ if (prec == HOST_BITS_PER_WIDE_INT)
+ return src;
+ else
+ return src & (((HOST_WIDE_INT)1 << prec) - 1);
+}
+
+#endif