views:

848

answers:

1

Hello all,

I am writing an application in C in GCC (for linux/ubuntu) that uses the following inline assembly:

float a[4] = { 10, 20, 30, 40 };
float b[4] = { 0.1, 0.1, 0.1, 0.1 };

asm volatile("movups (%0), %%xmm0\n\t"
             "mulps (%1), %%xmm0\n\t"
             "movups %%xmm0, (%1)"
             :: "r" (a), "r" (b));

Excuse typos in the above (im writing from memory). My question is what is the equivalent inline asm in visual c++ 6.0 ? I have discovered that I need to port my code.

Thanks in advance

+2  A: 
__declspec(align(16)) float a[4] = { 10, 20, 30, 40 };
__declspec(align(16)) float b[4] = { 0.1f, 0.1f, 0.1f, 0.1f };

__asm {
    movups xmm0, a; // could be movaps if array aligned
    mulps xmm0, b;
    movups b, xmm0; // could be movaps if array aligned
}

I'm not sure about Visual C++ 6, but it will work in Visual C++ 2008.

Kirill V. Lyadvinsky
thanks for this, ill try it out next chance i get :)
banister
TBH if you are aligning the float arrays to 16 bytes you may as well use a movaps as it will be MANY times faster ...
Goz
@Goz, added your note in answer. I tried to write an exact copy of question, and added `__declspec(align(16))` out of habit
Kirill V. Lyadvinsky
hey, i've just been reading a bit on alignment, and mightn't this solution (with regard to the alignment and movaps instruction) suffer from the problem raised in the selected answer on this thread: http://stackoverflow.com/questions/841433/gcc-attributealignedx-explanation
banister