Re: asm in C slightly OT

From: Andrew Morton (andrewm@uow.edu.au)
Date: Mon Jul 24 2000 - 17:42:24 EST


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

        (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

`dummy' will never be called. You can place any number of `.equ'
pseudo-ops in `dummy'.

> Careful inspection proved that this was as good as I could do in asm and
> keeps everything tracking the structures. Cost: about 4 wasted
> instructions.
>

Good!

The .equ hack merits more playing with, because it could be used to cure
the awkward stuff in entry.S. It may cause the generation of 16 bit
offsets where 8 bit would suffice, but that may be fixable. I'll append
it to my TTD list :)

-
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:17 EST