This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC Inline Assembler "memory" Clobber don't prevent from re-arrange the code in ARM .


stephen lu <lumotuwe@gmail.com> writes:
[...]
> This is safe by adding "memory" Clobber .
> asm volatile("mrs r12, cpsr\n\t"
>     "orr r12, r12, #0xC0\n\t"
>     "msr cpsr_c, r12\n\t" :: : "r12", "cc", "memory");
> c *= b; /* This is safe. */
> asm volatile("mrs r12, cpsr\n"
>     "bic r12, r12, #0xC0\n"
>     "msr cpsr_c, r12" ::: "r12", "cc", "memory");

Try this:

asm volatile("mrs r12, cpsr\n\t"
    "orr r12, r12, #0xC0\n\t"
    "msr cpsr_c, r12\n\t" :: : "r12", "cc", "memory");

*(int volatile *) &c *= *(int volatile *) &b;

asm volatile("mrs r12, cpsr\n"
    "bic r12, r12, #0xC0\n"
    "msr cpsr_c, r12" ::: "r12", "cc", "memory");


HTH

-- Sergey


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]