SIMD Function - Illegal instruction?

Started by
5 comments, last by RobTheBloke 10 years, 3 months ago

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?

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.

I apologize that was a typo. I didn't actually have it set to an array like that.

I believe that's an AVX instruction. Does your processor support AVX?

It doesn't support AVX. Thanks for making me double check.

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 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).

This topic is closed to new replies.

Advertisement