Mulit-line Macro for inline assembly -> error: duplicate label
Mulit-line Macro for inline assembly -> error: duplicate label
- Subject: Mulit-line Macro for inline assembly -> error: duplicate label
- From: Dave Thorup <email@hidden>
- Date: Thu, 9 Nov 2006 16:34:26 -0500
I've run into the following problem trying to get some of our hand-
tuned inline x86 assembly (originally written for VC++) to work in
gcc (Xcode 2.4.1). The problem is, how do you define a multi-line
Macro that can be used in inline assembly?
I've come up with the following trivial example, which does
absolutely nothing useful, but which illustrates the problem:
--------------------------------------------------
#define ASM_MACRO( r1, r2 ) }\
_asm{ pmulhw r1, r2 }\
_asm{ psllw r1, 1 }\
_asm{ paddw r2, r1 }\
_asm{
int main (int argc, const char * argv[]) {
unsigned short v0[4];
unsigned short v1[4];
unsigned int nCount;
_asm {
Loop:
movq mm0, [v0]
movq mm1, [v1]
ASM_MACRO( mm0, mm1 )
dec [nCount]
jnz Loop
}
return 0;
}
--------------------------------------------------
When I try to compile this I get the following error:
main.c:17: error: duplicate label 'LASM$Loop'
main.c:12: error: previous definition of 'LASM$Loop' was here
The problem seems to be that when ASM_MACRO is expanded it's expanded
to a single line which produces this:
--------------------------------------------------
_asm
{
Loop:
movq mm0, [v0]
movq mm1, [v1]
}_asm{ pmulhw mm0, mm1 }_asm{ psllw mm0, 1 }_asm{ paddw mm1, mm0 }
_asm{
dec [nCount]
jnz Loop
}
--------------------------------------------------
If ASM_MACRO did not contain the "}_asm{...}_asm{" parts then all 3
assembly statements would end up on the same line which is an error -
each statement must be on a separate line. The problem with the "}
_asm{...}" stuff is that now the label (Loop) declared in the first
_asm block cannot be referenced properly in the last _asm block.
This doesn't seem to be a problem with VC++ but it is for gcc.
Does anyone know how I might fix this? Is there any kind of line
separator that I could include in the Macro to properly separate the
assembly statements? Has anyone else successfully used multi-line
macros with inline assembly?
The actual macro that I'm having problems with is much bigger than
the one here and is used heavily in the code I'm working on. I could
of course manually expand the macro wherever it is used, but given
the size of the codebase and the size of the macro it would be a
considerable amount of work.
Thanks!
_____________________________
Dave Thorup
Software Engineer
email@hidden
http://www.kuwan.net
HyperSpell - Check spelling in Mac OS X from any application.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden