This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Assembly code parametriaztion
- From: "Piotr Wyderski" <piotr dot wyderski at hoga dot pl>
- To: "Andi Kleen" <ak at suse dot de>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Sat, 1 Mar 2003 21:27:10 +0100
- Subject: Re: Assembly code parametriaztion
- References: <002601c2e029$7e84ab60$47ec63d9@voltan.suse.lists.egcs> <p73wuji6fgd.fsf@amdsimf.suse.de>
Andi Kleen wrote:
> You can do it basically two ways (both are used in the linux kernel):
>
> - Make your include files assembler clean, usually with moderate
> use of #ifdef __ASSEMBLY__ and include them in the assembly
> files. This works well for #define, but not for things like structure
> offsets.
It also doesn't work for enumerated constants, if C++ is used.
So, in fact, this solution is virtually the same as two independent
include files. The same problem with code synchronization remains
-- you can modify a constant for C, but forget about its associated
assembly definition -- a possible source of very dangerous bugs.
My solution is able to make use of C/C++ constants directly.
> - For structure offsets or complicated expression have a separate file
> that includes the include files does something like:
>
> asm volatile("-- #define struct_field %0" :: "i" (offsetof(struct
structure, field)));
But such a construction must be defined inside a C function...
> Compile this program with -S, then run a small postprocessor over
> the assembly file that just filters out everything behind --
> Put that into an include file and use it from your assembly.
A truly comfortable solution... ;-))) All due respect (looking at
the e-mail address :-)), but Linux sources are everything but
a standard of clean code -- my built-in aesthetic monitor
throws "E_TOO_MANY_HACKS" exceptions constantly. :-)
Seriously: my set of macros allows the programmer to use it without
such combinations, you just need to type "EMIT(name,value)" and
that's all. But it's not a good solution, why can't we simply extend
GCC to accept parameters for free-standing assembly or to define
assembly constants easily, without helper functions, which are later
removed by the /**/ comments?
> Nice thing is that it also works fine for cross compiling.
Mine too, but I don't need postprocessors.
> Only tricky thing is that you have to get the dependencies right
> in the Makefile, otherwise there can be subtle failures with -j
> compilation.
A built-in mechanism would prevent such bugs...
Best regards
Piotr Wyderski
Serwis www.logo.hoga.pl - sciągaj bajery na telefony
Nokia, Siemens, Alcatel, Ericsson, Motorola,Samsung
------------------------------------------------------------
Promocja!!! rabat 40 % na zakup mks_vir 2003 dla klientów Connect , którzy
posiadaja kupony rabatowe.