public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values
@ 2013-04-08 12:04 martin at netbsd dot org
  2013-09-16 21:06 ` [Bug target/56875] " jbglaw@lug-owl.de
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: martin at netbsd dot org @ 2013-04-08 12:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

             Bug #: 56875
           Summary: vax target miscompiles short negative constants for
                    64bit values
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: martin@netbsd.org


Created attachment 29823
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29823
Use the D format specifie for ashqs second arg

The documentation for VAX operand formatting codes says:

   D    64-bit immediate operand

and:

/* The purpose of D is to get around a quirk or bug in vax assembler
   whereby -1 in a 64-bit immediate operand means 0x00000000ffffffff,
   which is not a 64-bit minus one.  */

However, the ashq instruction patters do not use this properly.

This small test program triggers it:

#include <stdio.h>
#include <inttypes.h>

int main(int argc, char **argv)
{
        size_t i;
        uint64_t v, nv;

        for (i = 0; i < 16; i++) {
                v = ~(uint64_t)0 << i;
                nv = ~v;
                printf("%zu: mask %08llx not %08llx\n", i, v, nv);
        }

        return 0;
}

The relevant line from assembly:

    ashq %r6,$-1,%r2

which is misinterpreted by the assembler, so dissasembly is:

   10637:       79 56 8f ff     ashq r6,$0x00000000ffffffff,r2
   1063b:       ff ff ff 00 
   1063f:       00 00 00 52 


The attached patch fixes it.


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
@ 2013-09-16 21:06 ` jbglaw@lug-owl.de
  2013-09-17  1:06 ` jbglaw@lug-owl.de
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jbglaw@lug-owl.de @ 2013-09-16 21:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #1 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
The `gas' bug seems to only show up on 32bit host platform. Creating a
cross-gas on a amd64 systems seems to always result in "correct" VAX binary
output, even for old 2.21 releases. (Will further check this.)

I tend to not fix GCC in this regard. Its output is correct, though doing hex
output instead of negative decimals would work-around gas's bug. However, I
think we'd better fix gas and possibly add a version check to gcc?


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
  2013-09-16 21:06 ` [Bug target/56875] " jbglaw@lug-owl.de
@ 2013-09-17  1:06 ` jbglaw@lug-owl.de
  2013-09-17  7:12 ` martin at netbsd dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jbglaw@lug-owl.de @ 2013-09-17  1:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #2 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
This is gas's tc-vax.c:

3158                           if ((is_absolute) && (expP->X_op != O_big))
3159                             {
3160                               /* If nbytes > 4, then we are scrod. We
3161                                  don't know if the high order bytes
3162                                  are to be 0xFF or 0x00.  BSD4.2 & RMS
3163                                  say use 0x00. OK --- but this
3164                                  assembler needs ANOTHER rewrite to
3165                                  cope properly with this bug.  */
3166                               md_number_to_chars (p + 1, this_add_number,
3167                                                   min (sizeof (valueT),
3168                                                        (size_t) nbytes));
3169                               if ((size_t) nbytes > sizeof (valueT))
3170                                 memset (p + 1 + sizeof (valueT),
3171                                         '\0', nbytes - sizeof (valueT));
3172                             }
[...]

This is for "small" values (ie. "-1" fitting in a 32bit valueT) and it doesn't
properly sign-extend in this case. Taking into account the next couple lines
(not shown here), this part of the code needs to rethought.

A workaround would be to actually place an all-hex value (through GCC) here,
but that wouldn't fix gas for any hand-written assembler.


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
  2013-09-16 21:06 ` [Bug target/56875] " jbglaw@lug-owl.de
  2013-09-17  1:06 ` jbglaw@lug-owl.de
@ 2013-09-17  7:12 ` martin at netbsd dot org
  2013-09-17  7:21 ` jbglaw@lug-owl.de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: martin at netbsd dot org @ 2013-09-17  7:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #3 from Martin Husemann <martin at netbsd dot org> ---
Of course I do not mind fixing gas, but the whole point of the "D" formatting
code is to work around this assembler bug, and while this might be mostly
irrelevant nowadays, isn't gcc supposed to work with other assemblers (like the
VMS one) as well? Gas seems to be "bug-compatible" here.

Overall, especially since this change is trivial, wouldn't it be best/easiest
to apply it anyway?


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
                   ` (2 preceding siblings ...)
  2013-09-17  7:12 ` martin at netbsd dot org
@ 2013-09-17  7:21 ` jbglaw@lug-owl.de
  2013-09-20 16:51 ` jbglaw@lug-owl.de
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jbglaw@lug-owl.de @ 2013-09-17  7:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #4 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
You're quite right, Martin!  It's a simple fix on the GCC side working around a
buggy gas, and it would also work with a fixed gas. However, gas isn't too
simple to fix, at least not with a well-architected fix.


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
                   ` (3 preceding siblings ...)
  2013-09-17  7:21 ` jbglaw@lug-owl.de
@ 2013-09-20 16:51 ` jbglaw@lug-owl.de
  2013-09-20 19:00 ` jbglaw at gcc dot gnu.org
  2013-09-21  8:18 ` martin at netbsd dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jbglaw@lug-owl.de @ 2013-09-20 16:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #5 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
