public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16308] New: Error passing constant as argument in m68k and address mode problem
@ 2004-07-01  2:46 ra010062 at ic dot unicamp dot br
  2004-07-01  3:35 ` [Bug target/16308] " pinskia at gcc dot gnu dot org
  2004-07-01 12:48 ` schwab at suse dot de
  0 siblings, 2 replies; 3+ messages in thread
From: ra010062 at ic dot unicamp dot br @ 2004-07-01  2:46 UTC (permalink / raw)
  To: gcc-bugs

It is important to enphasize that this bug was also verified in gcc 3.3.3.

When we compile a C code to the m68k architecture and in the C code we use a
constant as argument of a function, that's why the critical severity. The code
generated to the m68k is wrong.

The bug: this architecture, because it has few registers, uses the stack to
receive parameters. If a C code passes the value 5 to a function for example,
this value has to be store in the stack,after this has to be decremented by 4
(the stack goes up downward).
The code with this aim is normally generated with PEA(push effective address)
m68k coldfire family instrunction, and this instruction do not have a address
mode that loads directly the value to the stack, only what the value points  to
in memory. Therefore the code is generated this way, what is wrong.

In this example the codes generated would be pea 5.w 

The address mode told is (XXXX).W or (XXXX).L (described in m68k Coldfire family
manual). what problably occurs is a misunderstanding by the gcc about what this
address mode means. This cam be realized also with the use of JMP instruction
that has to jump downright to the address indicated by value x , but it jump to
address that value x points to im memory. That's what the parenthesis means, 
the operand is where XXXX points to.

A example in a fibonacci function:

C code:
int fibo(int);

int main(){
  int x;  
  x=fibo(10);    <---------- the constant value being passed
return 0;
}

int fibo(int n){
  if ((n==1)||(n==0)) return 1;
  else
    return (fibo(n-1)+fibo(n-2));
}


Assembly generated code:
#NO_APP
	.file	"fibonacci.c"
	.text
	.align	2
	.globl	main
	.type	main, @function
main:
	link.w %a6,#-4
	pea 10.w               <-------- It should put the value 10 in the stack
	jbsr fibo                        but puts what's in address 10
	addq.l #4,%sp
	move.l %d0,-4(%a6)
	clr.l %d0
	unlk %a6
	rts
	.size	main, .-main
	.align	2
	.globl	fibo
	.type	fibo, @function
fibo:
	link.w %a6,#-4
	move.l %d2,-(%sp)
	moveq #1,%d0
	cmp.l 8(%a6),%d0
	jbeq .L4
	tst.l 8(%a6)
	jbne .L3
.L4:
	moveq #1,%d0
	move.l %d0,-4(%a6)
	jbra .L2
	.align	2
.L3:
	move.l 8(%a6),%d0
	subq.l #1,%d0
	move.l %d0,-(%sp)
	jbsr fibo
	addq.l #4,%sp
	move.l %d0,%d2
	move.l 8(%a6),%d0
	subq.l #2,%d0
	move.l %d0,-(%sp)
	jbsr fibo
	addq.l #4,%sp
	add.l %d0,%d2
	move.l %d2,-4(%a6)
.L2:
	move.l -4(%a6),%d0
	move.l -8(%a6),%d2
	unlk %a6
	rts
	.size	fibo, .-fibo
	.ident	"GCC: (GNU) 3.4.0"

compilation line: 
m68k-elf-gcc -S fibonacci.c -o fibonaccireport.s

Compilation finished at Wed Jun 30 23:36:14




The gcc was compiled in Fedora linux with the folowing:

--target=m68k-elf --with-gnu-as --with-gnu-ld --with-newlib
--enable-languages=c++,c. The binutils was installed with the same target.

-- 
           Summary: Error passing constant as argument in m68k and address
                    mode problem
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ra010062 at ic dot unicamp dot br
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug target/16308] Error passing constant as argument in m68k and address mode problem
  2004-07-01  2:46 [Bug c/16308] New: Error passing constant as argument in m68k and address mode problem ra010062 at ic dot unicamp dot br
@ 2004-07-01  3:35 ` pinskia at gcc dot gnu dot org
  2004-07-01 12:48 ` schwab at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-01  3:35 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target
 GCC target triplet|                            |m68k-elf
           Keywords|                            |wrong-code


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


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

* [Bug target/16308] Error passing constant as argument in m68k and address mode problem
  2004-07-01  2:46 [Bug c/16308] New: Error passing constant as argument in m68k and address mode problem ra010062 at ic dot unicamp dot br
  2004-07-01  3:35 ` [Bug target/16308] " pinskia at gcc dot gnu dot org
@ 2004-07-01 12:48 ` schwab at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: schwab at suse dot de @ 2004-07-01 12:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2004-07-01 12:48 -------
Reread the description of the pea (and lea) instruction, there is nothing wrong 
here.  "pea 10.w" is exactly equivalent to "move.l #10,-(%sp)", except that the 
former is smaller and faster. 

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


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


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

end of thread, other threads:[~2004-07-01 12:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-01  2:46 [Bug c/16308] New: Error passing constant as argument in m68k and address mode problem ra010062 at ic dot unicamp dot br
2004-07-01  3:35 ` [Bug target/16308] " pinskia at gcc dot gnu dot org
2004-07-01 12:48 ` schwab at suse dot de

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