SSE2 seems to work but...

K.I.L.E.R

Retarded moron
Veteran
It seemed a little too easy to enable.

Here is where I got my instructions:
http://msdn.microsoft.com/library/d...ry/en-us/vclib/html/vclrf_set_SSE2_enable.asp

Is what I done logically correct? Syntaxly speaking it is. I get no warnings or errors.

Code:
#include <iostream>
#include <cmath>
using namespace std;

int _set_SSE2_enable(int flag);

void main(void)
{
	_set_SSE2_enable(1);
	double a, b, c;
	a = 5.6332;
	b = 10.32;
	c = 16.64;

	c = pow(a*b, c);	

	cout << c << endl;
}

int _set_SSE2_enable(int flag)
{
	return 1;
}

PS: Anyone have any SSE/SSE2 libraries I can download?
I son't want to end up coding in assembly just to use further functions of SSE2. The SSE2 functions in the cmath library are limited.

I read up about SSE2 and I know that it should only be used on really complex calculations otherwise it will only slow your code down.

Thanks
 
Why have you provided your own function called _set_SSE2_enable()? I think that's going to override the one defined in the library. It doesn't even do anything - what did you expect to achieve by returning 1 then not using that return value?
 
Whoops. Fixed it.

This is the only way to get it to compile without errors.
I mustn't be thinking very well today.

Thanks

Code:
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

int _set_SSE2_enable(int flag);

int main(void)
{
	double a, b, c;
	a = 5.6332;
	b = 10.32;
	c = 16.64;

	c = pow(a*b, c);

	cout << c << endl;
	
	system("pause");
	return 0;
}
 
I thought you said your last version also compiled without errors?

Your new version doesn't actually call the function anyway, you're just declaring its existance ready for later use, which isn't necessary since it's in the headers.
 
When I do initialise it, it doesn't compile. It just brings up errors. I do have a P4 CPU as well. So it has to be something I'm doing wrong.

Maybe I'm not initialising it properly.
 
Kiler , read what Myrmecophagavir said, you're 2nd version doenst call the function! If there are errors then send us the errors and we can help you out ;)[ force feed ]

this should be better ( famous last words , i've not got vs-net vc to try this ;0 )

Code:
#include <stdio.h> 
#include <math.h> 
#include <iostream> 
using namespace std; 

//int _set_SSE2_enable(int flag); 
// dfb-removed this , it *should* be in math.h .

int main(void) 
{ 
   double a, b, c; 

   int i ; // dfb-dummy variable to take the return value of _set_SSE2_enable
// you need to call the enabling function first, i'll not stick any code in
// to check for error codes ( look at the m$ version for that)

   i = _set_SSE2_enable(1); //dfb-enable sse2 . the code assumes this has worked.

   a = 5.6332; 
   b = 10.32; 
   c = 16.64; 

   c = pow(a*b, c); 

   cout << c << endl; 
    
   system("pause"); 
   return 0; 
}

note, if there are errors when linking, it's possible i suppose that the correct library isnt being used . the m$ docs should tell you the correct one..

-dave-
 
C:\Documents and Settings\Kruno\Desktop\coding\C++\SSE2\Cpp1.cpp(17) : error C2065: '_set_SSE2_enable' : undeclared identifier

Something funny going on. :(
 
looking at the doc's link you had, this seems to be visual-studio.net.. have you got that version?

fraid my m$ c++ knowledge isnt enough to say wether that would cause problems with your code ( the m$ example is c not c++)..

-dave-
you could also find the math.h and look to see if _set_SSE2_enable is in there,, it's possible theres a compiler option to include support or not though i imagine thats the whole point of having a return value from this function!
 
Oh. I have Visual C++ 6 not .NET. :(

I have also looked into math.h and couldn't find ANY reference to SSE2. Damn!
 
I'm currently using .NET Studio 2003, and math.h does define this function.

#if defined(_M_IX86)

_CRTIMP int __cdecl _set_SSE2_enable(int);

#endif
 
It doesn't have that line anywhere in my math.h library. :(

Do I *HAVE* to use assembly language to take advantage of SSE/2? :/
 
I'm not sure I understand your question. When you set this function to use SSE2, it basically causes a series of math-related functions (outlined in the aforementioned MSDN docs) to simply take advantage of SSE2. That's it.

I only use .NET Studio 2003 for C#/C++, but there might be a Visual Studio6 update that brings their libs up to date. I had VS6 installed about 9 months ago w/ all the updates/SP's, and I don't recall that being the case.
 
I installed SP5 as well as advanced processor support package (whatever it's called). It's still the case that SSE2 cannot be enabled in my program the way M$ have said it can.

Either I'm doing something wrong somewhere or something's not right.
 
VC6 shipped in 1998 - obviously it didn't have SSE2 support back then. You're correct that you need the processor pack to add support for it. But this doesn't seem to include revised standard runtime libraries, just allows your own code to use the extra instructions. So unless you upgrade your VC, you can't use SSE2-enhanced versions of the standard library functions.

I haven't actually installed the pack since I use VC 2003 now, so I can't say if it adds IDE options to enable automatic use of the extra instructions, or if you have to write explicit assembler functions to use them.

Even if you were using VC7, you missed this line in the page you pointed to:

By default, SSE2 implementation is enabled on processors that support it.
So you don't need to run _set_SSE2_enable() anyway to get what you want.
 
Oh. I read an article also stating that if SSE2 is enabled on everything that it would create program overhead and slow down the program's performance.

Is there anyway I can control where SSE/2 is used?

Thanks
 
But this function you're interested in - the one documented in the MSDN article - doesn't enable SSE2 everywhere. All it does is switch to using SSE2-optimised versions of certain standard runtime library maths routines, which will benefit from it. It's not going to affect compilation of your own code - at least I don't think it will judging from the function's description. Does the VC6 processor pack add extra options into the project properties dialogue?

No offence meant, but it seems you aren't that experienced with C coding - there's really no need to bother worrying about such details as extended instruction sets until you have more covered ;)
 
I'm experienced in C++, not C. :D

I'm not after enabling SSE2 everywhere. I know the compiler is SSE2 optimised as John has said but I want the binary to have SSE2 enabled.

I can't find any options in the project properties either relating to SSE/SSE2.

When I read up about implementing SSE2 the article suggested I use assembly language. I want to avoid that.
 
Yer you are right... I have never used it my self, just read about it. They have a 30 days trial version though so you could test if your code would gain anything from SSE2.
 
Back
Top