Advertisement Jump to content
Sign in to follow this  
Muzzy A

SIMD Function - Illegal instruction?

This topic is 1834 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

I made a particle emitter that will use SIMD

But it crashes on the first load in SIMD - Illegal Instruction

// Particle struct

struct Particle
{
__declspec(align(32)) float x[MAX_PARTICLES];
__declspec(align(32)) float y[MAX_PARTICLES];
__declspec(align(32)) float z[MAX_PARTICLES];
__declspec(align(32)) float dirX[MAX_PARTICLES];
__declspec(align(32)) float dirY[MAX_PARTICLES];
__declspec(align(32)) float dirZ[MAX_PARTICLES];
 
__declspec(align(32)) float m_Rate[MAX_PARTICLES];
__declspec(align(32)) int m_RandQuality[MAX_PARTICLES];
__declspec(align(32)) float m_RemainingLifetime[MAX_PARTICLES];
};
 
// The list of particles
Particle m_Particle;
 
 

for( int i=0;i<MAX_PARTICLES; i += 4 )
{
// use SIMD
Particle* pPart = &m_Particle;
 
__m128 x = _mm256_load_ps(pPart->dirX + i);   // Breaks on this line and says "Illegal Instruction" and I have no clue why
__m128 y = _mm256_load_ps(pPart->dirY + i);


// ..
// ..
// ..
}

Any suggesetions?

Edited by Muzzy A

Share this post


Link to post
Share on other sites
Advertisement

You probably want Particle m_particles, without the [ MAX_PARTICLES ] as your members are already arrays. Now you actually have MAX_PARTICLE * MAX_PARTICLES values and you use the address incorrectly.

Share this post


Link to post
Share on other sites
I believe that's an AVX instruction. Does your processor support AVX? Edited by Nypyren

Share this post


Link to post
Share on other sites

You are controlling the alignment of the data members of your Particle struct, but that doesn't mean the whole struct will be aligned, since you are allocating particles globally I don't how this is supposed to be 32-byte aligned.

 

I assume you need to allocate particles on the heap and manually make sure the address of the struct is 32-byte aligned.

Share this post


Link to post
Share on other sites

You are controlling the alignment of the data members of your Particle struct, but that doesn't mean the whole struct will be aligned, since you are allocating particles globally I don't how this is supposed to be 32-byte aligned.

 

I assume you need to allocate particles on the heap and manually make sure the address of the struct is 32-byte aligned.

 

You assume wrong. The above is valid (although admittedly there are nicer approaches). 

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!