From mint-bounce@lists.fishpool.fi  Tue May 12 09:11:53 2009
X-Virus-Scanned: amavisd-new at demon.co.uk
Subject: Re: [MiNT] Improvements for inline assembler
From: Alan Hourihane <alanh@fairlite.co.uk>
To: Vincent =?ISO-8859-1?Q?Rivi=E8re?= <vincent.riviere@freesbee.fr>
Cc: mint@lists.fishpool.fi
In-Reply-To: <4A08972D.1010200@freesbee.fr>
References: <4A08972D.1010200@freesbee.fr>
Content-Type: text/plain; charset="UTF-8"
Date: Tue, 12 May 2009 14:05:59 +0100
Message-Id: <1242133559.25932.56.camel@localhost>
Mime-Version: 1.0
X-Mailer: Evolution 2.24.5 
X-ecartis-version: Ecartis v1.0.0
Sender: mint-bounce@lists.fishpool.fi
Errors-to: mint-bounce@lists.fishpool.fi
X-original-sender: alanh@fairlite.co.uk
Precedence: bulk
List-help: <mailto:ecartis@lists.fishpool.fi?Subject=help>
List-unsubscribe: <mailto:mint-request@lists.fishpool.fi?Subject=unsubscribe>
List-Id: <mint.lists.fishpool.fi>
X-List-ID: <mint.lists.fishpool.fi>
List-subscribe: <mailto:mint-request@lists.fishpool.fi?Subject=subscribe>
List-owner: <mailto:tjhukkan@fishpool.fi>
List-post: <mailto:mint@lists.fishpool.fi>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by mail.sparemint.org id n4CDBqB7028338

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.
> 


