1

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 (I'm writing from memory). What is the equivalent inline assembler in Visual C++ 6.0 ? I have discovered that I need to port my code.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
horseyguy
  • 29,455
  • 20
  • 103
  • 145
  • You might find it easier to port a Linux application to Windows using one of the gcc-on-Window ports: http://wiki.answers.com/Q/How_do_you_install_GCC_in_Windows_XP – David Cary Sep 14 '10 at 15:51

1 Answers1

2
__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
  • 97,037
  • 24
  • 136
  • 212
  • 1
    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 Jul 22 '09 at 07:44
  • 1
    @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 Jul 22 '09 at 07:58
  • 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 – horseyguy Jul 24 '09 at 09:16