0

I'm tryting to insert an assembly instruction "isync" in my function using GHS compiler as below

    inline void my_asm(void)
    {
       __inline__ asm volatile("isync");
    }

But I'm getting an compiler error from the above sample. Any help on this would be really appreciated.

Thank you!

1)

    inline void my_asm(void)
    {
       asm volatile("isync");
    }

error: from the above sample ghs compiler is expecting "(" at volatile.

2)

    inline void my_asm(void)
    {
       __inle asm ("isync");
    }

error: "asm" in not allowed

  1. only working code is
    inline void my_asm(void)
    {
       asm ("isync");
    }

Any solution and any reference documents would be really appreciated.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • What exactly do you expect the `volatile` to do for you? Or implementation-specific `__inle` or `__inline__`? Also, note well that `asm(...)` is not standard C. It is a common extension, but on implementations that provide it, details are implementation specific. Nevertheless, it is not usual to allow a[nother] keyword between `asm` and the assembly instructions. – John Bollinger Aug 16 '23 at 11:57
  • while generating object code I don't want additional code to be added for the instructions. I want the instructions to be inline. So anything that works as inline volatile instructions of this specific instructions would be greatful – Adarsh Paramashivaiah Aug 16 '23 at 12:15
  • I guess you mean you want to insist that the compiler inline the function. Standard C does not provide any mechanism for that (it's not what the `inline` qualifier means, ironically), but if an implementation provided that capability then I would expect it to work via the function declaration, not by decorating code inside the function body. – John Bollinger Aug 16 '23 at 12:25
  • But you could consider defining `my_asm` as a macro that expands to your inline assembly, instead of a function. That amounts to inlining it manually. It also works around some tricky issues with C inline functions. – John Bollinger Aug 16 '23 at 12:27
  • Yeah thats correct I want compiler to inline the function. How to tell compiler not to optimize the asm code. – Adarsh Paramashivaiah Aug 16 '23 at 12:32
  • That would be specific to your compiler. Green Hills seems to require a (free) account to access [their online documentation](https://support.ghs.com/). You might also find documentation installed locally with the compiler. You may yet get an answer here from someone who knows your particular compiler well enough, but its docs are the primary source. – John Bollinger Aug 16 '23 at 13:43
  • 1
    In GNU C, you'd use `asm volatile("isync" ::: "memory")` to stop the asm statement from reordering wrt. other memory operations. (The `volatile` is implicit for `asm` if there are no output operands, like in this case). If Greenhills doesn't allow `asm volatile` or GNU C Extended asm syntax, probably those things are implicit in `asm("...")` statements. – Peter Cordes Aug 16 '23 at 17:13
  • You could try stuff like `x = 1 ; asm("isync"); x = 2;` for global vars and see if the compiler does dead-store elimination across the asm statement. (Look at the compiler's asm output) – Peter Cordes Aug 16 '23 at 17:13

0 Answers0