public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug store_bit_field_1 + patch
@ 2012-01-18 11:48 Aurelien Buhrig
  2012-01-21  2:38 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Buhrig @ 2012-01-18 11:48 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

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



[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 639 bytes --]

--- 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,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug store_bit_field_1 + patch
  2012-01-18 11:48 Bug store_bit_field_1 + patch Aurelien Buhrig
@ 2012-01-21  2:38 ` Alan Modra
  2012-01-23  8:44   ` Aurelien Buhrig
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2012-01-21  2:38 UTC (permalink / raw)
  To: Aurelien Buhrig; +Cc: gcc-patches

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.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug store_bit_field_1 + patch
  2012-01-21  2:38 ` Alan Modra
@ 2012-01-23  8:44   ` Aurelien Buhrig
  0 siblings, 0 replies; 3+ messages in thread
From: Aurelien Buhrig @ 2012-01-23  8:44 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-23  8:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-18 11:48 Bug store_bit_field_1 + patch Aurelien Buhrig
2012-01-21  2:38 ` Alan Modra
2012-01-23  8:44   ` Aurelien Buhrig

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).