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

Re: [MiNT] Improvements for inline assembler



No arguments here.

Alan.

On Mon, 2009-05-11 at 23:22 +0200, Vincent Rivière wrote:
> Hello.
> 
> Here is a proposal for improving the syntax of inline assembly inside the 
> MiNTLib. The generated code will not be affected in any way.
> 
> Current inline assembly is like this :
> 
> #define trap_1_w(n)							\
> __extension__								\
> ({									\
> 	register long retvalue __asm__("d0");				\
> 	    								\
> 	__asm__ volatile						\
> 	("\
> 		movw    %1,sp@-; \
> 		trap    #1;	\
> 		addqw   #2,sp "						\
> 	: "=r"(retvalue)			/* outputs */		\
> 	: "g"(n)				/* inputs  */		\
> 	: __CLOBBER_RETURN("d0") "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */	\
> 	  AND_MEMORY							\
> 	);								\
> 	retvalue;							\
> })
> 
> I propose to change it to the following :
> 
> #define trap_1_w(n)							\
> __extension__								\
> ({									\
> 	register long retvalue __asm__("d0");				\
> 	    								\
> 	__asm__ volatile						\
> 	(								\
> 		"movw	%1,sp@-\n\t"					\
> 		"trap	#1\n\t"						\
> 		"addqw	#2,sp\n\t"					\
> 	: "=r"(retvalue)			/* outputs */		\
> 	: "g"(n)				/* inputs  */		\
> 	: __CLOBBER_RETURN("d0") "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */	\
> 	  AND_MEMORY							\
> 	);								\
> 	retvalue;							\
> })
> 
> Basically, I removed the embedded newlines and semicolumns.
> Instead, I used one string for each assembler line. The strings are merged 
> by the compiler.
> 
> There are 2 advantages :
> 
> - Since every line is independent, it is possible to replace a single 
> instruction by a macro. That will be very useful for supporting multiple CPU 
> variants, such as ColdFire.
> 
> - The assembler code generated by gcc -S was unreadable, because all the 
> instructions were outputted on a single line. With the second version, the 
> generated assembler is clean, very helpful for debugging GCC output.
> 
> If there is no objection, I will submit a patch for the whole MiNTLib with 
> changes like this one.
> 
> NB: The ugly MIT syntax for opcodes is not required anymore by the binutils, 
> we could use the normal Motorola syntax. That may be the purpose of a 
> further patch.
>