Patchwork Bug store_bit_field_1 + patch

login
register
mail settings
Submitter Aurelien Buhrig
Date Jan. 18, 2012, 11:48 a.m.
Message ID <4F16B19D.5050806@gmail.com>
Download mbox | patch
Permalink /patch/136604/
State New
Headers show

Comments

Aurelien Buhrig - Jan. 18, 2012, 11:48 a.m.
Hi,

I've found a bug in store_bit_field_1 for BIG_ENDIAN targets whose words
are HI. The testcase is execute.exp=bitfld-3.c for my target (which is
not public).

It occurs on 4.6.1 release, but seem to be present in trunk (looking at
the code, not executed).

The problem occurs when value is a REG and bitsize > BITS_PER_WORD. This
is because wordnum, which is used to get the subword of value, is
incorrectly computed, in BIG_ENDIAN, wrt the number of words needed by
bitsize instead of the number of words needed by the integer mode of the
field, which is the mode used to compute subwords.

For instance, for a 40bit field to be set by a DI reg (with HI words),
the offset of the LSWord of the DI reg should be 3, not 2 as currently
computed.

The following patch seems to solve the issue. Tested on the C testsuite
without any regression (for my target only).

Hope it helps,
Aurélien
Alan Modra - Jan. 21, 2012, 2:37 a.m.
On Wed, Jan 18, 2012 at 12:48:45PM +0100, Aurelien Buhrig wrote:
> The problem occurs when value is a REG and bitsize > BITS_PER_WORD. This
> is because wordnum, which is used to get the subword of value, is
> incorrectly computed, in BIG_ENDIAN, wrt the number of words needed by
> bitsize instead of the number of words needed by the integer mode of the
> field, which is the mode used to compute subwords.

That doesn't sound right.  wordnum is passed to operand_subword as its
"offset" param, which counts in words of word_mode size.  I think you
have a problem elsewhere.
Aurelien Buhrig - Jan. 23, 2012, 8:44 a.m.
Le 21/01/2012 03:37, Alan Modra a écrit :

>> The problem occurs when value is a REG and bitsize > BITS_PER_WORD. This
>> is because wordnum, which is used to get the subword of value, is
>> incorrectly computed, in BIG_ENDIAN, wrt the number of words needed by
>> bitsize instead of the number of words needed by the integer mode of the
>> field, which is the mode used to compute subwords.
> 
> That doesn't sound right.  wordnum is passed to operand_subword as its
> "offset" param, which counts in words of word_mode size.  I think you
> have a problem elsewhere.
> 

The offset is wrong. I filed a bug. See
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51893

Patch

--- expmed.c.orig	2012-01-18 11:48:21.000000000 +0100
+++ expmed.c	2012-01-18 11:49:19.000000000 +0100
@@ -589,7 +589,10 @@ 
 	{
 	  /* If I is 0, use the low-order word in both field and target;
 	     if I is 1, use the next to lowest word; and so on.  */
-	  unsigned int wordnum = (backwards ? nwords - i - 1 : i);
+	  unsigned int wordnum = (backwards
+                                  ? GET_MODE_SIZE(fieldmode)/UNITS_PER_WORD
+                                        - i - 1 
+                                  : i);
 	  unsigned int bit_offset = (backwards
 				     ? MAX ((int) bitsize - ((int) i + 1)
 					    * BITS_PER_WORD,