RE: Assembler errors in optimization level 3 (-O3) - gcc (4.1.2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


> asm
> (
> 	"next:\n\t"
> #ifdef __x86_64__
> 	"pop %rax\n\t"
> 	"pop %rcx"
> #else
> 	"popl %eax\n\t"
> 	"popl %ecx"
> #endif
> );
> asm
> (
> 	"xorl %eax, %eax\n\t"
> 	"cpuid\n\t"
> 	"cmpl $4, %eax\n\t" 	// check if cpuid supports leaf 4
> 	"jl .single_core\n\t"	// Single core
> 	"movl $4, %eax\n\t"
> 	"movl $0, %ecx\n\t"	// start with index = 0; Leaf 4 reports
> );					// at least one valid cache
> asm
> (
> 	"cpuid"
> 	: "=a" (Regeax)
> 	:
> 	: "%ebx", "%ecx", "%edx"
> );
> asm
> (
> 	"jmp .multi_core\n"
> 	".single_core:\n\t"
> 	"xor %eax, %eax\n"
> 	".multi_core:"
> );

Dear All,

The label redefinition in inline ASM was fixed. The actual error is due
to the function was called more  than 3 times and in every place the
code was replaced. So, it was showed the redefinition error. However, by
looking at the following paragraph and links, I have fixed the error.

GCC allows (and requires) you to specify register constraints in your
inline assembly code, so the optimizer always know about it; thus,
inline assembly code is really made of patterns, not forcibly exact

Thus, you can put your assembly into CPP macros, and inline C functions,
so anyone can use it in as any C function/macro. Inline functions
resemble macros very much, but are sometimes cleaner to use. Beware that
in all those cases, code will be duplicated, so only local labels (of 1:
style) should be defined in that asm code. However, a macro would allow
the name for a non local defined label to be passed as a parameter (or
else, you should use additional meta-programming methods). Also, note
that propagating inline asm code will spread potential bugs in them; so
watch out doubly for register constraints in such inline asm code.

Thanks and Regards,
Srinivas G

To unsubscribe from this list: send the line "unsubscribe linux-apps" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux