Re: Compiler optimizing variables in inline assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 27, 2014 at 9:03 AM, Andrew Haley <aph@xxxxxxxxxx> wrote:
>
> I have been informed that this is wrong, sorry.
>
> The correct way to do it is like so:
>
> ---------------------------------------
> If you know how large the accessed memory is, you can add it as input or
> output but if this is not known, you should add `memory'.  As an example,
> if you access ten bytes of a string, you can use a memory input like:
>
>      {"m"( ({ struct { char x[10]; } *p = (void *)ptr ; *p; }) )}.
>
> ---------------------------------------
>
> If you use a zero-length array in the struct (i.e. char x[0]) that will
> effectively do the job if you don't know how large the array is, but there
> seems to be some doubt whether this is guaranteed.  A memory clobber really
> is guaranteed, but seems a bit like overkill.
>
> Andrew.
>

I gave that a shot but it didn't work for me.  I tried making small
modifications and it would either not work right(maybe optimizations)
or the instruction wouldn't allow offsets like [r0, #16].

I did this instead:

typedef struct { char x[16]; } MemContainer128;

....
output param is "=m" ( *((MemContainer128*)ptr))


Cody




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux