This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Use extract_bit_field to implement signbit
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Ulrich Weigand <weigand at i1 dot informatik dot uni-erlangen dot de>, <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 6 Feb 2004 12:22:57 -0700 (MST)
- Subject: [PATCH] Use extract_bit_field to implement signbit
On Wed, 4 Feb 2004, Richard Henderson wrote:
> If imode <= word_mode, and the signbit in imode is outside rmode,
> you should use extract_bit_field on the imode version.
The following patch implements this suggestion, using extract_bit_field
whenever imode > rmode, that is for all floating point formats wider
than an int. For shorter floating point formats(?), we continue to
use implement this using an "and" of a paradoxical subreg.
The good news is that using extract_bit_field actually enables the
RTL optimizers to implement signbit(x) as (imode)x < 0 on alpha.
Hurray!
In theory, the use of extract_bit_field should also allow us to
implement signbitl, where the floating point format doesn't have a
corresponding 80, 96 or 128-bit integer mode. However, I'm not
confident enough with aliasing MEMs to include that "enhancement"
with this bug-fix patch.
The following patch has been tested by bootstraps on i686-pc-linux-gnu
and alphaev67-dec-osf5.1, all default languages, and regression tested
with a top-level "make -k check" with no new failures. It also fixes
the failure of builtins-32.c on the alpha (and presumably s390x).
Ok for mainline?
2004-02-06 Roger Sayle <roger@eyesopen.com>
* builtins.c (expand_builtin_signbit): Use extract_bit_field instead
of gen_highpart or gen_lowpart when the floating point format is
wider than the result mode.
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.281
diff -c -3 -p -r1.281 builtins.c
*** builtins.c 2 Feb 2004 00:17:08 -0000 1.281
--- builtins.c 5 Feb 2004 18:33:56 -0000
*************** expand_builtin_signbit (tree exp, rtx ta
*** 4986,5019 ****
temp = expand_expr (arg, NULL_RTX, VOIDmode, 0);
temp = gen_lowpart (imode, temp);
! if (GET_MODE_BITSIZE (imode) < GET_MODE_BITSIZE (rmode))
! temp = gen_lowpart (rmode, temp);
! else if (GET_MODE_BITSIZE (imode) > GET_MODE_BITSIZE (rmode))
{
! if (bitpos > GET_MODE_BITSIZE (rmode))
{
! temp = gen_highpart (rmode, temp);
! bitpos %= GET_MODE_BITSIZE (rmode);
}
else
! temp = gen_lowpart (rmode, temp);
! }
! if (bitpos < HOST_BITS_PER_WIDE_INT)
! {
! hi = 0;
! lo = (HOST_WIDE_INT) 1 << bitpos;
! }
! else
! {
! hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
! lo = 0;
}
-
- temp = force_reg (rmode, temp);
- temp = expand_binop (rmode, and_optab, temp,
- immed_double_const (lo, hi, rmode),
- target, 1, OPTAB_LIB_WIDEN);
return temp;
}
--- 4986,5018 ----
temp = expand_expr (arg, NULL_RTX, VOIDmode, 0);
temp = gen_lowpart (imode, temp);
! if (GET_MODE_BITSIZE (imode) > GET_MODE_BITSIZE (rmode))
{
! temp = copy_to_mode_reg (imode, temp);
! temp = extract_bit_field (temp, 1, bitpos, 1,
! NULL_RTX, rmode, rmode,
! GET_MODE_SIZE (imode));
! }
! else
! {
! if (GET_MODE_BITSIZE (imode) < GET_MODE_BITSIZE (rmode))
! temp = gen_lowpart (rmode, temp);
! if (bitpos < HOST_BITS_PER_WIDE_INT)
{
! hi = 0;
! lo = (HOST_WIDE_INT) 1 << bitpos;
}
else
! {
! hi = (HOST_WIDE_INT) 1 << (bitpos - HOST_BITS_PER_WIDE_INT);
! lo = 0;
! }
! temp = force_reg (rmode, temp);
! temp = expand_binop (rmode, and_optab, temp,
! immed_double_const (lo, hi, rmode),
! target, 1, OPTAB_LIB_WIDEN);
}
return temp;
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833