Skip to main content
gamedev.net
🔒 Locked

GCC asm Array

Started by ZMaster Apr 25, 2004 at 7:33 AM 0 replies 850+ views
Original Post
ZMaster
ZMaster
Hi, variable names cannot be accessed from gcc inline asm unless they're declared globally, right? This works fine for me: //Somewhere global: float a[4] __attribute__ ((aligned(16))) = { 1.0, 2.0, 3.0, 4.0 }; float b[4] __attribute__ ((aligned(16))) = { 3.0, 2.0, 1.0, 0.0 }; //Somewhere in a function body ... asm("movaps _a, %xmm0 movaps _b, %xmm1 mulps %xmm0, %xmm1"); The result is { 3.0, 4.0, 3.0, 0.0 } (The two vectors get multiplied). But I'd like to define a and b locally and use extended inline asm. I know that gcc supports something like this: asm(operation : output : input : clobbers). The problem is, that I couldn't get the whole array a (and b) into one register so that I could access it with %0 or %1 or whatever. As I said before, this works fine if I access the variables direclty. I hope anyone can help me with this... TIA Flo [edited by - ZMaster on April 25, 2004 8:52:06 AM]
ZMaster
ZMaster
Ok, I found out that this works for me:

static float a[4] __attribute__ ((aligned(16))) = { 1.0, 2.0, 3.0, 0.0 };
static float b[4] __attribute__ ((aligned(16))) = { 3.0, 2.0, 1.0, 0.0 };

asm("movaps (%0), %%xmm0" : :"r"(a));
asm("movaps (%0), %%xmm1" : :"r"(b));
asm("mulps %xmm1, %xmm0");
asm("movaps %%xmm0, %0" : "=m"(a));

My mistake was, that I didn''t declare a and b as static. But in some cases (for example the WinMain function) it works without the static keyword. In functions that are called from the Message Callback function my application crashes without an error message or anything if I do not make a and b static. Why is this so?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.