Jump to content
  • Advertisement
Sign in to follow this  
Sc4Freak

SSE woes

This topic is 4235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been experimenting with SSE and SSE intrinsics in VS2005. But it seems that I just can't get my code to work. My initial test was to multiply a million floating point numbers by 2. VS2005's debugger gives me this message: "Unhandled exception at 0x00411488 in SSE2.exe: 0xC0000005: Access violation reading location 0x00821008." Here's my code:
	const int Iterations = 100;
	const int DataSize = 1048576;
	float* FloatData = new float[DataSize];
	for(int i = 0 ; i < DataSize ; i++)
		FloatData = 1.0f;
	__m128 x;
	__m128 y;
	__m128 z;

	for(int j = 0 ; j < Iterations ; j++)
	{
		for(float* i = FloatData ; i < FloatData + DataSize * sizeof(float) ; i += 4 * sizeof(float))
		{
			x = _mm_loadu_ps(i); // Breaks here with "Unhandled exception" error
			y = _mm_set_ps(2.0f, 2.0f, 2.0f, 2.0f);
			z = _mm_mul_ps(x, y);
			_mm_storeu_ps(i, z);
		}
	}

Any ideas about what I've done wrong?

Share this post


Link to post
Share on other sites
Advertisement
You don't need the sizeof(float) in your loop - adding an integer to a pointer advances the pointer by that number of elements, not that number of bytes. Your problem is nothing to do with SSE.

Share this post


Link to post
Share on other sites
Whoops, how could I have made such a simple mistake!

Guess I should go over pointer arithmetic once more. [grin]

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!