Bug 21981 - [4.0 only] __m64 return value should be returned in %mm0
[4.0 only] __m64 return value should be returned in %mm0
Status: RESOLVED WONTFIX
Product: gcc
Classification: Unclassified
Component: target
4.1.0
: P2 normal
: 4.0.3
Assigned To: Uroš Bizjak
http://gcc.gnu.org/ml/gcc-patches/200...
: ABI, ssemmx, wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-06-09 12:56 UTC by Uroš Bizjak
Modified: 2005-10-05 16:11 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 3.2.3 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2005-06-10 12:12:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2005-06-09 12:56:36 UTC
Calling convetions for x86 specify that __m64 values should be returned in %mm0 
MMX register [1]. Gcc returns __m64 values on stack.

The testcase:

--cut here--
#include <mmintrin.h>

__v8qi
aaa (__v8qi x, __v8qi y)
{
  __v8qi mm1;

  mm1 = _mm_add_pi8 (x, y);

  return mm1;
}

int main() {
  __v8qi mm0 = { 1,2,3,4,5,6,7,8 };
  __v8qi mm1 = { 11,12,13,14,15,16,17,18 };

  union ttt {
    __v8qi mm;
    char x[8];
  } temp;

  temp.mm = aaa (mm0, mm1);
  printf ("%i\n", temp.x[0]);

  return 0;
}
--cut here--

will produce:

aaa:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	paddb	%mm1, %mm0
	movq	%mm0, (%eax)   <<<<-- %mm0 goes to memory
	popl	%ebp
	ret	$4

main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	andl	$-16, %esp
	subl	$16, %esp
	leal	-8(%ebp), %eax
	movl	%eax, (%esp)
	movq	.LC0, %mm1
	movq	.LC1, %mm0
	call	aaa
	movsbl	-8(%ebp),%eax    <<<<-- return value taken from memory
	subl	$4, %esp
	movl	%eax, 4(%esp)
	movl	$.LC2, (%esp)
	call	printf
	xorl	%eax, %eax
	leave
	ret


[1] http://www.agner.org/assem/calling_conventions.pdf
Comment 1 Andrew Pinski 2005-06-09 14:16:34 UTC
Confirmed, ICC returns it in %mm0.
Note this is the testcase which I used:
#include <mmintrin.h>

__m64
aaa (__m64 x, __m64 y)
{
  __m64 mm1;
  mm1 = _mm_add_pi8 (x, y);
  return mm1;
}

int main() {
    __m64 mm0;
    __m64 mm1;
  union ttt {
    __m64 mm;
    char x[8];
  } temp;

  temp.mm = aaa (mm0, mm1);
  printf ("%i\n", temp.x[0]);

  return 0;
}
Comment 2 gcc-bugzilla@gcc.gnu.org 2005-06-09 16:11:05 UTC
Subject:  New: __m64 return value should  be returned in %mm0

Calling convetions for x86 specify that __m64 values should be returned in %mm0 
MMX register [1]. Gcc returns __m64 values on stack.

The testcase:

--cut here--
#include <mmintrin.h>

__v8qi
aaa (__v8qi x, __v8qi y)
{
  __v8qi mm1;

  mm1 = _mm_add_pi8 (x, y);

  return mm1;
}

int main() {
  __v8qi mm0 = { 1,2,3,4,5,6,7,8 };
  __v8qi mm1 = { 11,12,13,14,15,16,17,18 };

  union ttt {
    __v8qi mm;
    char x[8];
  } temp;

  temp.mm = aaa (mm0, mm1);
  printf ("%i\n", temp.x[0]);

  return 0;
}
--cut here--

will produce:

aaa:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	paddb	%mm1, %mm0
	movq	%mm0, (%eax)   <<<<-- %mm0 goes to memory
	popl	%ebp
	ret	$4

main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	andl	$-16, %esp
	subl	$16, %esp
	leal	-8(%ebp), %eax
	movl	%eax, (%esp)
	movq	.LC0, %mm1
	movq	.LC1, %mm0
	call	aaa
	movsbl	-8(%ebp),%eax    <<<<-- return value taken from memory
	subl	$4, %esp
	movl	%eax, 4(%esp)
	movl	$.LC2, (%esp)
	call	printf
	xorl	%eax, %eax
	leave
	ret


[1] http://www.agner.org/assem/calling_conventions.pdf

-- 
           Summary: __m64 return value should  be returned in %mm0
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: uros at kss-loka dot si
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21981
Comment 3 CVS Commits 2005-06-10 21:45:22 UTC
Subject: Bug 21981

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-06-10 21:45:15

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 

Log message:
	PR target/21981
	* config/i386/i386.c (ix86_function_value_regno_p): Return true
	for FIRST_MMX_REG if TARGET_MMX.
	(ix86_return_in_memory): Return 1 for MMX/3dNow vectors. Delete
	wrong comment.
	(ix86_struct_value_rtx): Emit warning for MMX ABI violations.
	(ix86_value_regno): Return FIRST_MMX_REG for MMX vector modes.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9122&r2=2.9123
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.828&r2=1.829

Comment 4 Uroš Bizjak 2005-06-21 12:09:43 UTC
Fixed on mailine for 4.1.0, what about branches?
Comment 5 Jakub Jelinek 2005-09-05 15:24:54 UTC
I don't think this should go to the branches.  It is an ABI change, which
shouldn't IMO happen between x.y.z and x.y.z+1.
Comment 6 Uroš Bizjak 2005-10-05 16:11:58 UTC
According to comment #5, closed as WONTFIX on branches.