From mint-bounce@lists.fishpool.fi Mon May 11 17:26:30 2009 Message-ID: <4A08972D.1010200@freesbee.fr> Date: Mon, 11 May 2009 23:22:53 +0200 From: =?ISO-8859-1?Q?Vincent_Rivi=E8re?= User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: mint@lists.fishpool.fi Subject: [MiNT] Improvements for inline assembler Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Antivirus: avast! (VPS 090510-0, 10/05/2009), Outbound message X-Antivirus-Status: Clean X-ecartis-version: Ecartis v1.0.0 Sender: mint-bounce@lists.fishpool.fi Errors-to: mint-bounce@lists.fishpool.fi X-original-sender: vincent.riviere@freesbee.fr Precedence: bulk List-help: List-unsubscribe: List-Id: X-List-ID: List-subscribe: List-owner: List-post: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.sparemint.org id n4BLQTMr007854 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. -- Vincent Rivière