Created attachment 30872
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30872&action=edit
Updated patch including testcase.


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
                   ` (4 preceding siblings ...)
  2013-09-20 16:51 ` jbglaw@lug-owl.de
@ 2013-09-20 19:00 ` jbglaw at gcc dot gnu.org
  2013-09-21  8:18 ` martin at netbsd dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jbglaw at gcc dot gnu.org @ 2013-09-20 19:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

--- Comment #6 from jbglaw at gcc dot gnu.org ---
Author: jbglaw
Date: Fri Sep 20 19:00:02 2013
New Revision: 202796

URL: http://gcc.gnu.org/viewcvs?rev=202796&root=gcc&view=rev
Log:
Work around buggy gas not properly sign-extending a 64bit value on a 32bit host

PR target/56875
2013-09-20  Martin Husemann  <martin@NetBSD.org>
        Jan-Benedict Glaw  <jbglaw@lug-owl.de>

gcc/
    * config/vax/vax.c (vax_output_int_move): Use D format specifier.
    * config/vax/vax.md (ashldi3, <unnamed>): Ditto.

gcc/testsuite/
    * gcc.target/vax/vax.exp: New.
    * gcc.target/vax/pr56875.c: Ditto.

Added:
    trunk/gcc/testsuite/gcc.target/vax/
    trunk/gcc/testsuite/gcc.target/vax/pr56875.c
    trunk/gcc/testsuite/gcc.target/vax/vax.exp
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/vax/vax.c
    trunk/gcc/config/vax/vax.md
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/56875] vax target miscompiles short negative constants for 64bit values
  2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
                   ` (5 preceding siblings ...)
  2013-09-20 19:00 ` jbglaw at gcc dot gnu.org
@ 2013-09-21  8:18 ` martin at netbsd dot org
  6 siblings, 0 replies; 8+ messages in thread
From: martin at netbsd dot org @ 2013-09-21  8:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56875

Martin Husemann <martin at netbsd dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Martin Husemann <martin at netbsd dot org> ---
fixed on trunk


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

end of thread, other threads:[~2013-09-21  8:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-08 12:04 [Bug target/56875] New: vax target miscompiles short negative constants for 64bit values martin at netbsd dot org
2013-09-16 21:06 ` [Bug target/56875] " jbglaw@lug-owl.de
2013-09-17  1:06 ` jbglaw@lug-owl.de
2013-09-17  7:12 ` martin at netbsd dot org
2013-09-17  7:21 ` jbglaw@lug-owl.de
2013-09-20 16:51 ` jbglaw@lug-owl.de
2013-09-20 19:00 ` jbglaw at gcc dot gnu.org
2013-09-21  8:18 ` martin at netbsd dot org

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