public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug pending/17293] New: binary produces bogus output when using SIMD built-ins
@ 2004-09-02 18:27 gcc-bugzilla at gcc dot gnu dot org
  2004-09-02 21:35 ` [Bug pending/17293] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-09-02 18:27 UTC (permalink / raw)
  To: gcc-bugs

NOTE: Defaulting component because reported component no longer exists

hello!

i wanted to test how fast the x86 built-in functions
work on my athlon (supports mmx and 3dnow). doing so
i discovered very strange behavoir of the compiled
binary.

(in the attached code there is no sense to measure time
because i've removed the for-loops for simplicity,
but it's the (nearly) original code that produces the bug.
i've also wrote a short version, see below)

please take a look on this code:
(the occurence of the bug is marked with lots of //// )

Environment:
System: Linux local 2.6.5-1.358 #1 Sat May 8 09:04:50 EDT 2004 i686 athlon i386 GNU/Linux (Fedora Core 2)
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --enable-languages=c,c++,java

How-To-Repeat:

**** SIMPLIFIED VERSION *******************************

// the following three lines are not yet used in this code
#define DATA_SIZE (200*1024*1024)
#define BUFFER_SIZE (1024*1024)
#define ROUNDS (DATA_SIZE/BUFFER_SIZE)

#define SIMD_MODE V2SI

typedef int simdType __attribute__((mode(SIMD_MODE)));

struct simulateType{
	int i[2];
};

double testFunctionSIMD(simdType &data1, simdType &data2, simdType &data3){
	clock_t startTime,endTime;
	startTime=clock();
			
			// normally this is included in a for-loop.
			// i've simplified the code, but the bug occurs anyway
			data3=__builtin_ia32_paddd(data1,data2); // calling SIMD function

	endTime=clock();
	
/////////////////////////////////////////////////

	cout<<startTime<<endl;             // returns 0
	cout<<((double)startTime)<<endl;   //// should return 0; returns NaN: bug?
	cout<<((double)startTime)<<endl;   //// returns NaN (compiler option -O3) or 0 again! (compiler option -O0)
	cout<<((double)startTime)<<endl;   //// returns NaN (compiler option -O3) or 0 again! (compiler option -O0)
	cout<<((double)endTime)<<endl;
	cout<<((double)CLOCKS_PER_SEC)<<endl;
	cout<<(double((double)endTime-(double)startTime)/(double)CLOCKS_PER_SEC)<<endl;
	
	// returns NaN because startTime is NaN
	return double((double)endTime-(double)startTime)/(double)CLOCKS_PER_SEC;

//// NOTE: when "typedef ... __attribute__((mode(simdType)))" is NOT used the bug doesn't occur
//// ( the value of ((double)startTime) is correctly displayed as 0 )
	
/////////////////////////////////////////////////
}

int main(){
	simdType d1,d2,d3;
	simulateType a1,a2,a3;
	
	a1.i[0]=33; a1.i[1]=3333;
	a2.i[0]=44; a2.i[1]=4444;
	
	// HERE IS A STUPID WAY TO COPY A 'simulateType' TO A 'simdType'
	memcpy((void*)&d1,(void*)&a1,sizeof(simdType));
	memcpy((void*)&d2,(void*)&a2,sizeof(simdType));

	double timeElapsedSIMD=testFunctionSIMD(d1,d2,d3);

	cout<<"   with SIMD (in MB/sec): "<<fixed<<setprecision(2)
		<<((double)DATA_SIZE/(1024.0*1024.0)/timeElapsedSIMD)<<endl;

	memcpy((void*)&a3,(void*)&d3,sizeof(simdType));
	cout<<a3.i[0]<<" | "<<a3.i[1]<<endl;
	// the result is correct: 77 and 7777

    return EXIT_SUCCESS;
}

**** END **********************************************


the following code is more simple but produces the bug
only when "typedef ... __attribute__((mode(SIMD_MODE)))"
AND(!) "__builtin_ia32_paddd(a,a)" are used!!!


**** VERY SIMPLIFIED SHORT VERSION *******************

#include<iostream>
using namespace std;

#define SIMD_MODE V2SI
typedef int simdType __attribute__((mode(SIMD_MODE)));

int main(){
	simdType a;
	a=__builtin_ia32_paddd(a,a);

	clock_t x=clock();
	cout<<x<<endl;           //// 0
	cout<<((double)x)<<endl; //// NaN when __builtin_ia32_paddd is used, otherwise 0

    return EXIT_SUCCESS;
}

//// NOTE: when "__builtin_ia32_paddd(a,a)" is NOT used the bug doesn't occur
//// ( the value of ((double)startTime) is correctly displayed as 0 )

**** END **********************************************


both versions of the code were compiled with
"-march=athlon -mmmx -m3dnow"


hope this code could help!

additionally i would like to ask you, where i can get
detailed information about platform-specific SIMD built-in
functions used in gcc.

bye!

Ivan G. Shevchenko < mail at yandex dot ru >

-- 
           Summary: binary produces bogus output when using SIMD built-ins
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: pending
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: linuxadmin at yandex dot ru
                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=17293


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

* [Bug pending/17293] binary produces bogus output when using SIMD built-ins
  2004-09-02 18:27 [Bug pending/17293] New: binary produces bogus output when using SIMD built-ins gcc-bugzilla at gcc dot gnu dot org
@ 2004-09-02 21:35 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-02 21:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-02 21:35 -------
Invalid as you forgot to call the builtin for the emms instruction which is needed for mmx.

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


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


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

end of thread, other threads:[~2004-09-02 21:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-02 18:27 [Bug pending/17293] New: binary produces bogus output when using SIMD built-ins gcc-bugzilla at gcc dot gnu dot org
2004-09-02 21:35 ` [Bug pending/17293] " pinskia at gcc dot gnu 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).