From: Richard Sandiford <rdsandiford@googlemail.com>
To: gcc-patches@gcc.gnu.org
Subject: [3/8] Add narrow_bit_field_mem
Date: Sat, 03 Nov 2012 11:16:00 -0000 [thread overview]
Message-ID: <877gq3ey1n.fsf@talisman.home> (raw)
In-Reply-To: <87k3u3eybu.fsf@talisman.home> (Richard Sandiford's message of "Sat, 03 Nov 2012 11:10:45 +0000")
This patch is the return of narrow_bit_field_mem, originally posted as
part of the preliminary patches. This time I've used a pointer rather
than a reference for the final parameter. (I agree consistency is good.)
The new version also takes the size of the field as a parameter and
handles BLKmode references.
Tested as described in the covering note. OK to install?
Richard
gcc/
* expmed.c (narrow_bit_field_mem): New function.
(store_bit_field_using_insv, store_bit_field_1, store_fixed_bit_field)
(extract_bit_field_1): Use it.
Index: gcc/expmed.c
===================================================================
--- gcc/expmed.c 2012-11-01 19:43:32.376371670 +0000
+++ gcc/expmed.c 2012-11-01 19:54:15.978370095 +0000
@@ -387,6 +387,34 @@ mode_for_extraction (enum extraction_pat
return data->operand[opno].mode;
}
+/* Adjust bitfield memory MEM so that it points to the first unit of mode
+ MODE that contains a bitfield of size BITSIZE at bit position BITNUM.
+ If MODE is BLKmode, return a reference to every byte in the bitfield.
+ Set *NEW_BITNUM to the bit position of the field within the new memory. */
+
+static rtx
+narrow_bit_field_mem (rtx mem, enum machine_mode mode,
+ unsigned HOST_WIDE_INT bitsize,
+ unsigned HOST_WIDE_INT bitnum,
+ unsigned HOST_WIDE_INT *new_bitnum)
+{
+ if (mode == BLKmode)
+ {
+ *new_bitnum = bitnum % BITS_PER_UNIT;
+ HOST_WIDE_INT offset = bitnum / BITS_PER_UNIT;
+ HOST_WIDE_INT size = ((*new_bitnum + bitsize + BITS_PER_UNIT - 1)
+ / BITS_PER_UNIT);
+ return adjust_bitfield_address_size (mem, mode, offset, size);
+ }
+ else
+ {
+ unsigned int unit = GET_MODE_BITSIZE (mode);
+ *new_bitnum = bitnum % unit;
+ HOST_WIDE_INT offset = (bitnum - *new_bitnum) / BITS_PER_UNIT;
+ return adjust_bitfield_address (mem, mode, offset);
+ }
+}
+
/* Return true if a bitfield of size BITSIZE at bit number BITNUM within
a structure of mode STRUCT_MODE represents a lowpart subreg. The subreg
offset is then BITNUM / BITS_PER_UNIT. */
@@ -424,11 +452,8 @@ store_bit_field_using_insv (rtx op0, uns
return false;
if (MEM_P (xop0))
- {
- /* Get a reference to the first byte of the field. */
- xop0 = adjust_bitfield_address (xop0, byte_mode, bitnum / BITS_PER_UNIT);
- bitnum %= BITS_PER_UNIT;
- }
+ /* Get a reference to the first byte of the field. */
+ xop0 = narrow_bit_field_mem (xop0, byte_mode, bitsize, bitnum, &bitnum);
else
{
/* Convert from counting within OP0 to counting in OP_MODE. */
@@ -831,18 +856,15 @@ store_bit_field_1 (rtx str_rtx, unsigned
&& GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (op0)))
{
rtx last, tempreg, xop0;
- unsigned int unit;
- unsigned HOST_WIDE_INT offset, bitpos;
+ unsigned HOST_WIDE_INT bitpos;
last = get_last_insn ();
/* Adjust address to point to the containing unit of
that mode. Compute the offset as a multiple of this unit,
counting in bytes. */
- unit = GET_MODE_BITSIZE (bestmode);
- offset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
- bitpos = bitnum % unit;
- xop0 = adjust_bitfield_address (op0, bestmode, offset);
+ xop0 = narrow_bit_field_mem (op0, bestmode, bitsize, bitnum,
+ &bitpos);
/* Fetch that unit, store the bitfield in it, then store
the unit. */
@@ -975,9 +997,7 @@ store_fixed_bit_field (rtx op0, unsigned
return;
}
- HOST_WIDE_INT bit_offset = bitnum - bitnum % GET_MODE_BITSIZE (mode);
- op0 = adjust_bitfield_address (op0, mode, bit_offset / BITS_PER_UNIT);
- bitnum -= bit_offset;
+ op0 = narrow_bit_field_mem (op0, mode, bitsize, bitnum, &bitnum);
}
mode = GET_MODE (op0);
@@ -1246,11 +1266,8 @@ extract_bit_field_using_extv (rtx op0, u
return NULL_RTX;
if (MEM_P (op0))
- {
- /* Get a reference to the first byte of the field. */
- op0 = adjust_bitfield_address (op0, byte_mode, bitnum / BITS_PER_UNIT);
- bitnum %= BITS_PER_UNIT;
- }
+ /* Get a reference to the first byte of the field. */
+ op0 = narrow_bit_field_mem (op0, byte_mode, bitsize, bitnum, &bitnum);
else
{
/* Convert from counting within OP0 to counting in EXT_MODE. */
@@ -1640,23 +1657,20 @@ extract_bit_field_1 (rtx str_rtx, unsign
&& !(SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (op0))
&& GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (op0)))
{
- unsigned HOST_WIDE_INT offset, bitpos;
-
- /* Compute the offset as a multiple of this unit,
- counting in bytes. */
- unsigned int unit = GET_MODE_BITSIZE (bestmode);
- offset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
- bitpos = bitnum % unit;
-
- /* Make sure the register is big enough for the whole field. */
- if (bitpos + bitsize <= unit)
+ unsigned HOST_WIDE_INT bitpos;
+ rtx xop0 = narrow_bit_field_mem (op0, bestmode, bitsize, bitnum,
+ &bitpos);
+
+ /* Make sure the register is big enough for the whole field.
+ (It might not be if bestmode == GET_MODE (op0) and the input
+ code was invalid.) */
+ if (bitpos + bitsize <= GET_MODE_BITSIZE (bestmode))
{
- rtx last, result, xop0;
+ rtx last, result;
last = get_last_insn ();
/* Fetch it to a register in that size. */
- xop0 = adjust_bitfield_address (op0, bestmode, offset);
xop0 = force_reg (bestmode, xop0);
result = extract_bit_field_1 (xop0, bitsize, bitpos,
unsignedp, packedp, target,
next prev parent reply other threads:[~2012-11-03 11:16 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-03 11:10 [0/8] Add optabs alternatives for insv, extv and extzv Richard Sandiford
2012-11-03 11:13 ` [1/8] Handle TRUNCATE in make_extraction Richard Sandiford
2012-11-10 15:52 ` Eric Botcazou
2012-11-03 11:14 ` [2/8] Add adjust_bitfield_address_size Richard Sandiford
2012-11-10 15:53 ` Eric Botcazou
2012-11-03 11:16 ` Richard Sandiford [this message]
2012-11-10 16:02 ` [3/8] Add narrow_bit_field_mem Eric Botcazou
2012-11-03 11:21 ` [4/8] Add bit_field_mode_iterator Richard Sandiford
2012-11-13 12:44 ` Eric Botcazou
2012-11-13 21:46 ` Richard Henderson
2012-11-13 22:05 ` Eric Botcazou
2012-11-15 12:11 ` Richard Sandiford
2012-11-15 20:39 ` Richard Henderson
2012-11-18 17:34 ` Richard Sandiford
2012-11-18 17:36 ` Richard Sandiford
2012-11-03 11:27 ` [5/8] Tweak bitfield alignment handling Richard Sandiford
2012-11-13 13:52 ` Eric Botcazou
2012-11-18 17:36 ` Richard Sandiford
2012-11-20 2:57 ` John David Anglin
2012-11-20 8:21 ` Mikael Pettersson
2012-11-20 10:32 ` Richard Sandiford
2012-11-20 19:56 ` Richard Sandiford
2012-11-20 22:11 ` Eric Botcazou
2012-11-03 11:28 ` [6/8] Add strict volatile handling to bit_field_mode_iterator Richard Sandiford
2012-11-13 13:57 ` Eric Botcazou
2012-11-15 12:25 ` Richard Sandiford
2012-11-15 17:10 ` Eric Botcazou
2012-11-15 17:47 ` Richard Sandiford
2012-11-15 19:32 ` Eric Botcazou
2012-11-18 17:36 ` Richard Sandiford
2012-11-03 11:39 ` [7/8] Replace mode_for_extraction with new interface Richard Sandiford
2012-11-03 11:41 ` [8/8] Add new optabs and use them for MIPS Richard Sandiford
2012-11-27 17:11 ` [0/8] Add optabs alternatives for insv, extv and extzv Ramana Radhakrishnan
2012-11-27 20:22 ` Richard Sandiford
2012-11-27 22:45 ` Ramana Radhakrishnan
2012-11-28 10:25 ` Richard Biener
2012-11-28 12:06 ` Ramana Radhakrishnan
2012-11-28 12:51 ` Richard Biener
2012-11-28 13:58 ` Richard Sandiford
2012-11-28 23:19 ` Eric Botcazou
2012-11-29 10:31 ` Richard Sandiford
2012-11-29 15:31 ` Eric Botcazou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877gq3ey1n.fsf@talisman.home \
--to=rdsandiford@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).