Bug 11395 - gas creates 64bit add-instruction in 32bit mode for hppa2.0
Summary: gas creates 64bit add-instruction in 32bit mode for hppa2.0
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-17 12:57 UTC by Michael Haubenwallner
Modified: 2011-03-14 16:32 UTC (History)
2 users (show)

See Also:
Host: hppa2.0*-hp-hpux*
Target: hppa2.0*-hp-hpux*
Build: hppa2.0*-hp-hpux*
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner 2010-03-17 12:57:12 UTC
GNU-as (2.19, 2.20) for hppa2.0w-hp-hpux11.31 creates a different bytecode for
the "ADD" instruction compared to HP-as, when .LEVEL is set to "2.0". There is
no difference when .LEVEL is set to "1.1".

Using this assembly file as input:
$ cat > xx20.s <<EOF
    .LEVEL   2.0
    .CODE
  func
    .PROC
    .CALLINFO   FRAME=0, NO_CALLS
    .EXPORT     func,ENTRY
    .ENTRY
    BV %r0(%rp)
    .EXIT
    ADD     %r1,%r1,%r1  ; <== the important line
    .PROCEND
    .END
EOF
$ /opt/hp-gcc/bin/as xx20.s -o xx20.gnu.o
$ /opt/hp-gcc/bin/objdump -d xx20.gnu.o > xx20.gnu.asm

$ /usr/ccs/bin/as xx20.s -o xx20.hp.o
$ /opt/hp-gcc/bin/objdump -d xx20.hp.o > xx20.hp.asm

$ diff xx20.hp.asm xx20.gnu.asm | grep add
<    4: 08 21 06 01     add r1,r1,r1
>    4: 08 21 06 21     add r1,r1,r1

As there is no cmplt/carry/cond modifier (as described in [1] on page 7-2), I'm
not sure if {The boolean variable "overflow" in the operation section is set}
actually applies.

[1]
http://h21007.www2.hp.com/portal/download/files/unprot/parisc20/PA_7_inst_descriptions.pdf
Comment 1 cvs-commit@gcc.gnu.org 2010-04-16 11:21:11 UTC
Subject: Bug 11395

CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2010-04-16 11:20:41

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-hppa.c 
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/hppa/basic: add2.s basic.exp 

Log message:
	PR gas/11395
	* config/tc-hppa.c (pa_ip): Do not allow 64-bit add condition
	matcher to accept and unconditional 32-bit add instruction.
	(pa_build_unwind_subspace): Cope with error conditions not
	allowing the start symbol to be set.
	
	* gas/hppa/basic/add2.s: Add test of simple 32-bit instruction.
	* gas/hppa/basic/basic.exp (do_add2): Add grep for expected
	disassembly.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4131&r2=1.4132
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-hppa.c.diff?cvsroot=src&r1=1.147&r2=1.148
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1655&r2=1.1656
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/hppa/basic/add2.s.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/hppa/basic/basic.exp.diff?cvsroot=src&r1=1.13&r2=1.14

Comment 2 Nick Clifton 2010-04-16 11:23:47 UTC
Hi Michael,

  Sorry for taking so long to look at this problem.

  It turns out to be a bug in GAS's code for parsing condition prefixes for
64-bit addition instructions.  If there were no conditions at all the
instruction was being matched and treated as a 64-bit add, instead of being
rejected and allowing the parser to proceed to the 32-bit add pattern.

  I have checked in a patch to fix this, as well as an addition to the HPPA part
of the GAS testsuite to make sure that the bug stays fixed.

Cheers
  Nick
Comment 3 John David Anglin 2010-12-26 19:45:18 UTC
Change breaks 64-bit linux build:

{standard input}: Assembler messages:
{standard input}:4508: Error: Invalid Add Condition: dc
{standard input}:4509: Error: Invalid Add Condition: dc
{standard input}:4510: Error: Invalid Add Condition: dc
{standard input}:4511: Error: Invalid Add Condition: dc
make[3]: *** [drivers/net/e1000/e1000_main.o] Error 1

The failing instructions are:
        .LEVEL 2.0w

        add,dc          %r20, %r28, %r28
        add,dc          %r21, %r28, %r28
        add,dc          %r22, %r28, %r28
        add,dc          %r1, %r28, %r28
Comment 4 John David Anglin 2010-12-26 20:49:28 UTC
The PA 2.0 architecture says "When a condition completer is not
specified, the "never" condition is used."

Adding ",dc" to the testcase case results in the following assembler
code with HP assembler:

   4:   08 21 07 21     add,dc r1,r1,r1

