Re: asm in C slightly OT

From: George Anzinger (george@pioneer.net)
Date: Tue Jul 25 2000 - 15:36:41 EST


Andrew Morton wrote:
>
> > ...
> > > dummy()
> > > {
> > > asm(".equ STUFF_OFFSET,%0"::"i" (OFFSETOF(thing, stuff)));
> > > }
> > Or maybe: asm(".equ STUFF_OFFSET,%0"::"i" (things.stuff))); where we
> > have bound: struct thing things;
>
> Not too sure what you mean here.. the "i" requires an immediate
> argument (an integer). So you need some construct which will allow the
> compiler to generate a constant. You could use
>
Actually I must have had a senior moment. What I ment was:

          (int)((struct thing *)0)->stuff

which is an integer. Of course the real problem is not being in a
function and the limits that imposes.

> (char *)&things.stuff - (char *)&things
>
> I'd expect the compiler to turn that into a constant, but it doesn't
> make much diff.
>
> > This is close to what I did. If you look at the asm code produced when
> > you wrap the asm with a dummy() you find that there are a few
> > instructions before and after the asm. In the case in point this did
> > not matter as the entry is by a jmp and the last instruction jmped out.
> > In fact, by doing the wrap I was able to:
> >
> > dummy()
> > {
> > asm(.....);
> > ++things.stuff;
> > asm(....);
> > }
>
> This is different. The example I sent only used `dummy' so that the
> `.equ' asm was within function context. It'll generate something like:
>
> .globl dummy
> dummy:
> .equ STUFF_OFFSET,$8
> ret

Understood. I think you get about 4 instructions more or less. In my
case the dummy wrapper is never called either, as a label is used to
enter and exit. (I know the manual says one should not fool the C
compiler in this way, but, hay, it works.

George

snip

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jul 31 2000 - 21:00:20 EST