The "overflow" bit (d) is set.
Comment 5 cvs-commit@gcc.gnu.org 2010-12-27 02:05:18 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	danglin@sourceware.org	2010-12-27 02:05:14

Modified files:
	gas            : ChangeLog 
	gas/testsuite  : ChangeLog 
	include        : ChangeLog 
	gas/config     : tc-hppa.c 
	gas/testsuite/gas/hppa/basic: add2.s basic.exp sub2.s 
	include/opcode : hppa.h 

Log message:
	PR gas/11395
	* config/tc-hppa.c (pa_ip): Set doubleword carry/borrow bit when a
	doubleword completer or doubleword condition is found in an add/sub
	instruction.  Reject match for 'A'/'S' only if there is no condition
	and d bit is not set.
	
	* gas/hppa/basic/add2.s: Add test for a simple doubleword carry
	instruction.
	* gas/hppa/basic/sub2.s: Add tests for simple word and doubleword
	borrow instructions.
	* gas/hppa/basic/basic.exp: Update regexps for above.
	
	* opcode/hppa.h: Clear "d" bit in "add" and "sub" patterns.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4368&r2=1.4369
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1818&r2=1.1819
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/ChangeLog.diff?cvsroot=src&r1=1.514&r2=1.515
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-hppa.c.diff?cvsroot=src&r1=1.149&r2=1.150
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/hppa/basic/add2.s.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/hppa/basic/basic.exp.diff?cvsroot=src&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/hppa/basic/sub2.s.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/opcode/hppa.h.diff?cvsroot=src&r1=1.67&r2=1.68
Comment 6 John David Anglin 2010-12-27 02:07:36 UTC
The initial fix broke the handling of "add,dc".  The same bug was
also present for "sub".  Fixed by patch.
Comment 7 cvs-commit@gcc.gnu.org 2010-12-31 16:43:51 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	danglin@sourceware.org	2010-12-31 16:43:48

Modified files:
	gas            : ChangeLog 
	include/opcode : ChangeLog hppa.h 
	opcodes        : ChangeLog hppa-dis.c 
	gas/config     : tc-hppa.c 

Log message:
	PR gas/11395
	* config/tc-hppa.c (pa_ip): Revert last change.  Add variable need_cond
	to determine whether a 64-bit condition is needed for 'A' and 'S'
	conditions.  Default to 32-bit never condition for logical and unit
	instructions.  Add error message for missing branch on bit condition.
	
	* hppa.h (pa_opcodes): Revert last change.  Exchange 32 and 64-bit
	"bb" entries.
	
	* hppa-dis.c (compare_cond_64_names): Change never condition to ",*".
	(add_cond_64_names): Likewise.
	(logical_cond_64_names): Likewise.
	(unit_cond_64_names): Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4372&r2=1.4373
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/opcode/ChangeLog.diff?cvsroot=src&r1=1.428&r2=1.429
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/opcode/hppa.h.diff?cvsroot=src&r1=1.68&r2=1.69
http://sourceware.org/cgi-bin/cvsweb.cgi/src/opcodes/ChangeLog.diff?cvsroot=src&r1=1.1677&r2=1.1678
http://sourceware.org/cgi-bin/cvsweb.cgi/src/opcodes/hppa-dis.c.diff?cvsroot=src&r1=1.49&r2=1.50
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-hppa.c.diff?cvsroot=src&r1=1.150&r2=1.151
Comment 8 cvs-commit@gcc.gnu.org 2011-03-14 16:28:14 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	danglin@sourceware.org	2011-03-14 16:28:09

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-hppa.c 

Log message:
	Backport from mainline:
	2010-12-26  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
	
	PR gas/11395
	* config/tc-hppa.c (pa_ip): Set doubleword carry/borrow bit when a
	doubleword completer or doubleword condition is found in an add/sub
	instruction.  Reject match for 'A'/'S' only if there is no condition
	and d bit is not set.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.4320.2.18&r2=1.4320.2.19
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-hppa.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.149&r2=1.149.2.1
Comment 9 cvs-commit@gcc.gnu.org 2011-03-14 16:32:04 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	danglin@sourceware.org	2011-03-14 16:31:57

Modified files:
	include/opcode : ChangeLog hppa.h 

Log message:
	Backport from mainline:
	2010-12-31  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
	
	PR gas/11395
	* hppa.h (pa_opcodes): Exchange 32 and 64-bit "bb" entries.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/opcode/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.421.2.1&r2=1.421.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/opcode/hppa.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.67&r2=1.67.4.1